OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Private Member Functions | List of all members
FindMaximum2 Class Referenceabstract

#include <newmatnl.h>

Inheritance diagram for FindMaximum2:
MLE_D_FI NonLinearLeastSquares

Public Member Functions

void Fit (ColumnVector &, int)
 
virtual ~FindMaximum2 ()
 

Private Member Functions

virtual void Value (const ColumnVector &, bool, Real &, bool &)=0
 
virtual bool NextPoint (ColumnVector &, Real &)=0
 
virtual Real LastDerivative (const ColumnVector &)=0
 

Detailed Description

Definition at line 171 of file newmatnl.h.

Constructor & Destructor Documentation

◆ ~FindMaximum2()

virtual FindMaximum2::~FindMaximum2 ( )
inlinevirtual

Definition at line 178 of file newmatnl.h.

178 {} // to keep gnu happy

Member Function Documentation

◆ Fit()

void FindMaximum2::Fit ( ColumnVector Theta,
int  n_it 
)

Definition at line 21 of file newmatnl.cpp.

References GeneralMatrix::Nrows(), Tracer::ReName(), and x.

Referenced by NonLinearLeastSquares::Fit(), and MLE_D_FI::Fit().

22 {
23  Tracer tr("FindMaximum2::Fit");
24  enum State {Start, Restart, Continue, Interpolate, Extrapolate,
25  Fail, Convergence};
26  State TheState = Start;
27  Real z,w,x,x2,g,l1,l2,l3,d1,d2=0,d3;
28  ColumnVector Theta1, Theta2, Theta3;
29  int np = Theta.Nrows();
30  ColumnVector H1(np), H3, HP(np), K, K1(np);
31  bool oorg, conv;
32  int counter = 0;
33  Theta1 = Theta; HP = 0.0; g = 0.0;
34 
35  // This is really a set of gotos and labels, but they do not work
36  // correctly in AT&T C++ and Sun 4.01 C++.
37 
38  for(;;)
39  {
40  switch (TheState)
41  {
42  case Start:
43  tr.ReName("FindMaximum2::Fit/Start");
44  Value(Theta1, true, l1, oorg);
45  if (oorg) Throw(ProgramException("invalid starting value\n"));
46 
47  case Restart:
48  tr.ReName("FindMaximum2::Fit/ReStart");
49  conv = NextPoint(H1, d1);
50  if (conv) { TheState = Convergence; break; }
51  if (counter++ > n_it) { TheState = Fail; break; }
52 
53  z = 1.0 / sqrt(d1);
54  H3 = H1 * z; K = (H3 - HP) * g; HP = H3;
55  g = 0.0; // de-activate to use curved projection
56  if (g==0.0) K1 = 0.0; else K1 = K * 0.2 + K1 * 0.6;
57  // (K - K1) * alpha + K1 * (1 - alpha)
58  // = K * alpha + K1 * (1 - 2 * alpha)
59  K = K1 * d1; g = z;
60 
61  case Continue:
62  tr.ReName("FindMaximum2::Fit/Continue");
63  Theta2 = Theta1 + H1 + K;
64  Value(Theta2, false, l2, oorg);
65  if (counter++ > n_it) { TheState = Fail; break; }
66  if (oorg)
67  {
68  H1 *= 0.5; K *= 0.25; d1 *= 0.5; g *= 2.0;
69  TheState = Continue; break;
70  }
71  d2 = LastDerivative(H1 + K * 2.0);
72 
73  case Interpolate:
74  tr.ReName("FindMaximum2::Fit/Interpolate");
75  z = d1 + d2 - 3.0 * (l2 - l1);
76  w = z * z - d1 * d2;
77  if (w < 0.0) { TheState = Extrapolate; break; }
78  w = z + sqrt(w);
79  if (1.5 * w + d1 < 0.0)
80  { TheState = Extrapolate; break; }
81  if (d2 > 0.0 && l2 > l1 && w > 0.0)
82  { TheState = Extrapolate; break; }
83  x = d1 / (w + d1); x2 = x * x; g /= x;
84  Theta3 = Theta1 + H1 * x + K * x2;
85  Value(Theta3, true, l3, oorg);
86  if (counter++ > n_it) { TheState = Fail; break; }
87  if (oorg)
88  {
89  if (x <= 1.0)
90  { x *= 0.5; x2 = x*x; g *= 2.0; d1 *= x; H1 *= x; K *= x2; }
91  else
92  {
93  x = 0.5 * (x-1.0); x2 = x*x; Theta1 = Theta2;
94  H1 = (H1 + K * 2.0) * x;
95  K *= x2; g = 0.0; d1 = x * d2; l1 = l2;
96  }
97  TheState = Continue; break;
98  }
99 
100  if (l3 >= l1 && l3 >= l2)
101  { Theta1 = Theta3; l1 = l3; TheState = Restart; break; }
102 
103  d3 = LastDerivative(H1 + K * 2.0);
104  if (l1 > l2)
105  { H1 *= x; K *= x2; Theta2 = Theta3; d1 *= x; d2 = d3*x; }
106  else
107  {
108  Theta1 = Theta2; Theta2 = Theta3;
109  x -= 1.0; x2 = x*x; g = 0.0; H1 = (H1 + K * 2.0) * x;
110  K *= x2; l1 = l2; l2 = l3; d1 = x*d2; d2 = x*d3;
111  if (d1 <= 0.0) { TheState = Start; break; }
112  }
113  TheState = Interpolate; break;
114 
115  case Extrapolate:
116  tr.ReName("FindMaximum2::Fit/Extrapolate");
117  Theta1 = Theta2; g = 0.0; K *= 4.0; H1 = (H1 * 2.0 + K);
118  d1 = 2.0 * d2; l1 = l2;
119  TheState = Continue; break;
120 
121  case Fail:
122  Throw(ConvergenceException(Theta));
123 
124  case Convergence:
125  Theta = Theta1; return;
126  }
127  }
128 }
virtual void Value(const ColumnVector &, bool, Real &, bool &)=0
ossim_uint32 x
double Real
Definition: include.h:57
int Nrows() const
Definition: newmat.h:430
virtual bool NextPoint(ColumnVector &, Real &)=0
virtual Real LastDerivative(const ColumnVector &)=0

◆ LastDerivative()

virtual Real FindMaximum2::LastDerivative ( const ColumnVector )
privatepure virtual

Implemented in MLE_D_FI, and NonLinearLeastSquares.

◆ NextPoint()

virtual bool FindMaximum2::NextPoint ( ColumnVector ,
Real &   
)
privatepure virtual

Implemented in MLE_D_FI, and NonLinearLeastSquares.

◆ Value()

virtual void FindMaximum2::Value ( const ColumnVector ,
bool  ,
Real &  ,
bool &   
)
privatepure virtual

Implemented in MLE_D_FI, and NonLinearLeastSquares.


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