00001 // RobustLevenbergMarquardtMinimizer.h: interface for the CRobustLevenbergMarquardtMinimizer class. 00002 // 00004 00005 #if !defined(AFX_ROBUSTLEVENBERGMARQUARDTMINIMIZER_H__699CF063_2C7A_408C_94EE_B02FB5D42FC3__INCLUDED_) 00006 #define AFX_ROBUSTLEVENBERGMARQUARDTMINIMIZER_H__699CF063_2C7A_408C_94EE_B02FB5D42FC3__INCLUDED_ 00007 00008 #if _MSC_VER > 1000 00009 #pragma once 00010 #endif // _MSC_VER > 1000 00011 00012 #ifdef _WIN32 00013 #include <mkl.h> 00014 #else 00015 #include "lapack.h" 00016 #define __min min 00017 #define __max max 00018 #endif 00019 00020 #include <iostream> 00021 #include <fstream> 00022 #include <cmath> 00023 #include <cfloat> 00024 //#include <mkl.h> 00025 #include <assert.h> 00026 #include "NLLSMinimizable.h" 00027 #include "ParameterFilter.h" 00028 #include "Minimizer.h" 00029 using namespace std; 00030 00031 class CRobustLevenbergMarquardtMinimizer : public Minimizer 00032 { 00033 public: 00034 CRobustLevenbergMarquardtMinimizer(); 00035 CRobustLevenbergMarquardtMinimizer(CParameterFilter *pFilter, double marquardt, double chiTol, double gradTol, int nIterations); 00036 virtual ~CRobustLevenbergMarquardtMinimizer(); 00037 double Minimize(double *parameters, Minimizable *minimizable); 00038 void ComputeDerivativeInformation(double *parameters, NLLSMinimizable *nlls); 00039 // solve LM system without explicit calculation of the Hessian 00040 void QRSolveMarquardtSystem(double *deltaP); 00041 private: 00042 bool m_bBreakFlag; // Set to true to break out of the routine 00043 double m_dMarquardt; // Marquardt parameter 00044 int m_iNIterations; // Maximum number of LM iterations 00045 double m_dChiSqTol; // Fractional stopping criterion for Chi squared 00046 double m_dGradTol; // Stopping criterion for the norm of the gradient 00047 double** m_pdJacobian; // Jacobian matrix 00048 double** m_pdAlpha; // (1/2)*approximate Hessian matrix 00049 double* m_pdBeta; // (-1/2)*gradient 00050 double* m_pdScalingMatrix; // Diagonal scaling matrix 00051 double* m_pdCurrentResiduals; // Residuals at the current parameter values 00052 int m_iNResiduals; // number of residuals in NLLSMinimizable 00053 CParameterFilter *m_pFilter; // Filter if parameters need to be kept positive 00054 }; 00055 00056 #endif // !defined(AFX_ROBUSTLEVENBERGMARQUARDTMINIMIZER_H__699CF063_2C7A_408C_94EE_B02FB5D42FC3__INCLUDED_)