FittingFunctionGaussian Class Reference

#include <FittingFunctionGaussian.h>

Inherits FittingFunction.

Inheritance diagram for FittingFunctionGaussian:

Inheritance graph
[legend]
Collaboration diagram for FittingFunctionGaussian:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 FittingFunctionGaussian ()
 FittingFunctionGaussian (long lNbIteration, double dLimitSearch)
virtual ~FittingFunctionGaussian ()
virtual PtrFunction getFunction () const
virtual PtrFunctionDerivate getFunctionDerivate () const
virtual PtrFunctionAndDerivate getFunctionAndDerivate () const
virtual int doFit (long points, gsl_vector *x, gsl_vector *y, gsl_vector *sigma, gsl_vector *guess, bool bEstimateGuess, int iSearchStoppingMethod=1, bool bUseScaled=true)
virtual int generateFunctionFit (double dValMinX, double dResolutionX, long lNbPoints, gsl_vector *funcX, gsl_vector *funcY)
virtual int generateFunctionFit (long lNbPoints, gsl_vector *x, gsl_vector *funcX, gsl_vector *funcY)
void printState (size_t iter, gsl_multifit_fdfsolver *s)
void printResults ()
double computeValue (double dX, double dPosition, double dWidth, double dHeight, double dBackground=0.0)
double computeDerivateValue (double dX, double dPosition, double dWidth, double dHeight)
 TO BE FINISHED.
void initializeInitialsParameters (gsl_vector *vExperimentalDataX, gsl_vector *vExperimentalDataY, gsl_vector *vInitialGuess, bool bEstimate)
void estimateInitialGuess (gsl_vector *vExperimentalDataX, gsl_vector *vExperimentalDataY)
double estimateInitialPosition (gsl_vector *vExperimentalDataX, gsl_vector *vExperimentalDataY)
double estimateInitialSigma (gsl_vector *vExperimentalDataX, gsl_vector *vExperimentalDataY)
double estimateInitialHeight (gsl_vector *vExperimentalDataX, gsl_vector *vExperimentalDataY)
double estimateInitialBackground (gsl_vector *vExperimentalDataX, gsl_vector *vExperimentalDataY)
std::string getEquation () const

Static Public Member Functions

static int Function (const gsl_vector *peak_params, void *calc_data, gsl_vector *func)
 Implements the Gaussian function for the model :

\[ Y_i = height * \exp \left[ - \frac{1}{2} \left( \frac{x_i - pos}{width}\right)^2 \right] \]

The HWHM is equal to :

\[ HWHM = width\sqrt {2\ln(2)} \]

ModelId=43849A030029.

static int FunctionDerivate (const gsl_vector *peak_params, void *calc_data, gsl_matrix *Jacobian)
 Partial Derivates of Gaussian function according each of the variable parameters

\[ Y_i = height * \exp \left[ - \frac{1}{2} \left( \frac{x_i - pos}{width}\right)^2 \right] \]

\[ \frac{\partial Y_i}{\partial pos} = \frac{height}{width}* \frac{x_i - pos}{width} * \exp \left[ - \frac{1}{2} \left( \frac{x_i - pos}{width}\right)^2 \right] \]

\[ \frac{\partial Y_i}{\partial width} = \frac{height}{width} * \left( \frac{x_i - pos}{width}\right)^2 * \exp \left[ - \frac{1}{2} \left( \frac{x_i - pos}{width}\right)^2 \right] \]

\[ \frac{\partial Y_i}{\partial height} = \exp \left[ - \frac{1}{2} \left( \frac{x_i - pos}{width}\right)^2 \right] \]

The jacobian matrix is filled with the derivate of Yi with the parameters :

\[ \frac{\partial Y_i}{\partial pos} / \sigma_i \]

\[ \frac{\partial Y_i}{\partial width} / \sigma_i \]

\[ \frac{\partial Y_i}{\partial height} / \sigma_i \]

with $ \sigma_i $ the error on data number $ i $
ModelId=43849A03002E.

static int FunctionAndDerivate (const gsl_vector *peak_params, void *calc_data, gsl_vector *func, gsl_matrix *Jacobian)

Detailed Description

Definition at line 18 of file FittingFunctionGaussian.h.


Constructor & Destructor Documentation

FittingFunctionGaussian::FittingFunctionGaussian  ) 
 

Definition at line 22 of file FittingFunctionGaussian.cpp.

References FittingFunction::_dSearchLimit, FittingFunction::_iNbParameters, FittingFunction::_lNbMaxIteration, FittingFunction::_mFunctionMap, FittingFunction::_pParameters, FittingFunction::_pParametersErrors, FittingFunction::_vInitialGuess, NB_ITERATION_MAX, and SEARCH_LIMIT.

00023 {
00024         _iNbParameters                          =       3;
00025         _lNbMaxIteration                        =       NB_ITERATION_MAX;
00026         _dSearchLimit                           =       SEARCH_LIMIT;
00027         _pParameters                            =       new double[_iNbParameters];
00028         _pParametersErrors                      =       new double[_iNbParameters];
00029         _mFunctionMap["Position"]       =       0;
00030         _mFunctionMap["Width"]          =       1;
00031         _mFunctionMap["Height"]         =       2;
00032         _vInitialGuess = gsl_vector_alloc(3);
00033 }

FittingFunctionGaussian::FittingFunctionGaussian long  lNbIteration,
double  dLimitSearch
 

Definition at line 36 of file FittingFunctionGaussian.cpp.

References FittingFunction::_dSearchLimit, FittingFunction::_iNbParameters, FittingFunction::_lNbMaxIteration, FittingFunction::_mFunctionMap, FittingFunction::_pParameters, FittingFunction::_pParametersErrors, and FittingFunction::_vInitialGuess.

00037 {
00038         _iNbParameters                          =       3;
00039         _lNbMaxIteration                        =       lNbIteration;
00040         _dSearchLimit                           =       dLimitSearch;
00041         _pParameters                            =       new double[_iNbParameters];
00042         _pParametersErrors                      =       new double[_iNbParameters];
00043         _mFunctionMap["Position"]       =       0;
00044         _mFunctionMap["Width"]          =       1;
00045         _mFunctionMap["Height"]         =       2;
00046         _vInitialGuess = gsl_vector_alloc(3);
00047 }

FittingFunctionGaussian::~FittingFunctionGaussian  )  [virtual]
 

Definition at line 50 of file FittingFunctionGaussian.cpp.

References FittingFunction::_pParameters, FittingFunction::_pParametersErrors, and FittingFunction::_vInitialGuess.

00051 {
00052         printf ("Destruction FittingFunctionGaussian !!!\n");
00053         delete[] _pParameters;
00054         delete[] _pParametersErrors;
00055         _pParameters = NULL;
00056         _pParametersErrors = NULL;
00057         gsl_vector_free(_vInitialGuess);
00058 }


Member Function Documentation

double FittingFunctionGaussian::computeDerivateValue double  dX,
double  dPosition,
double  dWidth,
double  dHeight
[virtual]
 

TO BE FINISHED.

Implements FittingFunction.

Definition at line 430 of file FittingFunctionGaussian.cpp.

00431 {
00432         return 0.0;
00433 }

double FittingFunctionGaussian::computeValue double  dX,
double  dPosition,
double  dWidth,
double  dHeight,
double  dBackground = 0.0
[virtual]
 

Implements FittingFunction.

Definition at line 417 of file FittingFunctionGaussian.cpp.

00418 {
00419         double dXPos,dXPos2,dWidth2,dYi;
00420 
00421         dXPos   = dX - dPosition;
00422         dXPos2  = dXPos * dXPos;
00423         dWidth2 = dWidth * dWidth;
00424         
00425         dYi = dHeight * exp(-0.5 * dXPos2 / dWidth2);
00426         return dYi;
00427 }

int FittingFunctionGaussian::doFit long  points,
gsl_vector *  x,
gsl_vector *  y,
gsl_vector *  sigma,
gsl_vector *  guess,
bool  bEstimateGuess,
int  iSearchStoppingMethod = 1,
bool  bUseScaled = true
[virtual]
 

Implements FittingFunction.

Definition at line 169 of file FittingFunctionGaussian.cpp.

References FittingFunction::_dSearchLimit, FittingFunction::_iNbParameters, FittingFunction::_vInitialGuess, getFunction(), getFunctionAndDerivate(), getFunctionDerivate(), initializeInitialsParameters(), FittingData::n, printState(), FittingData::sigma, FittingData::x, and FittingData::y.

00170 {
00171 
00172         initializeInitialsParameters(x,y,guess,bEstimateGuess);
00173 
00174         long            i;
00175         long            iter;
00176         long            status;
00177         
00178         double* datax = new double[points];
00179         double* datay = new double[points];
00180         double* datas = new double[points];
00181                                                         
00182         // fill the data arrays 
00183         for (i=0; i<points; i++)
00184         {               
00185                 datax[i] = gsl_vector_get (x, i);               // x = index            
00186                 datay[i] = gsl_vector_get (y, i);               // y = data to be fit           
00187                 datas[i] = gsl_vector_get (sigma, i);   // s = sigma (weight) of data values 
00188         }
00189         
00190         //gsl data structure    
00191         struct FittingData gsl_data;
00192         gsl_data.n      = points;
00193         gsl_data.x      = datax;
00194         gsl_data.y              = datay;
00195         gsl_data.sigma  = datas;
00196 
00197         cout << "\n---------------------------------------------" << endl;
00198         cout << "Initials Parameters For The Fit" << endl;
00199         // set-up the solver 
00200         const gsl_multifit_fdfsolver_type *T;
00201         if (bUseScaled)
00202         {
00203                 T       = gsl_multifit_fdfsolver_lmsder;
00204                 cout << "Jacobian Data Scaled" << endl;
00205         }
00206         else
00207         {
00208                 T       = gsl_multifit_fdfsolver_lmder;
00209                 cout << "Jacobian Data Not Scaled" << endl;
00210         }
00211         gsl_multifit_fdfsolver *s                               = gsl_multifit_fdfsolver_alloc (T, points, _iNbParameters);
00212         gsl_multifit_function_fdf f;
00213 
00214         f.f             = getFunction();             
00215         f.df            = getFunctionDerivate();      
00216         f.fdf           = getFunctionAndDerivate();   
00217         f.n             = points;
00218         f.p             = _iNbParameters;
00219         f.params        = &gsl_data;
00220   
00221         switch(iSearchStoppingMethod)
00222         {
00223                 case 1 :
00224                         cout << "Test Delta Search Stopping Function Used" << endl;
00225                         break;
00226 
00227                 case 2 :
00228                         cout << "Test Gradient Search Stopping Function Used" << endl;
00229                         break;
00230         }
00231 
00232         cout << "\n----------------------------------------------" << endl;
00233         cout << "Initials Values For The Fit " << endl;
00234         cout << "Position = " << gsl_vector_get (_vInitialGuess, 0) << endl;
00235         cout << "Width    = "   << gsl_vector_get (_vInitialGuess, 1) << endl;
00236         cout << "Height   = "   << gsl_vector_get (_vInitialGuess, 2) << endl;
00237 
00238 
00239         gsl_multifit_fdfsolver_set ( s,  &f,  _vInitialGuess );
00240 
00241         cout << "\n---------------------------------------------" << endl;
00242         cout << "Iterations" << endl;
00243         iter = 0;
00244         #ifdef DEBUG_FIT
00245           printState (iter, s);
00246         #endif
00247 
00248         do
00249     {
00250                 iter++;
00251                 status = gsl_multifit_fdfsolver_iterate (s);
00252 
00253                 #ifdef DEBUG_FIT
00254                           printf ("status = %s\n", gsl_strerror (status));
00255                           printState (iter, s);
00256                 #endif
00257                 
00258                 if (status)
00259                 {
00260                 break;
00261                 }
00262 
00263 
00264                 switch(iSearchStoppingMethod)
00265                 {
00266                 case 1 :
00267                         status = gsl_multifit_test_delta (s->dx, s->x,  /*_dSearchLimit*/0.0, _dSearchLimit);
00268                         break;
00269 
00270                 case 2 :
00271                         gsl_vector* gradient = gsl_vector_alloc(_iNbParameters);
00272                         gsl_multifit_gradient(s->J,s->f,gradient);
00273                         status = gsl_multifit_test_gradient (gradient, _dSearchLimit);
00274                         gsl_vector_free(gradient);
00275                         break;
00276                 }
00277     }
00278         while (status == GSL_CONTINUE && iter < _lNbMaxIteration);
00279 
00280         _lNbIterations = iter;
00281 
00282         // Check whether the fitting has converged or failed  
00283         //if ( status == GSL_SUCCESS )
00284 
00285         gsl_matrix *covar               = gsl_matrix_alloc (_iNbParameters, _iNbParameters);
00286         gsl_multifit_covar (s->J, 0.0, covar);
00287         double chi                              = gsl_blas_dnrm2(s->f);
00288 
00289         _pParameters[0]                 =       FIT(0);
00290         _pParameters[1]                 =       FIT(1);
00291         _pParameters[2]                 =       FIT(2);
00292 
00293         _pParametersErrors[0]   =       ERR(0);
00294         _pParametersErrors[1]   =       ERR(1);
00295         _pParametersErrors[2]   =       ERR(2);
00296 
00297         /*double dHeight                        =       _pParameters[2];
00298         _dQualityFactor                 =       pow(chi, 2.0)/ (points - _iNbParameters);
00299         _dSigma                                 =       1.0/ (sqrt(2*M_PI)*dHeight);
00300         _dFHWM                                  =       2.355*_dSigma;*/
00301         
00302         double dEstimatedWidth  =       _pParameters[1];
00303         _dQualityFactor                 =       pow(chi, 2.0)/ (points - _iNbParameters);
00304 //      _dSigma                                 =       1.0/ (sqrt(2*M_PI)*dHeight);
00305 //      _dFHWM                                  =       2.355*_dSigma;
00306         _dHWHM                                  =       dEstimatedWidth * sqrt(2*log(2.0));
00307         _dFHWM                                  =       2*_dHWHM;               
00308         cout << "2*sqrt(2*log(2.0))=" << 2*sqrt(2*log(2.0)) <<endl;
00309 
00310         #ifdef DEBUG_FIT        
00311                         cout << "\n---------------------------------------------" << endl;
00312                         cout << "Results For Gaussian" << endl;
00313                         printResults();
00314         #endif  
00315                 
00316         gsl_matrix_free(covar);         
00317         //              }
00318 
00319         #ifdef DEBUG_FIT  
00320                 printf ("status = %s\n", gsl_strerror (status));
00321         #endif
00322         
00323         // Free data
00324         gsl_multifit_fdfsolver_free (s);
00325 
00326         delete[] datax;
00327         delete[] datay;
00328         delete[] datas;
00329         
00330         datax = NULL;
00331         datax = NULL;
00332         datax = NULL;
00333 
00334         return status;
00335 }

Here is the call graph for this function:

double FittingFunctionGaussian::estimateInitialBackground gsl_vector *  vExperimentalDataX,
gsl_vector *  vExperimentalDataY
 

Definition at line 498 of file FittingFunctionGaussian.cpp.

Referenced by estimateInitialHeight(), and estimateInitialSigma().

00499 {
00500         double dBackground = 0.0;
00501         return dBackground;
00502 }

void FittingFunctionGaussian::estimateInitialGuess gsl_vector *  vExperimentalDataX,
gsl_vector *  vExperimentalDataY
[virtual]
 

Implements FittingFunction.

Definition at line 437 of file FittingFunctionGaussian.cpp.

References FittingFunction::_vInitialGuess, estimateInitialHeight(), estimateInitialPosition(), and estimateInitialSigma().

Referenced by initializeInitialsParameters().

00438 {
00439         // fill the initials parameters values estimation vector for the initialisation
00440         // [0] = position 
00441         // [1] = width  
00442         // [2] = height
00443         // Thanks to the max index of all the points, we can get the
00444         // position_value = x_value at index_max
00445         // width                  = standard deviation
00446         // height_value   = y_value     at index_max
00447         //max_index = gsl_vector_max_index (vExperimentalDataY);
00448 
00449         double dInitialPosition         = estimateInitialPosition(vExperimentalDataX,vExperimentalDataY);
00450         double dInitialSigma            = estimateInitialSigma(vExperimentalDataX,vExperimentalDataY);
00451         double dInitialHeight           = estimateInitialHeight(vExperimentalDataX,vExperimentalDataY);
00452 
00453         gsl_vector_set(_vInitialGuess, 0, dInitialPosition);
00454         gsl_vector_set(_vInitialGuess, 1, dInitialSigma);
00455         gsl_vector_set(_vInitialGuess, 2, dInitialHeight);
00456 }

Here is the call graph for this function:

double FittingFunctionGaussian::estimateInitialHeight gsl_vector *  vExperimentalDataX,
gsl_vector *  vExperimentalDataY
 

Definition at line 487 of file FittingFunctionGaussian.cpp.

References estimateInitialBackground().

Referenced by estimateInitialGuess(), and estimateInitialSigma().

00488 {
00489         size_t max_index        = gsl_vector_max_index (vExperimentalDataY);
00490 
00491         double background       = estimateInitialBackground(vExperimentalDataX,vExperimentalDataY);
00492         double maxValue         = gsl_vector_get(vExperimentalDataY, max_index);
00493         double height           = maxValue - background;
00494         return height;
00495 }

Here is the call graph for this function:

double FittingFunctionGaussian::estimateInitialPosition gsl_vector *  vExperimentalDataX,
gsl_vector *  vExperimentalDataY
 

Definition at line 476 of file FittingFunctionGaussian.cpp.

Referenced by estimateInitialGuess().

00477 {
00478         size_t max_index        = gsl_vector_max_index (vExperimentalDataY);
00479         double dPosition        = gsl_vector_get(vExperimentalDataX,max_index);
00480 
00481         return dPosition;
00482 }

double FittingFunctionGaussian::estimateInitialSigma gsl_vector *  vExperimentalDataX,
gsl_vector *  vExperimentalDataY
 

Definition at line 505 of file FittingFunctionGaussian.cpp.

References estimateInitialBackground(), and estimateInitialHeight().

Referenced by estimateInitialGuess().

00506 {
00507         double dSigma;
00508         double dCovariance;
00509         double dHeight                          = estimateInitialHeight(vExperimentalDataX,vExperimentalDataY);
00510         double dBackground                      = estimateInitialBackground(vExperimentalDataX,vExperimentalDataY);
00511         
00512         size_t iIndexMax                        = gsl_vector_max_index(vExperimentalDataY);
00513         double dYMaxValue                       = gsl_vector_get(vExperimentalDataY, iIndexMax);
00514   
00515         double  dYCurrentValue          = dYMaxValue;
00516 
00517         size_t iCurrentIndex            = iIndexMax;
00518         size_t lVectorSize                      = vExperimentalDataX->size;//lSizeX;
00519         double lHalfVectorSize          = 0.5 * lVectorSize;
00520         double dHalfMaximum                     = 0.5 * dHeight + dBackground;
00521   
00522         size_t iIndexLow                        = iCurrentIndex;
00523         size_t iIndexHigh                       = iCurrentIndex;
00524 
00525     if (iIndexMax < lHalfVectorSize)
00526     {
00527 //              cout << "\n\t--> Look in increasing direction" << endl;
00528                 //- look in increasing direction
00529                 while(iCurrentIndex < lVectorSize - 1 && dYCurrentValue > dHalfMaximum)
00530                 {
00531                         dYCurrentValue  = gsl_vector_get(vExperimentalDataY, ++iCurrentIndex);
00532                         iIndexHigh              = iCurrentIndex;
00533                         iIndexLow               = iIndexMax - (iIndexHigh - iIndexMax);
00534                 }
00535     }
00536     else
00537     {
00538 //              cout << "\n\t--> Look in decreasing direction" << endl;
00539                 //- look in decreasing direction
00540                 while( iCurrentIndex > 0 && dYCurrentValue > dHalfMaximum)
00541                 {
00542                         dYCurrentValue =  gsl_vector_get(vExperimentalDataY, --iCurrentIndex);
00543                         iIndexLow               = iCurrentIndex;
00544                         iIndexHigh              = iIndexMax + (iIndexMax - iIndexLow);
00545                 }
00546     }
00547 
00548     if (iCurrentIndex != iIndexMax)
00549     {
00550                 double dPosition        = gsl_vector_get(vExperimentalDataX, iIndexMax);
00551                 double dX2                      = gsl_vector_get(vExperimentalDataX, iCurrentIndex);
00552                 dSigma = ::fabs(dX2 - dPosition);
00553     }
00554     else
00555     {
00556                 //- try an arbitrary value that should be not so far from reality
00557                 dSigma = lVectorSize / 6;
00558     }
00559 /*      cout << "-------------------------------" << endl;
00560         cout << "Peak : (x,y) --> ("    << gsl_vector_get(vExperimentalDataX, iIndexMax) << "," 
00561                                                                         << gsl_vector_get(vExperimentalDataY, iIndexMax) << ")" << endl;
00562                 
00563         
00564         cout << "Low : index=" << iIndexLow << endl;
00565         cout << "\txlow=" << gsl_vector_get(vExperimentalDataX, iIndexLow) << " | ylow=" << gsl_vector_get(vExperimentalDataY, iIndexLow) << endl;
00566         cout << "\txhigh=" << gsl_vector_get(vExperimentalDataX, iIndexHigh) << " | yhigh=" << gsl_vector_get(vExperimentalDataY, iIndexHigh) << endl;
00567         
00568         cout << "\txhigh - xlow= " << gsl_vector_get(vExperimentalDataX, iIndexHigh) - gsl_vector_get(vExperimentalDataX, iIndexLow) << endl;
00569         cout << "\tsigma=" << dSigma << endl;
00570 */
00571     dCovariance = dSigma * dSigma;
00572         return dSigma;
00573 }

Here is the call graph for this function:

int FittingFunctionGaussian::Function const gsl_vector *  peak_params,
void *  calc_data,
gsl_vector *  func
[static]
 

Implements the Gaussian function for the model :

\[ Y_i = height * \exp \left[ - \frac{1}{2} \left( \frac{x_i - pos}{width}\right)^2 \right] \]

The HWHM is equal to :

\[ HWHM = width\sqrt {2\ln(2)} \]

ModelId=43849A030029.

Definition at line 81 of file FittingFunctionGaussian.cpp.

References FittingData::sigma, FittingData::x, and FittingData::y.

Referenced by FunctionAndDerivate(), and getFunction().

00082 {
00083         size_t i;
00084         size_t iNbPoints        = ((struct FittingData *)calc_data)->n;
00085         double *x                       = ((struct FittingData *)calc_data)->x;
00086         double *y                       = ((struct FittingData *)calc_data)->y;
00087         double *sigma           = ((struct FittingData *)calc_data)->sigma;
00088 
00089         double pos                      = gsl_vector_get (peak_params, 0);
00090         double width            = gsl_vector_get (peak_params, 1);
00091         double height           = gsl_vector_get (peak_params, 2);
00092 
00093 //#ifdef DEBUG_FIT      
00094 //      printf("pos = %g, width = %g, height = %g\n", pos, width, height);
00095 //#endif        
00096 
00097         double dXPos,dXPos2,dWidth2,dYi;
00098 
00099         for (i=0; i < iNbPoints; i++)
00100     {           
00101                 dXPos   = x[i] - pos;
00102                 dXPos2  = dXPos * dXPos;
00103                 dWidth2 = width * width;
00104 
00105                 dYi             = height * exp(-0.5 * dXPos2 / dWidth2);
00106 
00107                 gsl_vector_set (func, i,( dYi - y[i]) / sigma[i]);              
00108     }
00109         return GSL_SUCCESS;
00110 }

int FittingFunctionGaussian::FunctionAndDerivate const gsl_vector *  peak_params,
void *  calc_data,
gsl_vector *  func,
gsl_matrix *  Jacobian
[static]
 

Definition at line 160 of file FittingFunctionGaussian.cpp.

References Function(), and FunctionDerivate().

Referenced by getFunctionAndDerivate().

00161 {       
00162         Function                (peak_params, calc_data, func);
00163         FunctionDerivate(peak_params, calc_data, Jacobian);
00164         return GSL_SUCCESS;
00165 }

Here is the call graph for this function:

int FittingFunctionGaussian::FunctionDerivate const gsl_vector *  peak_params,
void *  calc_data,
gsl_matrix *  Jacobian
[static]
 

Partial Derivates of Gaussian function according each of the variable parameters

\[ Y_i = height * \exp \left[ - \frac{1}{2} \left( \frac{x_i - pos}{width}\right)^2 \right] \]

\[ \frac{\partial Y_i}{\partial pos} = \frac{height}{width}* \frac{x_i - pos}{width} * \exp \left[ - \frac{1}{2} \left( \frac{x_i - pos}{width}\right)^2 \right] \]

\[ \frac{\partial Y_i}{\partial width} = \frac{height}{width} * \left( \frac{x_i - pos}{width}\right)^2 * \exp \left[ - \frac{1}{2} \left( \frac{x_i - pos}{width}\right)^2 \right] \]

\[ \frac{\partial Y_i}{\partial height} = \exp \left[ - \frac{1}{2} \left( \frac{x_i - pos}{width}\right)^2 \right] \]

The jacobian matrix is filled with the derivate of Yi with the parameters :

\[ \frac{\partial Y_i}{\partial pos} / \sigma_i \]

\[ \frac{\partial Y_i}{\partial width} / \sigma_i \]

\[ \frac{\partial Y_i}{\partial height} / \sigma_i \]

with $ \sigma_i $ the error on data number $ i $
ModelId=43849A03002E.

Definition at line 123 of file FittingFunctionGaussian.cpp.

References FittingData::n, FittingData::sigma, and FittingData::x.

Referenced by FunctionAndDerivate(), and getFunctionDerivate().

00124 {
00125         size_t i;
00126         
00127         size_t  n               = ((struct FittingData *)calc_data)->n;
00128         double *x               = ((struct FittingData *)calc_data)->x;
00129         double *sigma   = ((struct FittingData *)calc_data)->sigma;
00130 
00131         double pos              = gsl_vector_get (peak_params, 0);
00132         double width    = gsl_vector_get (peak_params, 1);
00133         double height   = gsl_vector_get (peak_params, 2);
00134   
00135         double d_pos, d_width, d_height;
00136         
00137         double s, xpos2, width2,e;
00138         // Fill the Jacobian Matrix
00139         for (i=0; i< n; i++)
00140     {
00141                 s                       = sigma[i];
00142                 xpos2           = (x[i]-pos)*(x[i]-pos);
00143                 width2          = width * width;
00144                 e                       = exp( -0.5 * xpos2 / width2);
00145                 
00146                 d_pos           = (height/width2 * (x[i] - pos) * e) / s;       // derivate dYi/dpos     
00147                 d_width         = (height/width2/width * xpos2 * e) / s;        // derivate dYi/dwidth  
00148                 d_height        = e/s;                                                                          // derivate dYi/dheight 
00149                 
00150                 // fill the jacobian matrix J(points, parameters) 
00151         gsl_matrix_set (Jacobian, i, 0, d_pos); 
00152                 gsl_matrix_set (Jacobian, i, 1, d_width);
00153                 gsl_matrix_set (Jacobian, i, 2, d_height);
00154     } 
00155         return GSL_SUCCESS;
00156 }

int FittingFunctionGaussian::generateFunctionFit long  lNbPoints,
gsl_vector *  x,
gsl_vector *  funcX,
gsl_vector *  funcY
[virtual]
 

Implements FittingFunction.

Definition at line 366 of file FittingFunctionGaussian.cpp.

References FittingFunction::_pParameters.

00367 {
00368         int i;
00369         double dPos             =       _pParameters[0];
00370         double dWidth   =       _pParameters[1];
00371         double dHeight  =       _pParameters[2];
00372         double dXi              =       0;
00373         double dXPos    =       0;
00374         double dXPos2   =       0;
00375         double dWidth2  =       1;
00376         double dYi              =       0;
00377 
00378         for (i=0;i<lNbPoints;i++) 
00379         {
00380                 dXi             = gsl_vector_get(x,i);
00381                 
00382                 dXPos   = dXi - dPos;
00383                 dXPos2  = dXPos * dXPos;
00384                 dWidth2 = dWidth * dWidth;
00385                 dYi             = dHeight * exp(-0.5 * dXPos2 / dWidth2);
00386         
00387                 gsl_vector_set(funcX,i,dXi);
00388                 gsl_vector_set(funcY,i,dYi);
00389         }
00390         return 1;
00391 }

int FittingFunctionGaussian::generateFunctionFit double  dValMinX,
double  dResolutionX,
long  lNbPoints,
gsl_vector *  funcX,
gsl_vector *  funcY
[virtual]
 

Implements FittingFunction.

Definition at line 339 of file FittingFunctionGaussian.cpp.

References FittingFunction::_pParameters.

00340 {
00341 
00342         int i;
00343         double dPos             =       _pParameters[0];
00344         double dWidth   =       _pParameters[1];
00345         double dHeight  =       _pParameters[2];
00346         double dXi              =       0;
00347         double dXPos    =       0;
00348         double dXPos2   =       0;
00349         double dWidth2  =       1;
00350         double dYi              =       0;
00351 
00352         for (i=0;i<lNbPoints;i++) 
00353         {
00354                 dXi             = dValMinX+i*dResolutionX;
00355                 dXPos   = dXi - dPos;
00356                 dXPos2  = dXPos * dXPos;
00357                 dWidth2 = dWidth * dWidth;
00358                 dYi             = dHeight * exp(-0.5 * dXPos2 / dWidth2);
00359         
00360                 gsl_vector_set(funcX,i,dXi);
00361                 gsl_vector_set(funcY,i,dYi);
00362         }
00363         return 1;
00364 }

std::string FittingFunctionGaussian::getEquation  )  const [virtual]
 

Implements FittingFunction.

Definition at line 14 of file FittingFunctionGaussian.cpp.

00015 {
00016         return "f(x) = Height * exp[ - (x - Position)˛ / (2 * Width˛)]";
00017 }

PtrFunction FittingFunctionGaussian::getFunction  )  const [virtual]
 

Implements FittingFunction.

Definition at line 61 of file FittingFunctionGaussian.cpp.

References Function().

Referenced by doFit().

00061                                                       {
00062         return FittingFunctionGaussian::Function;
00063 }

Here is the call graph for this function:

PtrFunctionAndDerivate FittingFunctionGaussian::getFunctionAndDerivate  )  const [virtual]
 

Implements FittingFunction.

Definition at line 71 of file FittingFunctionGaussian.cpp.

References FunctionAndDerivate().

Referenced by doFit().

00071                                                                              {
00072         return FittingFunctionGaussian::FunctionAndDerivate;
00073 }

Here is the call graph for this function:

PtrFunctionDerivate FittingFunctionGaussian::getFunctionDerivate  )  const [virtual]
 

Implements FittingFunction.

Definition at line 66 of file FittingFunctionGaussian.cpp.

References FunctionDerivate().

Referenced by doFit().

00066                                                                       {
00067         return FittingFunctionGaussian::FunctionDerivate;
00068 }

Here is the call graph for this function:

void FittingFunctionGaussian::initializeInitialsParameters gsl_vector *  vExperimentalDataX,
gsl_vector *  vExperimentalDataY,
gsl_vector *  vInitialGuess,
bool  bEstimate
[virtual]
 

Implements FittingFunction.

Definition at line 460 of file FittingFunctionGaussian.cpp.

References FittingFunction::_vInitialGuess, and estimateInitialGuess().

Referenced by doFit().

00461 {
00462 
00463         if      (bEstimate)
00464         {
00465                 estimateInitialGuess(vExperimentalDataX,vExperimentalDataY);
00466         }
00467         else
00468         {       //use the vInitialGuess gsl_vector of this function parameters
00469                 gsl_vector_set(_vInitialGuess,0,gsl_vector_get(vInitialGuess,0));
00470                 gsl_vector_set(_vInitialGuess,1,gsl_vector_get(vInitialGuess,1));
00471                 gsl_vector_set(_vInitialGuess,2,gsl_vector_get(vInitialGuess,2));
00472         }
00473 }

Here is the call graph for this function:

void FittingFunctionGaussian::printResults  ) 
 

Definition at line 406 of file FittingFunctionGaussian.cpp.

References FittingFunction::_dFHWM, FittingFunction::_dHWHM, FittingFunction::_dQualityFactor, FittingFunction::_dSigma, FittingFunction::_pParametersErrors, and FittingFunction::getParameter().

00407 {
00408                 printf ("pos            = %g \t+/- %g\n",       getParameter("Position"),       _pParametersErrors[0]);
00409                 printf ("width          = %g \t+/- %g\n",       getParameter("Width")   ,       _pParametersErrors[1]);
00410                 printf ("height         = %g \t+/- %g\n",       getParameter("Height")  ,       _pParametersErrors[2]);
00411         printf ("chisq/dof      = %g\n",                                _dQualityFactor);
00412                 printf ("Sigma          = %g\n",                                _dSigma);
00413                 printf ("HWHM           = %g\n",                                _dHWHM);
00414                 printf ("FHWM           = %g\n",                                _dFHWM);
00415 }

Here is the call graph for this function:

void FittingFunctionGaussian::printState size_t  iter,
gsl_multifit_fdfsolver *  s
 

Definition at line 395 of file FittingFunctionGaussian.cpp.

Referenced by doFit().

00396 {
00397   printf ("iter: %3u x : %g %g %g |f(x)|=%g\n",
00398           iter,
00399           gsl_vector_get (s->x, 0), 
00400           gsl_vector_get (s->x, 1),
00401           gsl_vector_get (s->x, 2), 
00402           gsl_blas_dnrm2 (s->f));
00403 }


The documentation for this class was generated from the following files:
Generated on Tue Apr 14 09:34:49 2009 for Data Fitting Library by  doxygen 1.4.5