00001 // LevenbergMarquardtMinimizer.h: interface for the LevenbergMarquardtMinimizer class. 00002 // 00004 00005 #if !defined(AFX_POSITIVEDEFINITELEVENBERGMARQUARDTMINIMIZER_H__B872BB8D_BEEB_412D_BDC2_43D6F067FD89__INCLUDED_) 00006 #define AFX_POSITIVEDEFINITELEVENBERGMARQUARDTMINIMIZER_H__B872BB8D_BEEB_412D_BDC2_43D6F067FD89__INCLUDED_ 00007 00008 #if _MSC_VER > 1000 00009 #pragma once 00010 #endif // _MSC_VER > 1000 00011 00012 // XXX debug 00013 #include <iostream> 00014 00015 #ifdef _WIN32 00016 #include <mkl.h> 00017 #else 00018 #include "lapack.h" 00019 #endif 00020 00021 #include <fstream> 00022 #include <cmath> 00023 #include <cfloat> 00024 //#include <mkl.h> 00025 #include <assert.h> 00026 #include "Minimizer.h" 00027 #include "NLLSMinimizable.h" 00028 #include "ParameterFilter.h" 00029 using namespace std; 00030 00031 class CPositiveDefiniteLevenbergMarquardtMinimizer : public Minimizer 00032 { 00033 public: 00034 CPositiveDefiniteLevenbergMarquardtMinimizer(); 00035 CPositiveDefiniteLevenbergMarquardtMinimizer(CParameterFilter *pFilter, double marquardt, double chiTol, double gradTol, int nIterations); 00036 virtual ~CPositiveDefiniteLevenbergMarquardtMinimizer(); 00037 double Minimize(double *parameters, Minimizable *minimizable); 00038 void ComputeDerivativeInformation(double *parameters, NLLSMinimizable *nlls); 00039 // Solve LM system using Singular Value Decomp. 00040 void SVDSolveMarquardtSystem(double *deltaP); 00041 // Solve LM system using LU factorization 00042 void LUSolveMarquardtSystem(double *deltaP); 00043 void SetBounds(double *parameters); 00044 void CheckBounds(double *parameters); 00045 private: 00046 bool m_bBreakFlag; // Set to true to break out of the routine 00047 bool m_bReconditionFlag; // Set to true to recondition the LM Hessian 00048 double m_dMarquardt; // Marquardt parameter 00049 int m_iNIterations; // Maximum number of LM iterations 00050 double m_dChiSqTol; // Fractional stopping criterion for Chi squared 00051 double m_dGradTol; // Stopping criterion for the norm of the gradient 00052 double** m_pdAlpha; // (1/2)*approximate Hessian matrix 00053 double* m_pdBeta; // (-1/2)*gradient 00054 double* m_pdUpperBounds; // Keeps parameters from getting too big 00055 double* m_pdLowerBounds; // Keeps parameters from getting too small 00056 int m_iNResiduals; // number of residuals in NLLSMinimizable 00057 CParameterFilter *m_pFilter; // Filter if parameters need to be kept positive 00058 }; 00059 00060 #endif // !defined(AFX_POSITIVEDEFINITELEVENBERGMARQUARDTMINIMIZER_H__B872BB8D_BEEB_412D_BDC2_43D6F067FD89__INCLUDED_)