Files Classes Functions Hierarchy
00001 #ifndef PATTERNSEARCHD2_H 00002 #define PATTERNSEARCHD2_H 00003 00004 #include <vec.h> 00005 #include <cirbuffarr.h> 00006 #include <typeop.h> 00007 #include <print.h> 00008 00023 template< typename EXP > 00024 class patternsearchD2 00025 { 00026 public: 00027 00028 typedef typename typeop<EXP>::Tbare::Ttype T; 00029 typedef typename typeop<EXP>::Tbare::XItype XI; 00030 00032 EXP exp; 00033 00035 T hstep; 00036 00038 uintc dim; 00039 00041 T* coef; 00042 00044 patternsearchD2( EXP exp_, uintc dim_, T hstep_=1.0); 00045 00047 ~patternsearchD2(); 00048 00050 cirbuffarr< T > xi0; 00051 00053 vec< XI, T > xivec; 00054 00056 void reset(); 00057 00059 void reset( T const * x0 ) 00060 { exp.reset(x0); reset(); } 00061 00063 void operator ++ (); 00064 00065 bool const operator ! () const 00066 { return exp.valid; } 00067 00068 }; 00069 00070 00071 /* 00072 *--------------------------------------------------------------- 00073 * Implementation 00074 */ 00075 00076 template< typename EXP > 00077 patternsearchD2<EXP>::~patternsearchD2() 00078 { 00079 delete[] coef; 00080 }; 00081 00082 template< typename EXP > 00083 void patternsearchD2<EXP>::reset() 00084 { 00085 exp.reset(); 00086 xi0.push(exp.xi); 00087 for (uint i=1; i<dim; ++i) 00088 exp.move(); 00089 xi0.push(exp.xi); 00090 } 00091 00092 00093 template< typename EXP > 00094 void patternsearchD2<EXP>::operator ++ () 00095 { 00096 uintc N(exp.N); 00097 uint k; 00098 uint j; 00099 for (bool loop=true; loop;) 00100 { 00101 xi0.push(exp.xi); 00102 00103 for (k=0; k<N; ++k) 00104 { 00105 exp.xi[k] = coef[0]*xi0[0][k]; 00106 for (j=1; j<=dim; ++j) 00107 exp.xi[k] += coef[j]*xi0[j][k]; 00108 } 00109 00110 // xivec[k] = coef[0]*xi0[0][k] + coef[1]*xi0[1][k] 00111 // + coef[2]*xi0[2][k]; 00112 00113 exp.movelocal(); 00114 00115 loop = exp.evaluate(); 00116 } 00117 xi0.copyto(exp.xi); 00118 } 00119 00120 00121 template< typename EXP > 00122 patternsearchD2<EXP>::patternsearchD2( EXP exp_, uintc dim_, T hstep_ ) 00123 : exp(exp_), hstep(hstep_), dim(dim_), coef(new T[dim_+1]), 00124 xi0(dim+3,exp.N), xivec(exp.xi,exp.N) 00125 { 00126 assert(dim>0); 00127 00128 uintc w(dim+1); 00129 00130 T t0[w]; 00131 vec< T*, T > t(t0,w); 00132 00133 T xop[w]; 00134 vec< T*, T > x(xop,w); 00135 x.identity(0); 00136 00137 vec< T*, T > coefv(coef,w); 00138 00139 coefv = x; 00140 T hfactor(1); 00141 for (uint k=1; k<w; ++k) 00142 { 00143 hfactor *= (hstep/(T)k); 00144 x.difference(); 00145 t = x; 00146 t *= hfactor; 00147 coefv += t; 00148 } 00149 00150 //cout << printvecfunc(coef,dim+1) << endl; 00151 00152 /* 00153 00154 coef[0] = hstep*hstep*0.5 + hstep + 1.0; 00155 coef[1] = -hstep-hstep*hstep; 00156 coef[2] = hstep*hstep*0.5; 00157 */ 00158 00159 00160 } 00161 00162 00163 #endif 00164 00165
1.5.8