void Minimize1<Real>::GetMinimum (Real t0, Real f0, Real tm, Real fm, Real t1, Real f1, int level) { if (level-- == 0) { return; } if ((t1 - tm)*(f0 - fm) > (tm - t0)*(fm - f1)) { // The quadratic fit has positive second derivative at the midpoint. if (f1 > f0) { if (fm >= f0) { // Increasing, repeat on [t0,tm]. GetMinimum(t0, f0, tm, fm, level); } else { // Not monotonic, have a bracket. GetBracketedMinimum(t0, f0, tm, fm, t1, f1, level); } } else if (f1 < f0) { if (fm >= f1) { // Decreasing, repeat on [tm,t1]. GetMinimum(tm, fm, t1, f1, level); } else { // Not monotonic, have a bracket. GetBracketedMinimum(t0, f0, tm, fm, t1, f1, level); } } else { // Constant, repeat on [t0,tm] and [tm,t1]. GetMinimum(t0, f0, tm, fm, level); GetMinimum(tm, fm, t1, f1, level); } } else { // The quadratic fit has a nonpositive second derivative at the // midpoint. if (f1 > f0) { // Repeat on [t0,tm]. GetMinimum(t0, f0, tm, fm, level); } else if ( f1 < f0 ) { // Repeat on [tm,t1]. GetMinimum(tm, fm, t1, f1, level); } else { // Repeat on [t0,tm] and [tm,t1]. GetMinimum(t0, f0, tm, fm, level); GetMinimum(tm, fm, t1, f1, level); } } }
//---------------------------------------------------------------------------- void Minimize1D::GetMinimum (float fT0, float fF0, float fTm, float fFm, float fT1, float fF1, int iLevel) { if ( fF0 < m_fFMin ) { m_fTMin = fT0; m_fFMin = fF0; } if ( fFm < m_fFMin ) { m_fTMin = fTm; m_fFMin = fFm; } if ( fF1 < m_fFMin ) { m_fTMin = fT1; m_fFMin = fF1; } if ( iLevel-- == 0 ) return; if ( (fT1 - fTm)*(fF0 - fFm) > (fTm - fT0)*(fFm - fF1) ) { // quadratic fit has positive second derivative at midpoint if ( fF1 > fF0 ) { if ( fFm >= fF0 ) { // increasing, repeat on [t0,tm] GetMinimum(fT0,fF0,fTm,fFm,iLevel); } else { // not monotonic, have a bracket GetBracketedMinimum(fT0,fF0,fTm,fFm,fT1,fF1,iLevel); } } else if ( fF1 < fF0 ) { if ( fFm >= fF1 ) { // decreasing, repeat on [tm,t1] GetMinimum(fTm,fFm,fT1,fF1,iLevel); } else { // not monotonic, have a bracket GetBracketedMinimum(fT0,fF0,fTm,fFm,fT1,fF1,iLevel); } } else { // constant, repeat on [t0,tm] and [tm,t1] GetMinimum(fT0,fF0,fTm,fFm,iLevel); GetMinimum(fTm,fFm,fT1,fF1,iLevel); } } else { // quadratic fit has nonpositive second derivative at midpoint if ( fF1 > fF0 ) { // repeat on [t0,tm] GetMinimum(fT0,fF0,fTm,fFm,iLevel); } else if ( fF1 < fF0 ) { // repeat on [tm,t1] GetMinimum(fTm,fFm,fT1,fF1,iLevel); } else { // repeat on [t0,tm] and [tm,t1] GetMinimum(fT0,fF0,fTm,fFm,iLevel); GetMinimum(fTm,fFm,fT1,fF1,iLevel); } } }
void Minimize1<Real>::GetMinimum (Real t0, Real f0, Real t1, Real f1, int level) { if (level-- == 0) { return; } Real tm = ((Real)0.5)*(t0 + t1); Real fm = mFunction(tm, mUserData); if (fm < mFMin) { mTMin = tm; mFMin = fm; } if (f0 - ((Real)2)*fm + f1 > (Real)0) { // The quadratic fit has positive second derivative at the midpoint. if (f1 > f0) { if (fm >= f0) { // Increasing, repeat on [t0,tm]. GetMinimum(t0, f0, tm, fm, level); } else { // Not monotonic, have a bracket. GetBracketedMinimum(t0, f0, tm, fm, t1, f1, level); } } else if (f1 < f0) { if (fm >= f1) { // Decreasing, repeat on [tm,t1]. GetMinimum(tm, fm, t1, f1, level); } else { // Not monotonic, have a bracket. GetBracketedMinimum(t0, f0, tm, fm, t1, f1, level); } } else { // Constant, repeat on [t0,tm] and [tm,t1]. GetMinimum(t0, f0, tm, fm, level); GetMinimum(tm, fm, t1, f1, level); } } else { // The quadratic fit has nonpositive second derivative at the // midpoint. if (f1 > f0) { // Repeat on [t0,tm]. GetMinimum(t0, f0, tm, fm, level); } else if (f1 < f0) { // Repeat on [tm,t1]. GetMinimum(tm, fm, t1, f1, level); } else { // Repeat on [t0,tm] and [tm,t1]. GetMinimum(t0, f0, tm, fm, level); GetMinimum(tm, fm, t1, f1, level); } } }
//---------------------------------------------------------------------------- void Minimize1D::GetMinimum (float fT0, float fF0, float fT1, float fF1, int iLevel) { if ( fF0 < m_fFMin ) { m_fTMin = fT0; m_fFMin = fF0; } if ( fF1 < m_fFMin ) { m_fTMin = fT1; m_fFMin = fF1; } if ( iLevel-- == 0 ) return; float fTm = 0.5f*(fT0+fT1); float fFm = m_oF(fTm,m_pvUserData); if ( fF0 - 2.0f*fFm + fF1 > 0.0f ) { // quadratic fit has positive second derivative at midpoint if ( fF1 > fF0 ) { if ( fFm >= fF0 ) { // increasing, repeat on [t0,tm] GetMinimum(fT0,fF0,fTm,fFm,iLevel); } else { // not monotonic, have a bracket GetBracketedMinimum(fT0,fF0,fTm,fFm,fT1,fF1,iLevel); } } else if ( fF1 < fF0 ) { if ( fFm >= fF1 ) { // decreasing, repeat on [tm,t1] GetMinimum(fTm,fFm,fT1,fF1,iLevel); } else { // not monotonic, have a bracket GetBracketedMinimum(fT0,fF0,fTm,fFm,fT1,fF1,iLevel); } } else { // constant, repeat on [t0,tm] and [tm,t1] GetMinimum(fT0,fF0,fTm,fFm,iLevel); GetMinimum(fTm,fFm,fT1,fF1,iLevel); } } else { // quadratic fit has nonpositive second derivative at midpoint if ( fF1 > fF0 ) { // repeat on [t0,tm] GetMinimum(fT0,fF0,fTm,fFm,iLevel); } else if ( fF1 < fF0 ) { // repeat on [tm,t1] GetMinimum(fTm,fFm,fT1,fF1,iLevel); } else { // repeat on [t0,tm] and [tm,t1] GetMinimum(fT0,fF0,fTm,fFm,iLevel); GetMinimum(fTm,fFm,fT1,fF1,iLevel); } } }