proj home

Files   Classes   Functions   Hierarchy  

exploreh< FN, XI, T > Class Template Reference

N dimensional Pattern search minimization algorithm. More...

#include <exploreh.h>

Collaboration diagram for exploreh< FN, XI, T >:

List of all members.

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.
ostreamprint (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.
Thi
 The step sizes.
uintc N
 The number of dimensions.
Th0
 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.


Detailed Description

template<typename FN, typename XI, typename T>
class exploreh< FN, XI, T >

N dimensional Pattern search minimization algorithm.

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.


Member Typedef Documentation

template<typename FN, typename XI, typename T>
typedef FN exploreh< FN, XI, T >::FNtype

XI type information exported.

Definition at line 41 of file exploreh.h.

template<typename FN, typename XI, typename T>
typedef T exploreh< FN, XI, T >::Ttype

T type information exported.

Definition at line 45 of file exploreh.h.

template<typename FN, typename XI, typename T>
typedef XI exploreh< FN, XI, T >::XItype

XI type information exported.

Definition at line 43 of file exploreh.h.


Constructor & Destructor Documentation

template<typename FN , typename XI , typename T >
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().

00239   : valid(false), N(N_), indexmax(indexmax_)
00240 {
00241   init();
00242   h0Set(h0step);
00243 }

template<typename FN , typename XI , typename T >
exploreh< FN, XI, T >::exploreh ( FN  fn_,
uintc  N_,
T const   h0step = 20.0,
uintc  indexmax_ = 500 
) [inline]

FN can be a reference.

Definition at line 247 of file exploreh.h.

References init().

00253   : fn(fn_), valid(false), N(N_), indexmax(indexmax_)
00254 {
00255   init();
00256   h0Set(h0step);
00257 }

template<typename FN , typename XI , typename T >
exploreh< FN, XI, T >::~exploreh (  )  [inline]

Clean up memory allocations.

Definition at line 269 of file exploreh.h.

References exploreh< FN, XI, T >::clean().

00270 {
00271   clean();
00272 }


Member Function Documentation

template<typename FN , typename XI , typename T >
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().

00261 {
00262   delete[] hi;
00263   delete[] h0;
00264   hi=0;
00265   h0=0;
00266 }

template<typename FN, typename XI, typename T>
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   }

template<typename FN , typename XI , typename T >
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 }

template<typename FN , typename XI , typename T >
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 }

template<typename FN , typename XI , typename T >
void exploreh< FN, XI, T >::move (  )  [inline]

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 }

template<typename FN , typename XI , typename T >
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 }

template<typename FN, typename XI, typename T>
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; }

template<typename FN , typename XI , typename T >
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 }

template<typename FN , typename XI , typename T >
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 }

template<typename FN , typename XI , typename T >
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 }

template<typename FN , typename XI , typename T >
void exploreh< FN, XI, T >::reset (  )  [inline]

template<typename FN, typename XI, typename T>
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().

00097     { xi = fn.xi = xi_; }


Member Data Documentation

template<typename FN, typename XI, typename T>
T exploreh< FN, XI, T >::fmin

template<typename FN, typename XI, typename T>
FN exploreh< FN, XI, T >::fn

template<typename FN, typename XI, typename T>
T* exploreh< FN, XI, T >::h0

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().

template<typename FN, typename XI, typename T>
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++().

template<typename FN, typename XI, typename T>
T* exploreh< FN, XI, T >::hi

template<typename FN, typename XI, typename T>
uint exploreh< FN, XI, T >::index

template<typename FN, typename XI, typename T>
uint exploreh< FN, XI, T >::indexmax

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++().

template<typename FN, typename XI, typename T>
uintc exploreh< FN, XI, T >::N

template<typename FN, typename XI, typename T>
bool exploreh< FN, XI, T >::valid

template<typename FN, typename XI, typename T>
XI exploreh< FN, XI, T >::xi


The documentation for this class was generated from the following file:

Generated on Fri Mar 4 00:49:56 2011 for Chelton Evans Source by  doxygen 1.5.8