proj home

Files   Classes   Functions   Hierarchy  

lineoptimizerparabola< LNPATH, T > Class Template Reference

Minimize fn on a 1D path in N dimensional space by fitting a parabola. More...

#include <lineoptimizerparabola.h>

Inheritance diagram for lineoptimizerparabola< LNPATH, T >:
Collaboration diagram for lineoptimizerparabola< LNPATH, T >:

List of all members.

Public Types

typedef lineoptimizergold2
< LNPATH, T
lopg

Public Member Functions

 lineoptimizerparabola (LNPATH linepath_)
 Initialize memory, does no computations.
bool const parabolamin (T &tnew, uintc a0, uintc a1, uintc a2) const
 From consecutive indexed points fit a parabola for tnew.
void operator++ ()
 One iteration of the line minimization algorithm.

Static Public Attributes

static T zero = 1E-20
 A small positive number used for zero tests.


Detailed Description

template<typename LNPATH, typename T>
class lineoptimizerparabola< LNPATH, T >

Minimize fn on a 1D path in N dimensional space by fitting a parabola.

Usage
Example
  double d1[] = {0.0,1.0,1.0};
  double x0[] = {0.0,0.0,0.0};
  parab2 fn;
  typedef linepathd1<parab2&,double*,double*,double> lpth;
  lineoptimizerparabola<lpth,double> 
    opt( lpth(3,fn,fn.xi,x0,d1) );

  opt.reset(0.0,5.0);
  for (uint i=0; i<10; ++i)
  {
    ++opt;
    opt.printstate();
  }

Definition at line 42 of file lineoptimizerparabola.h.


Member Typedef Documentation

template<typename LNPATH , typename T >
typedef lineoptimizergold2<LNPATH,T> lineoptimizerparabola< LNPATH, T >::lopg

Definition at line 46 of file lineoptimizerparabola.h.


Constructor & Destructor Documentation

template<typename LNPATH , typename T >
lineoptimizerparabola< LNPATH, T >::lineoptimizerparabola ( LNPATH  linepath_  )  [inline]

Initialize memory, does no computations.

Definition at line 52 of file lineoptimizerparabola.h.

00052                                            :
00053     lineoptimizergold2<LNPATH,T>(linepath_) {}


Member Function Documentation

template<typename LNPATH , typename T >
void lineoptimizerparabola< LNPATH, T >::operator++ (  )  [inline]

One iteration of the line minimization algorithm.

Reimplemented from lineoptimizergold2< LNPATH, T >.

Definition at line 110 of file lineoptimizerparabola.h.

References lineoptimizergold2< LNPATH, T >::ai, lineoptimizergold2< LNPATH, T >::fti, lineoptimizergold2< LNPATH, T >::goldratio, lineoptimizergold2< LNPATH, T >::lengthgold, lineoptimizergold2< LNPATH, T >::linepath, lineoptimizerparabola< LNPATH, T >::parabolamin(), lineoptimizergold2< LNPATH, T >::printstate(), lineoptimizergold2< LNPATH, T >::resetInnerTwoPoints(), lineoptimizergold2< LNPATH, T >::ti, and lineoptimizergold2< LNPATH, T >::verify().

00111 {
00112   lopg::lengthgold *= lopg::goldratio;
00113 //cout << SHOW(lengthgold) << endl;
00114 
00115   // Minimization
00116   uint rej;
00117 
00118   T w;
00119 
00120   //printstate();
00121 
00122   // Test - reject x0 if successful.
00123   if (lopg::fti[lopg::ai[2]]<lopg::fti[lopg::ai[1]])
00124   {
00125 
00126     // If parabola minimization fails, do two gold section minimizations
00127     if (parabolamin(w,lopg::ai[1],lopg::ai[2],lopg::ai[3])==false)
00128     {
00129 cout << "parabolamin failed in x0 rejection." << endl;
00130 
00131       rej = lopg::ai[0];
00132 //cout << "parab min failed, rejecting x0" << endl;
00133 lopg::printstate();
00134       lopg::ai[0] = lopg::ai[1];
00135       lopg::ai[1] = rej;
00136       lopg::resetInnerTwoPoints();
00137 
00138       return;
00139     }
00140 
00141 //cout << "Reject x0" << endl;
00142     rej = lopg::ai[0];
00143     lopg::ti[rej] = w;
00144     lopg::linepath.fneval(lopg::fti[rej],lopg::ti[rej]);
00145     lopg::ai[0] = lopg::ai[1];
00146 
00147     if (w<lopg::ti[lopg::ai[2]])
00148       lopg::ai[1] = rej;
00149     else
00150     {
00151       lopg::ai[1] = lopg::ai[2];
00152       lopg::ai[2] = rej;
00153     }
00154 
00155     //convergencetest();
00156 
00157     //printstate();
00158     assert(lopg::verify());
00159     return;
00160   }
00161 
00162 
00163 //cout << "Reject x3" << endl;
00164   rej = lopg::ai[3];
00165 
00166   // Test - reject x3 if successful.
00167   if (lopg::fti[lopg::ai[1]]<lopg::fti[lopg::ai[2]])
00168   {
00169 
00170     // If parabola minimization fails, do two gold section minimizations
00171     if (parabolamin(w,lopg::ai[0],lopg::ai[1],lopg::ai[2])==false)
00172     {
00173 cout << "parabolamin failed in x3 rejection." << endl;
00174 //cout << "parab min failed, rejecting x3" << endl;
00175       rej = lopg::ai[3];
00176 
00177       lopg::ai[3] = lopg::ai[2];
00178       lopg::ai[2] = rej;
00179       lopg::resetInnerTwoPoints();
00180 
00181       return;
00182     }
00183 
00184 //cout << "Reject x0" << endl;
00185     rej = lopg::ai[3];
00186     lopg::ti[rej] = w;
00187     lopg::linepath.fneval(lopg::fti[rej],lopg::ti[rej]);
00188     lopg::ai[3] = lopg::ai[2];
00189 
00190     if (w<lopg::ti[lopg::ai[1]])
00191     {
00192       lopg::ai[2] = lopg::ai[1];
00193       lopg::ai[1] = rej;
00194     }
00195     else
00196     {
00197       lopg::ai[2] = rej;
00198     }
00199 
00200     //printstate();
00201     assert(lopg::verify());
00202     return;
00203   }
00204 
00205   // No interval can be rejected because both points are the same height.
00206   // This is a hack. If the value between 1 and 2 is the same then the method
00207   // will fail.  
00208   lopg::ti[lopg::ai[1]] += lopg::ti[ lopg::ai[2] ];
00209   lopg::ti[lopg::ai[1]] *= (T)0.5;
00210   lopg::linepath.fneval(lopg::fti[lopg::ai[1]],lopg::ti[lopg::ai[1]]);
00211 
00212 }

template<typename LNPATH , typename T >
bool const lineoptimizerparabola< LNPATH, T >::parabolamin ( T tnew,
uintc  a0,
uintc  a1,
uintc  a2 
) const [inline]

From consecutive indexed points fit a parabola for tnew.

Definition at line 217 of file lineoptimizerparabola.h.

Referenced by lineoptimizerparabola< LNPATH, T >::operator++().

00223 {
00224 // Scale and minimize
00225 // max/min at -b/2a = (-q^2*f2+q^2*f0+f1-f0)/(2*(f1-f0+q(f0-f2))
00226 // where q=(t1-t0)/(t2-t0)
00227   assert( lopg::ti[a2] != lopg::ti[a0] );
00228 
00229   T f5 = lopg::fti[a1]-lopg::fti[a0];
00230   T q = (lopg::ti[a1]-lopg::ti[a0])/(lopg::ti[a2]-lopg::ti[a0]);
00231   T den = (f5+q*(lopg::fti[a0]-lopg::fti[a2]))*2;
00232   if ( den*den < zero )
00233     return false;
00234   T num = q*q*(lopg::fti[a0]-lopg::fti[a2])+f5;
00235   T w = num/den;
00236   if (w<=(T)0.0)
00237     return false;
00238   if (w>=(T)1.0)
00239     return false;
00240 
00241   tnew = lopg::ti[a0] + (lopg::ti[a2]-lopg::ti[a0])*w;
00242 
00243   return true;
00244 }


Member Data Documentation

template<typename LNPATH , typename T >
T lineoptimizerparabola< LNPATH, T >::zero = 1E-20 [inline, static]

A small positive number used for zero tests.

Definition at line 49 of file lineoptimizerparabola.h.


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

Generated on Fri Mar 4 00:50:04 2011 for Chelton Evans Source by  doxygen 1.5.8