SciDAVis  1.D4
Public Types | Public Member Functions | Static Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | Private Member Functions
Fit Class Reference

Fit base class. More...

#include <Fit.h>

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

List of all members.

Public Types

enum  Algorithm { ScaledLevenbergMarquardt, UnscaledLevenbergMarquardt, NelderMeadSimplex }
enum  ErrorSource { UnknownErrors, AssociatedErrors, PoissonErrors, CustomErrors }
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 *)

Public Member Functions

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.
double evaluate_d (const gsl_vector *x)
int evaluate_df (const gsl_vector *x, gsl_matrix *J)
int evaluate_f (const gsl_vector *x, gsl_vector *f)
 Fit (ApplicationWindow *parent, Graph *g=0, const char *name=0)
virtual void fit ()
 Actually does the fit. Should be reimplemented in derived classes.
QString formula ()
void generateFunction (bool yes, int points=100)
 Specifies weather the result of the fit is a function curve.
virtual void guessInitialValues ()
virtual QString legendInfo ()
 Output string added to the plot as a new legend.
int numParameters ()
TableparametersTable (const QString &tableName)
double * results ()
 Returns a vector with the fit results.
double rSquare ()
 Returns the coefficient of determination, R^2.
void scaleErrors (bool yes=true)
 Specifies wheather the errors must be scaled with sqrt(chi_2/dof)
void setAlgorithm (Algorithm s)
void setDataCurve (int curve, double start, double end)
void setInitialGuess (int parIndex, double val)
void setInitialGuesses (double *x_init)
bool setYErrorSource (ErrorSource err, const QString &colName=QString::null, bool fail_silently=false)
 Sets the data set to be used as source of Y errors.
 ~Fit ()
- Public Member Functions inherited from Filter
int dataSize ()
 Returns the size of the fitted data set.
bool error ()
 Filter (ApplicationWindow *parent, Table *t=0, const char *name=0)
 Filter (ApplicationWindow *parent, Graph *g=0, const char *name=0)
virtual bool run ()
 Actually does the job. Should be reimplemented in derived classes.
void setColor (int colorId)
 Sets the color of the output fit curve.
void setColor (const QString &colorName)
 Sets the color of the output fit curve. Provided for convenience. To be used in scripts only!
bool setDataFromCurve (const QString &curveTitle, Graph *g=0)
bool setDataFromCurve (const QString &curveTitle, double from, double to, Graph *g=0)
void setInterval (double from, double to)
 Changes the data range if the source curve was already assigned. Provided for convenience.
void setMaximumIterations (int iter)
 Sets the maximum number of iterations to be performed during an iterative session.
void setOutputPoints (int points)
 Sets the number of points in the output curve.
void setOutputPrecision (int digits)
 Sets the precision used for the output.
void setTolerance (double eps)
 Sets the tolerance used by the GSL routines.
virtual void showLegend ()
 Adds a new legend to the plot. Calls virtual legendInfo()
 ~Filter ()
- Public Member Functions inherited from scripted
 scripted (ScriptingEnv *env)
void scriptingChangeEvent (ScriptingChangeEvent *)
 ~scripted ()

Static Public Member Functions

static double evaluate_df_helper (double x, void *param)

Protected Slots

void scriptError (const QString &message, const QString &script_name, int line_number)

Protected Member Functions

virtual void calculateFitCurveData (double *par, double *X, double *Y)
 Calculates the data for the output fit curve and store itin the X an Y vectors.
virtual void generateFitCurve (double *par)
 Adds the result curve to the plot.
void insertFitFunctionCurve (const QString &name, double *x, double *y, int penWidth=1)
 Adds the result curve as a FunctionCurve to the plot, if d_gen_function = true.
virtual QString logFitInfo (double *par, int iterations, int status, const QString &plotName)
 Output string added to the result log.
- Protected Member Functions inherited from Filter
QwtPlotCurve * addResultCurve (double *x, double *y)
 Adds the result curve to the target output plot window. Creates a hidden table and frees the input data from memory.
virtual void calculateOutputData (double *X, double *Y)
 Calculates the data for the output curve and store it in the X an Y vectors.
int curveIndex (const QString &curveTitle, Graph *g)
 Performs checks and returns the index of the source data curve if OK, -1 otherwise.
virtual bool isDataAcceptable ()
virtual QString logInfo ()
 Output string added to the log pannel of the application.
virtual void output ()
 Performs the data analysis and takes care of the output.

Protected Attributes

double chi_2
 The sum of squares of the residuals from the best-fit line.
gsl_matrix * covar
 Covariance matrix.
fit_function_df d_df
fit_function d_f
fit_function_fdf d_fdf
QString d_formula
 The fit formula.
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_result_errors
 Stores standard deviations of the result parameters.
double * d_results
 Stores the result parameters.
bool d_scale_errors
 Specifies wheather the errors must be scaled with sqrt(chi_2/dof)
Scriptd_script
 Script used to evaluate user-defined functions.
Algorithm d_solver
 Algorithm type.
QString d_y_error_dataset
 The name of the dataset containing Y standard errors (if applicable).
ErrorSource d_y_error_source
 Where standard errors of the input data are taken from.
double * d_y_errors
 Standard deviations of Y input 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.
- Protected Attributes inherited from Filter
QwtPlotCurve * d_curve
 The curve to be analysed.
int d_curveColorIndex
 Color index of the result curve.
QString d_explanation
 String explaining the operation in the comment of the result table and in the project explorer.
double d_from
 Data interval.
Graphd_graph
 The graph where the result curve should be displayed.
bool d_init_err
 Error flag telling if something went wrong during the initialization phase.
int d_max_iterations
 Maximum number of iterations per fit.
int d_min_points
 Minimum number of data points necessary to perform the operation.
int d_n
 Size of the data arrays.
int d_points
 Number of result points to de calculated and displayed in the output curve.
int d_prec
 Precision (number of significant digits) used for the results output.
bool d_sort_data
 Specifies if the filter needs sorted data as input.
Tabled_table
 A table source of data.
double d_to
double d_tolerance
 GSL Tolerance, if ever needed...
double * d_x
 x data set to be analysed
double * d_y
 y data set to be analysed
- Protected Attributes inherited from scripted
ScriptingEnvscriptEnv

Private Member Functions

double * fitGslMultifit (int &iterations, int &status)
 Execute the fit using GSL non-linear least-squares fitting (Levenberg-Marquardt).
double * fitGslMultimin (int &iterations, int &status)
 Execute the fit using GSL multidimensional minimization (Nelder-Mead Simplex).
virtual void storeCustomFitResults (double *par)
 Customs and stores the fit results according to the derived class specifications. Used by exponential fits.

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:
UnknownErrors 
AssociatedErrors 
PoissonErrors 
CustomErrors 

Constructor & Destructor Documentation

Fit::Fit ( ApplicationWindow parent,
Graph g = 0,
const char *  name = 0 
)
Fit::~Fit ( )

Member Function Documentation

virtual void Fit::calculateFitCurveData ( double *  par,
double *  X,
double *  Y 
)
inlineprotectedvirtual

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

Reimplemented in GaussAmpFit, ThreeExpFit, LinearFit, TwoExpFit, PolynomialFit, PluginFit, ExponentialFit, NonLinearFit, 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.

Matrix * Fit::covarianceMatrix ( const QString &  matrixName)
double * Fit::errors ( )

Returns a vector with the standard deviations of the results.

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

double Fit::evaluate_d ( const gsl_vector *  x)
int Fit::evaluate_df ( const gsl_vector *  x,
gsl_matrix *  J 
)
double Fit::evaluate_df_helper ( double  x,
void *  param 
)
static
int Fit::evaluate_f ( const gsl_vector *  x,
gsl_vector *  f 
)
void Fit::fit ( )
virtual
double * Fit::fitGslMultifit ( int &  iterations,
int &  status 
)
private

Execute the fit using GSL non-linear least-squares fitting (Levenberg-Marquardt).

References chi_2, covar, d_df, d_f, d_fdf, Filter::d_max_iterations, Filter::d_n, d_p, d_param_init, d_solver, Filter::d_tolerance, Filter::d_x, Filter::d_y, d_y_error_source, d_y_errors, ScaledLevenbergMarquardt, UnknownErrors, and UnscaledLevenbergMarquardt.

Referenced by fit().

double * Fit::fitGslMultimin ( int &  iterations,
int &  status 
)
private

Execute the fit using GSL multidimensional minimization (Nelder-Mead Simplex).

References chi_2, covar, d_df, d_fsimplex, Filter::d_max_iterations, Filter::d_n, d_p, d_param_init, Filter::d_tolerance, Filter::d_x, Filter::d_y, d_y_error_source, d_y_errors, and UnknownErrors.

Referenced by fit().

QString Fit::formula ( )
inline
void Fit::generateFitCurve ( double *  par)
protectedvirtual
void Fit::generateFunction ( bool  yes,
int  points = 100 
)

Specifies weather the result of the fit is a function curve.

References d_gen_function, and Filter::d_points.

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

virtual void Fit::guessInitialValues ( )
inlinevirtual

Reimplemented in MultiPeakFit, and SigmoidalFit.

Referenced by ApplicationWindow::analyzeCurve().

void Fit::insertFitFunctionCurve ( const QString &  name,
double *  x,
double *  y,
int  penWidth = 1 
)
protected
QString Fit::legendInfo ( )
virtual

Output string added to the plot as a new legend.

Reimplemented from Filter.

Reimplemented in 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, and rSquare().

QString Fit::logFitInfo ( double *  par,
int  iterations,
int  status,
const QString &  plotName 
)
protectedvirtual
int Fit::numParameters ( )
inline

References d_p.

Table * Fit::parametersTable ( const QString &  tableName)
double* Fit::results ( )
inline

Returns a vector with the fit results.

References d_results.

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

double Fit::rSquare ( )

Returns the coefficient of determination, R^2.

References chi_2, Filter::d_n, Filter::d_y, d_y_error_source, d_y_errors, and UnknownErrors.

Referenced by legendInfo(), and logFitInfo().

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(), PolynomFitDialog::fit(), and ExpDecayDialog::fit().

void Fit::scriptError ( const QString &  message,
const QString &  script_name,
int  line_number 
)
protectedslot

Referenced by fit().

void Fit::setAlgorithm ( Algorithm  s)
inline

References d_solver.

Referenced by FitDialog::accept().

void Fit::setDataCurve ( int  curve,
double  start,
double  end 
)
virtual
void Fit::setInitialGuess ( int  parIndex,
double  val 
)
inline

References d_param_init.

Referenced by MultiPeakFitTool::selectPeak().

void Fit::setInitialGuesses ( double *  x_init)
bool Fit::setYErrorSource ( ErrorSource  err,
const QString &  colName = QString::null,
bool  fail_silently = false 
)
void Fit::storeCustomFitResults ( double *  par)
privatevirtual

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

Reimplemented in ThreeExpFit, TwoExpFit, MultiPeakFit, and ExponentialFit.

References d_p, and d_results.

Referenced by fit().


Member Data Documentation

double Fit::chi_2
protected

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

Referenced by chiSquare(), errors(), PolynomialFit::fit(), Fit(), LinearFit::fit(), fitGslMultifit(), fitGslMultimin(), legendInfo(), logFitInfo(), and rSquare().

gsl_matrix* Fit::covar
protected
fit_function_df Fit::d_df
protected
fit_function Fit::d_f
protected
fit_function_fdf Fit::d_fdf
protected
QString Fit::d_formula
protected
fit_function_simplex Fit::d_fsimplex
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_result_errors
protected

Stores standard deviations of the result parameters.

Referenced by errors(), Fit(), and ~Fit().

double* Fit::d_results
protected
bool Fit::d_scale_errors
protected

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

Referenced by errors(), Fit(), legendInfo(), logFitInfo(), and scaleErrors().

Script* Fit::d_script
protected

Script used to evaluate user-defined functions.

Referenced by NonLinearFit::calculateFitCurveData(), evaluate_d(), evaluate_df(), evaluate_f(), and fit().

Algorithm Fit::d_solver
protected

Algorithm type.

Referenced by Fit(), fit(), fitGslMultifit(), logFitInfo(), and setAlgorithm().

QString Fit::d_y_error_dataset
protected

The name of the dataset containing Y standard errors (if applicable).

Referenced by Fit(), logFitInfo(), and setYErrorSource().

ErrorSource Fit::d_y_error_source
protected

Where standard errors of the input data are taken from.

Referenced by PolynomialFit::fit(), Fit(), LinearFit::fit(), fitGslMultifit(), fitGslMultimin(), logFitInfo(), rSquare(), and setYErrorSource().

double* Fit::d_y_errors
protected
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 Fit(), PolynomialFit::init(), LinearFit::init(), logFitInfo(), and ~Fit().


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