Fit Class Reference

Fit base class. More...

#include <Fit.h>

Inheritance diagram for Fit:
Filter ExponentialFit GaussAmpFit LinearFit LinearSlopeFit LogisticFit MultiPeakFit NonLinearFit PluginFit PolynomialFit SigmoidalFit ThreeExpFit TwoExpFit

List of all members.

Public Types

enum  Algorithm { ScaledLevenbergMarquardt, UnscaledLevenbergMarquardt, NelderMeadSimplex }
typedef int(* fit_function )(const gsl_vector *, void *, gsl_vector *)
typedef int(* fit_function_df )(const gsl_vector *, void *, gsl_matrix *)
typedef int(* fit_function_fdf )(const gsl_vector *, void *, gsl_vector *, gsl_matrix *)
typedef double(* fit_function_simplex )(const gsl_vector *, void *)
enum  FitType { BuiltIn = 0, Plugin = 1, User = 2 }
enum  WeightingMethod {
  NoWeighting, Instrumental, Statistical, Dataset,
  Direct
}

Public Member Functions

double adjustedRSquare ()
 Returns adjusted R^2.
double chiSquare ()
 Returns the sum of squares of the residuals from the best-fit line.
MatrixcovarianceMatrix (const QString &matrixName)
double * errors ()
 Returns a vector with the standard deviations of the results.
virtual double eval (double *, double)
 Calculates the data for the output fit curve.
QString fileName ()
virtual void fit ()
 Actually does the fit. Should be reimplemented in derived classes.
 Fit (ApplicationWindow *parent, Table *t, const QString &name=QString())
 Fit (ApplicationWindow *parent, Graph *g=0, const QString &name=QString())
 Fit (ApplicationWindow *parent, QwtPlotCurve *c)
QString formula ()
void generateFunction (bool yes, int points=100)
 Specifies weather the result of the fit is a function curve.
virtual void guessInitialValues ()
double initialGuess (int parIndex)
double lcl (int parIndex, double confidenceLevel)
 Lower Confidence Limit.
virtual QString legendInfo ()
 Output string added to the plot as a new legend.
bool load (const QString &fileName)
int numParameters ()
QStringList parameterNames ()
TableparametersTable (const QString &tableName)
double * residuals ()
 Returns a vector with the fit residuals.
QString resultFormula ()
double * results ()
 Returns a vector with the fit results.
double rmse ()
 Returns the Root Mean Squared Error.
double rSquare ()
 Returns R^2.
double rss ()
 Returns the Residual Sum of Squares.
virtual bool run ()
 Actually does the job. Should be reimplemented in derived classes.
bool save (const QString &fileName)
void scaleErrors (bool yes=true)
 Specifies wheather the errors must be scaled with sqrt(chi_2/dof).
void setAlgorithm (Algorithm s)
void setDataCurve (QwtPlotCurve *curve, double start, double end)
bool setDataFromTable (Table *t, const QString &xColName, const QString &yColName, int from=1, int to=-1)
void setFileName (const QString &fn)
virtual bool setFormula (const QString &, bool=true)
void setInitialGuess (int parIndex, double val)
void setInitialGuesses (double *x_init)
void setParameterExplanations (const QStringList &lst)
void setParameterRange (int parIndex, double left, double right)
virtual bool setParametersList (const QStringList &)
void setType (FitType t)
bool setWeightingData (WeightingMethod w, const QString &colName=QString::null)
 Sets the data set to be used for weighting.
void showConfidenceLimits (double confidenceLevel)
void showPredictionLimits (double confidenceLevel)
QwtPlotCurve * showResiduals ()
 Plot residuals and display data values in a column.
FitType type ()
double ucl (int parIndex, double confidenceLevel)
 Upper Confidence Limit.
void writeParametersToTable (Table *t, bool append=false)
 ~Fit ()

Protected Member Functions

virtual void calculateFitCurveData (double *X, double *Y)
 Calculates the data for the output fit curve and store itin the X an Y vectors.
virtual void freeMemory ()
 Frees all the arrays with size d_n. Used when changing the source data sets.
void freeWorkspace ()
 Frees the memory allocated for the fit workspace.
virtual void generateFitCurve ()
 Adds the result curve to the plot.
void initWorkspace (int par)
 Allocates the memory for the fit workspace.
virtual FunctionCurveinsertFitFunctionCurve (const QString &name, int penWidth=1, bool updateData=true)
 Adds the result curve as a FunctionCurve to the plot, if d_gen_function = true.
virtual QString logFitInfo (int iterations, int status)
 Output string added to the result log.

Protected Attributes

double chi_2
 The sum of squares of the residuals from the best-fit line.
gsl_matrix * covar
 Covariance matrix.
double d_adjusted_r_square
 Adjusted R^2.
Matrixd_cov_matrix
 Matrix window used for the output of covariance matrix.
fit_function_df d_df
double * d_errors
 Stores standard deviations of the result parameters.
fit_function d_f
fit_function_fdf d_fdf
QString d_file_name
 Path of the XML file where the user stores the fit model.
FitType d_fit_type
QString d_formula
 The fit formula given on input.
fit_function_simplex d_fsimplex
bool d_gen_function
 Specifies weather the result curve is a FunctionCurve or a normal curve with the same x values as the fit data.
int d_p
 Number of fit parameters.
QStringList d_param_explain
 Stores a list of short explanations for the significance of the fit parameters.
gsl_vector * d_param_init
 Initial guesses for the fit parameters.
QStringList d_param_names
 Names of the fit parameters.
double * d_param_range_left
 Stores the left limits of the research interval for the result parameters.
double * d_param_range_right
 Stores the right limits of the research interval for the result parameters.
Tabled_param_table
 Table window used for the output of fit parameters.
double * d_residuals
 Stores fit residuals.
QString d_result_formula
 The result fit formula, where the fit parameters are replaced with the calculated values.
double * d_results
 Stores the result parameters.
double d_rss
 Residual sum of squares.
bool d_scale_errors
 Specifies wheather the errors must be scaled with sqrt(chi_2/dof).
Algorithm d_solver
 Algorithm type.
double * d_w
 weighting data set used for the fit
WeightingMethod d_weighting
 The kind of weighting to be performed on the data.
bool is_non_linear
 Tells whether the fitter uses non-linear/simplex fitting with an initial parameters set, that must be freed in the destructor.
QString weighting_dataset
 The name of the weighting dataset.

Private Member Functions

virtual void customizeFitResults ()
 Customs and stores the fit results according to the derived class specifications. Used by exponential fits.
gsl_multifit_fdfsolver * fitGSL (gsl_multifit_function_fdf f, int &iterations, int &status)
 Pointer to the GSL multifit solver.
gsl_multimin_fminimizer * fitSimplex (gsl_multimin_function f, int &iterations, int &status)
 Pointer to the GSL multifit minimizer (for simplex algorithm).
void init ()
virtual void removeDataSingularities ()
 Removes any data singularities before fitting.

Detailed Description

Fit base class.


Member Typedef Documentation

typedef int(* Fit::fit_function)(const gsl_vector *, void *, gsl_vector *)
typedef int(* Fit::fit_function_df)(const gsl_vector *, void *, gsl_matrix *)
typedef int(* Fit::fit_function_fdf)(const gsl_vector *, void *, gsl_vector *, gsl_matrix *)
typedef double(* Fit::fit_function_simplex)(const gsl_vector *, void *)

Member Enumeration Documentation

Enumerator:
ScaledLevenbergMarquardt 
UnscaledLevenbergMarquardt 
NelderMeadSimplex 
Enumerator:
BuiltIn 
Plugin 
User 
Enumerator:
NoWeighting 
Instrumental 
Statistical 
Dataset 
Direct 

Constructor & Destructor Documentation

Fit::Fit ( ApplicationWindow parent,
QwtPlotCurve *  c 
)

References init().

Fit::Fit ( ApplicationWindow parent,
Graph g = 0,
const QString &  name = QString() 
)

References init().

Fit::Fit ( ApplicationWindow parent,
Table t,
const QString &  name = QString() 
)

References init().

Fit::~Fit (  ) 

References d_p, freeMemory(), and freeWorkspace().


Member Function Documentation

double Fit::adjustedRSquare (  )  [inline]

Returns adjusted R^2.

References d_adjusted_r_square.

virtual void Fit::calculateFitCurveData ( double *  X,
double *  Y 
) [inline, protected, virtual]

Calculates the data for the output fit curve and store itin the X an Y vectors.

Reimplemented in ExponentialFit, TwoExpFit, ThreeExpFit, LogisticFit, GaussAmpFit, NonLinearFit, PluginFit, PolynomialFit, LinearFit, LinearSlopeFit, and SigmoidalFit.

Referenced by generateFitCurve().

double Fit::chiSquare (  )  [inline]

Returns the sum of squares of the residuals from the best-fit line.

References chi_2.

Referenced by ApplicationWindow::fitLinear(), and ApplicationWindow::fitSlope().

Matrix * Fit::covarianceMatrix ( const QString &  matrixName  ) 
virtual void Fit::customizeFitResults (  )  [inline, private, virtual]

Customs and stores the fit results according to the derived class specifications. Used by exponential fits.

Reimplemented in ExponentialFit, and MultiPeakFit.

Referenced by generateFitCurve().

double * Fit::errors (  ) 

Returns a vector with the standard deviations of the results.

References chi_2, covar, d_errors, Filter::d_n, d_p, and d_scale_errors.

Referenced by FitDialog::accept().

virtual double Fit::eval ( double *  ,
double   
) [inline, virtual]
QString Fit::fileName (  )  [inline]
void Fit::fit (  )  [virtual]
gsl_multifit_fdfsolver * Fit::fitGSL ( gsl_multifit_function_fdf  f,
int &  iterations,
int &  status 
) [private]
gsl_multimin_fminimizer * Fit::fitSimplex ( gsl_multimin_function  f,
int &  iterations,
int &  status 
) [private]

Pointer to the GSL multifit minimizer (for simplex algorithm).

References Filter::d_max_iterations, d_p, d_param_init, d_param_range_left, d_param_range_right, d_results, and Filter::d_tolerance.

Referenced by fit().

QString Fit::formula (  )  [inline]
void Fit::freeMemory (  )  [protected, virtual]

Frees all the arrays with size d_n. Used when changing the source data sets.

Reimplemented from Filter.

References d_residuals, and d_w.

Referenced by ~Fit().

void Fit::freeWorkspace (  )  [protected]
void Fit::generateFitCurve (  )  [protected, virtual]
void Fit::generateFunction ( bool  yes,
int  points = 100 
)
virtual void Fit::guessInitialValues (  )  [inline, virtual]
void Fit::init (  )  [private]
double Fit::initialGuess ( int  parIndex  )  [inline]
void Fit::initWorkspace ( int  par  )  [protected]
FunctionCurve * Fit::insertFitFunctionCurve ( const QString &  name,
int  penWidth = 1,
bool  updateData = true 
) [protected, virtual]
double Fit::lcl ( int  parIndex,
double  confidenceLevel 
)

Lower Confidence Limit.

References covar, Filter::d_n, d_p, and d_results.

Referenced by showConfidenceLimits(), and showPredictionLimits().

QString Fit::legendInfo (  )  [virtual]

Output string added to the plot as a new legend.

Reimplemented from Filter.

Reimplemented in NonLinearFit, and PolynomialFit.

References chi_2, covar, Filter::d_curve, d_formula, Filter::d_n, d_p, d_param_names, Filter::d_prec, d_results, d_scale_errors, Filter::d_y_col_name, and rSquare().

bool Fit::load ( const QString &  fileName  ) 

Reimplemented in PluginFit.

References d_file_name.

Referenced by FitDialog::loadUserFunctions().

QString Fit::logFitInfo ( int  iterations,
int  status 
) [protected, virtual]
int Fit::numParameters (  )  [inline]
QStringList Fit::parameterNames (  )  [inline]
Table * Fit::parametersTable ( const QString &  tableName  ) 
virtual void Fit::removeDataSingularities (  )  [inline, private, virtual]

Removes any data singularities before fitting.

Reimplemented in NonLinearFit.

Referenced by fit().

double * Fit::residuals (  ) 

Returns a vector with the fit residuals.

References Filter::d_n, d_residuals, d_results, Filter::d_x, Filter::d_y, Filter::error(), and eval().

QString Fit::resultFormula (  )  [inline]

References d_result_formula.

double* Fit::results (  )  [inline]

Returns a vector with the fit results.

References d_results.

Referenced by FitDialog::accept(), ExpDecayDialog::fit(), ApplicationWindow::fitLinear(), and ApplicationWindow::fitSlope().

double Fit::rmse (  )  [inline]

Returns the Root Mean Squared Error.

References Filter::d_n, d_p, and d_rss.

double Fit::rSquare (  ) 
double Fit::rss (  )  [inline]

Returns the Residual Sum of Squares.

References d_rss.

virtual bool Fit::run (  )  [inline, virtual]

Actually does the job. Should be reimplemented in derived classes.

Reimplemented from Filter.

References fit().

bool Fit::save ( const QString &  fileName  ) 
void Fit::scaleErrors ( bool  yes = true  )  [inline]

Specifies wheather the errors must be scaled with sqrt(chi_2/dof).

References d_scale_errors.

Referenced by FitDialog::accept(), ApplicationWindow::analyzeCurve(), and ExpDecayDialog::fit().

void Fit::setAlgorithm ( Algorithm  s  )  [inline]

References d_solver.

Referenced by FitDialog::accept().

void Fit::setDataCurve ( QwtPlotCurve *  curve,
double  start,
double  end 
) [virtual]
bool Fit::setDataFromTable ( Table t,
const QString &  xColName,
const QString &  yColName,
int  from = 1,
int  to = -1 
) [virtual]
void Fit::setFileName ( const QString &  fn  )  [inline]
virtual bool Fit::setFormula ( const QString &  ,
bool  = true 
) [inline, virtual]
void Fit::setInitialGuess ( int  parIndex,
double  val 
) [inline]
void Fit::setInitialGuesses ( double *  x_init  ) 
void Fit::setParameterExplanations ( const QStringList &  lst  )  [inline]

References d_param_explain.

Referenced by FitModelHandler::endElement().

void Fit::setParameterRange ( int  parIndex,
double  left,
double  right 
)
virtual bool Fit::setParametersList ( const QStringList &   )  [inline, virtual]

Reimplemented in NonLinearFit.

Referenced by FitModelHandler::endElement().

void Fit::setType ( FitType  t  )  [inline]

References d_fit_type.

Referenced by FitModelHandler::endElement().

bool Fit::setWeightingData ( WeightingMethod  w,
const QString &  colName = QString::null 
)
void Fit::showConfidenceLimits ( double  confidenceLevel  ) 
void Fit::showPredictionLimits ( double  confidenceLevel  ) 
QwtPlotCurve * Fit::showResiduals (  ) 
FitType Fit::type (  )  [inline]
double Fit::ucl ( int  parIndex,
double  confidenceLevel 
)

Upper Confidence Limit.

References covar, Filter::d_n, d_p, and d_results.

Referenced by showConfidenceLimits(), and showPredictionLimits().

void Fit::writeParametersToTable ( Table t,
bool  append = false 
)

Member Data Documentation

double Fit::chi_2 [protected]

The sum of squares of the residuals from the best-fit line.

Referenced by chiSquare(), errors(), LinearSlopeFit::fit(), LinearFit::fit(), PolynomialFit::fit(), fit(), init(), legendInfo(), logFitInfo(), and writeParametersToTable().

gsl_matrix* Fit::covar [protected]
double Fit::d_adjusted_r_square [protected]

Adjusted R^2.

Referenced by adjustedRSquare(), init(), logFitInfo(), and rSquare().

Matrix* Fit::d_cov_matrix [protected]

Matrix window used for the output of covariance matrix.

Referenced by covarianceMatrix(), and init().

double* Fit::d_errors [protected]

Stores standard deviations of the result parameters.

Referenced by errors(), freeWorkspace(), and init().

fit_function Fit::d_f [protected]
QString Fit::d_file_name [protected]

Path of the XML file where the user stores the fit model.

Referenced by fileName(), load(), save(), and setFileName().

FitType Fit::d_fit_type [protected]
QString Fit::d_formula [protected]
bool Fit::d_gen_function [protected]
int Fit::d_p [protected]
QStringList Fit::d_param_explain [protected]
gsl_vector* Fit::d_param_init [protected]
QStringList Fit::d_param_names [protected]
double* Fit::d_param_range_left [protected]

Stores the left limits of the research interval for the result parameters.

Referenced by fitGSL(), fitSimplex(), freeWorkspace(), init(), initWorkspace(), and setParameterRange().

double* Fit::d_param_range_right [protected]

Stores the right limits of the research interval for the result parameters.

Referenced by fitGSL(), fitSimplex(), freeWorkspace(), init(), initWorkspace(), and setParameterRange().

Table* Fit::d_param_table [protected]

Table window used for the output of fit parameters.

Referenced by init(), and parametersTable().

double* Fit::d_residuals [protected]

Stores fit residuals.

Referenced by freeMemory(), init(), residuals(), rSquare(), and showResiduals().

QString Fit::d_result_formula [protected]

The result fit formula, where the fit parameters are replaced with the calculated values.

Referenced by init(), and resultFormula().

double* Fit::d_results [protected]
double Fit::d_rss [protected]

Residual sum of squares.

Referenced by init(), logFitInfo(), rmse(), rSquare(), rss(), showConfidenceLimits(), and showPredictionLimits().

bool Fit::d_scale_errors [protected]

Specifies wheather the errors must be scaled with sqrt(chi_2/dof).

Referenced by errors(), LinearSlopeFit::init(), LinearFit::init(), PolynomialFit::init(), init(), legendInfo(), logFitInfo(), scaleErrors(), and writeParametersToTable().

Algorithm Fit::d_solver [protected]

Algorithm type.

Referenced by fit(), fitGSL(), init(), logFitInfo(), and setAlgorithm().

double* Fit::d_w [protected]

The kind of weighting to be performed on the data.

Referenced by LinearSlopeFit::fit(), LinearFit::fit(), PolynomialFit::fit(), init(), logFitInfo(), setDataCurve(), and setWeightingData().

bool Fit::is_non_linear [protected]

Tells whether the fitter uses non-linear/simplex fitting with an initial parameters set, that must be freed in the destructor.

Referenced by LinearSlopeFit::init(), LinearFit::init(), PolynomialFit::init(), init(), and logFitInfo().

QString Fit::weighting_dataset [protected]

The name of the weighting dataset.

Referenced by init(), logFitInfo(), setDataCurve(), and setWeightingData().


The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.2