00001
00002
00004
00005 #if !defined(AFX_STOCHASTICSENSITIVITYANALYSIS_H__6F1FADC6_28C2_4963_AFA8_607527338B17__INCLUDED_)
00006 #define AFX_STOCHASTICSENSITIVITYANALYSIS_H__6F1FADC6_28C2_4963_AFA8_607527338B17__INCLUDED_
00007
00008 #if _MSC_VER > 1000
00009 #pragma once
00010 #endif // _MSC_VER > 1000
00011
00012 #ifdef _WIN32
00013 #include <mkl.h>
00014 #include <strstream>
00015 #else
00016 #include "lapack.h"
00017 #include <algorithm>
00018 using namespace std;
00019 #define __min min
00020 #define __max max
00021 #endif
00022
00023 #include <iostream>
00024 #include <fstream>
00025 #include <vector>
00026 #include <iomanip>
00027 #include <sstream>
00028 #include "SubjectObserver.h"
00029 #include "NLLSMinimizable.h"
00030 #include "Rand.h"
00031 #include "ParameterFilter.h"
00032 #include "EnsembleMember.h"
00033 using namespace std;
00034
00035 class CStochasticSensitivityAnalysis : public Subject
00036 {
00037 public:
00038 CStochasticSensitivityAnalysis();
00039 CStochasticSensitivityAnalysis(bool readFlag, bool hessianFlag, int nEnsembleSize, int seed, CParameterFilter *pFilter, double funcAccuracy, double temperature=1.0);
00040 virtual ~CStochasticSensitivityAnalysis();
00041
00042 void ComputeApproximateHessian(double *pParameters, NLLSMinimizable *pNLLS);
00043
00044 void ComputeTrueHessian(double *pParameters, NLLSMinimizable *pNLLS);
00045
00046 void ReadHessian();
00047 void DoAnalysis(double *pFittedParameters, Minimizable *pMinimizable);
00048 double SampleGaussian(double *pParDelta);
00049 double SampleWithoutExplicitHessian(double *pParDelta);
00050 void ConstructTrialMove(double *pParTrial, double *pParCurrent, double *pParDelta);
00051 void AddParametersToEnsemble(double *pParSave, double *resid, double quadratic, double cost);
00052 bool AcceptMove(double quadratic, double deltaCost);
00053 double GetRWValue() const {return m_dRWValue;}
00054 std::vector<CEnsembleMember *> *GetEnsemble() {return &m_vpEnsemble;}
00055 const double **GetEigenvectorMatrix() const {return (const double **)m_pdMatrixV;}
00056 double GetRescale() {return m_dRescale;}
00057 double *GetSingularValues() {return m_pdSingularValues;}
00058 private:
00059
00060 bool m_bSVDFlag;
00061
00062 bool m_bHessianFlag;
00063
00064 bool m_bReadFlag;
00065
00066 int m_iNResiduals;
00067
00068 int m_iNParameters;
00069
00070 int m_iNEnsembleSize;
00071 int m_iRNGSeed;
00072
00073 double m_dTemperature;
00074
00075 double m_dRescale;
00076
00077 double m_dAcceptanceRatio;
00078
00079 double m_dFuncAccuracy;
00080
00081 double m_dRWValue;
00082
00083 double m_dMNormSquared;
00084
00085 double *m_pdSingularValues;
00086
00087 double **m_pdMatrixV;
00088
00089 double **m_pdHessian;
00090
00091 double **m_pdSamplingMatrix;
00092
00093 double **m_pdJacobian;
00094 CParameterFilter *m_pFilter;
00095 Rand *m_pRNG;
00096 std::vector<CEnsembleMember *> m_vpEnsemble;
00097 };
00098
00099 #endif // !defined(AFX_STOCHASTICSENSITIVITYANALYSIS_H__6F1FADC6_28C2_4963_AFA8_607527338B17__INCLUDED_)