Files Classes Functions Hierarchy
#include <exploreh.h>
Public Types | |
| typedef FN | FNtype |
| XI type information exported. | |
| typedef XI | XItype |
| XI type information exported. | |
| typedef T | Ttype |
| T type information exported. | |
Public Member Functions | |
| void | h0Set (T const hnew) |
| Set all the h values to the new step length. | |
| bool const | evaluate () |
| Update the new state if successful. | |
| void | movelocal () |
| Move to local minimum from current position, ignores the current global minimum. | |
| void | move () |
| Perterb N dimensions till the state is changed. | |
| void | xiSet (XI xi_) |
| Set the pointers manually. | |
| exploreh (uintc N_, T const h0step=20.0, uintc indexmax_=500) | |
| Construct a N dimensional direct search object on FN. | |
| exploreh (FN fn_, uintc N_, T const h0step=20.0, uintc indexmax_=500) | |
| FN can be a reference. | |
| ~exploreh () | |
| Clean up memory allocations. | |
| bool const | operator! () const |
| Use this object as an iterator. | |
| void | reset () |
| Set the current position as the new minimum. | |
| void | reset (T const *x0) |
| The current state is evaluated for a new minimum. | |
| void | operator++ () |
| Iterate towards the minimum. | |
| ostream & | print (ostream &os) const |
| Display the minimum, hi, and xi. | |
Public Attributes | |
| FN | fn |
| The function to be minimized. | |
| uint | index |
| Local index. | |
| bool | valid |
| Associated with ++ operator and reset(). | |
| bool | hasStateChanged |
| Set to true when there is a change in state with ++ opertion. | |
| T | fmin |
| The minimum associated with the current state x. | |
| T * | hi |
| The step sizes. | |
| uintc | N |
| The number of dimensions. | |
| T * | h0 |
| N dimensional array of initial step sizes. | |
| XI | xi |
| N dimensional array of the current state. | |
| uint | indexmax |
| Each index has a counter, if during iteration this is exceeded valid is set to false. | |
Protected Member Functions | |
| void | clean () |
| Frees resources. | |
| void | init () |
| Allocate memory and state. | |
This is a 0 order aproximator. When all N variables are iterated over it becomes a 1st order approximator.
F is the function with the following interface. void FN::operator( T & val ) T * FN::xi The state xi is owned by FN. xi supports vector operations [].
be owned by either the minimizer (the default) or the function F.
Definition at line 31 of file exploreh.h.
| exploreh< FN, XI, T >::exploreh | ( | uintc | N_, | |
| T const | h0step = 20.0, |
|||
| uintc | indexmax_ = 500 | |||
| ) | [inline] |
Construct a N dimensional direct search object on FN.
Definition at line 238 of file exploreh.h.
References exploreh< FN, XI, T >::h0Set(), and exploreh< FN, XI, T >::init().
Clean up memory allocations.
Definition at line 269 of file exploreh.h.
References exploreh< FN, XI, T >::clean().
00270 { 00271 clean(); 00272 }
| void exploreh< FN, XI, T >::clean | ( | ) | [inline, protected] |
Frees resources.
Definition at line 260 of file exploreh.h.
References exploreh< FN, XI, T >::h0, and exploreh< FN, XI, T >::hi.
Referenced by exploreh< FN, XI, T >::~exploreh().
| bool const exploreh< FN, XI, T >::evaluate | ( | ) | [inline] |
Update the new state if successful.
Definition at line 65 of file exploreh.h.
References exploreh< FN, XI, T >::fmin, exploreh< FN, XI, T >::fn, and exploreh< FN, XI, T >::hasStateChanged.
Referenced by exploreh< FN, XI, T >::operator++().
00066 { 00067 T f1; 00068 fn(f1); 00069 if (f1<fmin) 00070 { 00071 fmin=f1; 00072 //cout << SHOW(fmin) << endl; 00073 hasStateChanged=true; 00074 return true; 00075 } 00076 return false; 00077 }
| void exploreh< FN, XI, T >::h0Set | ( | T const | hnew | ) | [inline] |
Set all the h values to the new step length.
Definition at line 288 of file exploreh.h.
References exploreh< FN, XI, T >::h0, exploreh< FN, XI, T >::hi, and exploreh< FN, XI, T >::N.
Referenced by exploreh< FN, XI, T >::exploreh().
00289 { 00290 assert(N!=0); 00291 00292 for (uint i=0; i<N; ++i) 00293 hi[i] = h0[i] = hnew; 00294 }
| void exploreh< FN, XI, T >::init | ( | ) | [inline, protected] |
Allocate memory and state.
Excludes x and h!
Definition at line 275 of file exploreh.h.
References exploreh< FN, XI, T >::fn, exploreh< FN, XI, T >::h0, exploreh< FN, XI, T >::hi, exploreh< FN, XI, T >::index, exploreh< FN, XI, T >::N, and exploreh< FN, XI, T >::xi.
Referenced by exploreh< FN, XI, T >::exploreh().
00276 { 00277 assert(N!=0); 00278 00279 index=0; 00280 hi = new T[N]; 00281 h0 = new T[N]; 00282 00283 xi = fn.xi; 00284 }
Perterb N dimensions till the state is changed.
Definition at line 202 of file exploreh.h.
References exploreh< FN, XI, T >::hasStateChanged, exploreh< FN, XI, T >::operator++(), and exploreh< FN, XI, T >::valid.
00203 { 00204 #ifndef NDEBUG 00205 if (valid==false) 00206 cout << "error: exploreh.valid is false" << endl; 00207 // assert(valid==true); 00208 #endif 00209 hasStateChanged=false; 00210 00211 for ( ; (hasStateChanged==false)&&valid; ) 00212 { 00213 operator ++ (); 00214 } 00215 00216 }
| void exploreh< FN, XI, T >::movelocal | ( | ) | [inline] |
Move to local minimum from current position, ignores the current global minimum.
Definition at line 170 of file exploreh.h.
References exploreh< FN, XI, T >::fmin, exploreh< FN, XI, T >::fn, exploreh< FN, XI, T >::hasStateChanged, exploreh< FN, XI, T >::operator++(), and exploreh< FN, XI, T >::valid.
00171 { 00172 00173 #ifndef NDEBUG 00174 if (valid==false) 00175 cout << "error" << endl; 00176 assert(valid==true); 00177 #endif 00178 00179 // preserve fmin; 00180 T fmin0 = fmin; 00181 fn(fmin); 00182 //resetposition(); 00183 /* 00184 T f1; 00185 fn(f1); 00186 fmin=f1; 00187 */ 00188 00189 hasStateChanged=false; 00190 00191 for ( ; (hasStateChanged==false)&&valid; ) 00192 { 00193 operator ++ (); 00194 } 00195 00196 // Restore fmin. 00197 fmin = fmin0; 00198 }
| bool const exploreh< FN, XI, T >::operator! | ( | ) | const [inline] |
Use this object as an iterator.
Definition at line 128 of file exploreh.h.
References exploreh< FN, XI, T >::valid.
00129 { return valid; }
| void exploreh< FN, XI, T >::operator++ | ( | ) | [inline] |
Iterate towards the minimum.
Definition at line 328 of file exploreh.h.
References exploreh< FN, XI, T >::evaluate(), exploreh< FN, XI, T >::hasStateChanged, exploreh< FN, XI, T >::hi, exploreh< FN, XI, T >::index, exploreh< FN, XI, T >::indexmax, exploreh< FN, XI, T >::N, SHOW, exploreh< FN, XI, T >::valid, and exploreh< FN, XI, T >::xi.
Referenced by exploreh< FN, XI, T >::move(), and exploreh< FN, XI, T >::movelocal().
00329 { 00330 //cout << "exploreh<FN,XI,T>::operator ++" << endl; 00331 00332 hasStateChanged=false; 00333 00334 if (!valid) 00335 return; 00336 00337 if (index>indexmax) 00338 { 00339 valid=false; 00340 #ifndef NDEBUG 00341 cout << "error: indexmax reached " << SHOW(index) << endl; 00342 #endif 00343 return; 00344 } 00345 00346 ++index; 00347 00348 for (uint i=0; i<N; ++i) 00349 { 00350 //cout << "***" << i << endl; 00351 xi[i] += hi[i]; 00352 if (evaluate()) 00353 continue; 00354 00355 hi[i] *= -1; 00356 xi[i] += hi[i]; 00357 xi[i] += hi[i]; 00358 if (evaluate()) 00359 continue; 00360 00361 xi[i] -= hi[i]; 00362 00363 // Golden Section Search. 00364 hi[i] *= 0.61803398875; 00365 } 00366 //cout << printvecfunc(xi,N) << endl; 00367 }
| ostream & exploreh< FN, XI, T >::print | ( | ostream & | os | ) | const [inline] |
Display the minimum, hi, and xi.
Definition at line 220 of file exploreh.h.
References exploreh< FN, XI, T >::fmin, exploreh< FN, XI, T >::hi, exploreh< FN, XI, T >::N, and exploreh< FN, XI, T >::xi.
Referenced by exploretest02(), exploretest03(), exploretest08(), and partialderivativetest01().
00221 { 00222 os << "fmin=" << fmin; 00223 00224 os << " h: " << hi[0]; 00225 for (uint i=1; i<N; ++i) 00226 os << " " << hi[i]; 00227 os << " x: " << xi[0]; 00228 for (uint i=1; i<N; ++i) 00229 os << " " << xi[i]; 00230 00231 os << endl; 00232 00233 return os; 00234 }
| void exploreh< FN, XI, T >::reset | ( | T const * | x0 | ) | [inline] |
The current state is evaluated for a new minimum.
The step sizes h are reset to h0. The index counters are set to 0. xi is set to x0.
Definition at line 311 of file exploreh.h.
References exploreh< FN, XI, T >::fmin, exploreh< FN, XI, T >::fn, exploreh< FN, XI, T >::h0, exploreh< FN, XI, T >::hi, exploreh< FN, XI, T >::index, exploreh< FN, XI, T >::N, exploreh< FN, XI, T >::valid, and exploreh< FN, XI, T >::xi.
00312 { 00313 index=0; 00314 for (uint i=0; i<N; ++i) 00315 { 00316 assert(h0[i]!=0.0); 00317 hi[i] = h0[i]; 00318 xi[i] = x0[i]; 00319 } 00320 valid=true; 00321 00322 fn(fmin); 00323 }
Set the current position as the new minimum.
Definition at line 297 of file exploreh.h.
References exploreh< FN, XI, T >::fmin, exploreh< FN, XI, T >::fn, exploreh< FN, XI, T >::h0, exploreh< FN, XI, T >::hi, exploreh< FN, XI, T >::index, exploreh< FN, XI, T >::N, and exploreh< FN, XI, T >::valid.
Referenced by explorepdtest02(), exploretest01(), exploretest02(), exploretest03(), exploretest04(), exploretest05(), exploretest06(), exploretest07(), exploretest08(), minimizecomparetest01(), minimizecomparetest02(), partialderivativetest01(), and test11().
00298 { 00299 index=0; 00300 for (uint i=0; i<N; ++i) 00301 { 00302 assert(h0[i]!=0.0); 00303 hi[i] = h0[i]; 00304 } 00305 valid=true; 00306 00307 fn(fmin); 00308 }
| void exploreh< FN, XI, T >::xiSet | ( | XI | xi_ | ) | [inline] |
Set the pointers manually.
eg if fn does not manage xi.
Definition at line 96 of file exploreh.h.
References exploreh< FN, XI, T >::fn, and exploreh< FN, XI, T >::xi.
Referenced by exploretest01(), and exploretest08().
The minimum associated with the current state x.
Definition at line 57 of file exploreh.h.
Referenced by exploreh< FN, XI, T >::evaluate(), explorepdtest02(), exploretest08(), minimizecomparetest01(), minimizecomparetest02(), exploreh< FN, XI, T >::movelocal(), exploreh< FN, XI, T >::print(), exploreh< FN, XI, T >::reset(), and test11().
The function to be minimized.
Definition at line 48 of file exploreh.h.
Referenced by exploreh< FN, XI, T >::evaluate(), explorepdtest02(), exploretest03(), exploretest04(), exploretest08(), exploreh< FN, XI, T >::init(), minimizecomparetest01(), minimizecomparetest02(), exploreh< FN, XI, T >::movelocal(), partialderivativetest01(), exploreh< FN, XI, T >::reset(), test08(), test11(), and exploreh< FN, XI, T >::xiSet().
N dimensional array of initial step sizes.
Definition at line 90 of file exploreh.h.
Referenced by exploreh< FN, XI, T >::clean(), exploreh< FN, XI, T >::h0Set(), exploreh< FN, XI, T >::init(), and exploreh< FN, XI, T >::reset().
| bool exploreh< FN, XI, T >::hasStateChanged |
Set to true when there is a change in state with ++ opertion.
Definition at line 55 of file exploreh.h.
Referenced by exploreh< FN, XI, T >::evaluate(), exploretest04(), exploreh< FN, XI, T >::move(), exploreh< FN, XI, T >::movelocal(), and exploreh< FN, XI, T >::operator++().
The step sizes.
Definition at line 59 of file exploreh.h.
Referenced by exploreh< FN, XI, T >::clean(), exploretest03(), exploreh< FN, XI, T >::h0Set(), exploreh< FN, XI, T >::init(), exploreh< FN, XI, T >::operator++(), exploreh< FN, XI, T >::print(), and exploreh< FN, XI, T >::reset().
Local index.
Definition at line 51 of file exploreh.h.
Referenced by exploreh< FN, XI, T >::init(), exploreh< FN, XI, T >::operator++(), and exploreh< FN, XI, T >::reset().
Each index has a counter, if during iteration this is exceeded valid is set to false.
Definition at line 101 of file exploreh.h.
Referenced by exploretest01(), exploretest02(), exploretest04(), exploretest05(), exploretest06(), exploretest07(), exploretest08(), and exploreh< FN, XI, T >::operator++().
The number of dimensions.
Definition at line 87 of file exploreh.h.
Referenced by exploreh< FN, XI, T >::h0Set(), exploreh< FN, XI, T >::init(), exploreh< FN, XI, T >::operator++(), exploreh< FN, XI, T >::print(), and exploreh< FN, XI, T >::reset().
Associated with ++ operator and reset().
Definition at line 53 of file exploreh.h.
Referenced by exploreh< FN, XI, T >::move(), exploreh< FN, XI, T >::movelocal(), exploreh< FN, XI, T >::operator!(), exploreh< FN, XI, T >::operator++(), and exploreh< FN, XI, T >::reset().
N dimensional array of the current state.
Definition at line 93 of file exploreh.h.
Referenced by exploretest01(), exploretest02(), exploretest04(), exploretest05(), exploretest06(), exploretest07(), exploreh< FN, XI, T >::init(), minimizecomparetest01(), exploreh< FN, XI, T >::operator++(), exploreh< FN, XI, T >::print(), exploreh< FN, XI, T >::reset(), test08(), test11(), and exploreh< FN, XI, T >::xiSet().
1.5.8