37 #include <gsl/gsl_multifit_nlin.h>
38 #include <gsl/gsl_multimin.h>
51 typedef int (*
fit_function)(
const gsl_vector *,
void *, gsl_vector *);
53 typedef int (*
fit_function_fdf)(
const gsl_vector *,
void *, gsl_vector *, gsl_matrix *);
66 virtual bool run(){
fit();
return true;};
71 void setDataCurve(QwtPlotCurve *curve,
double start,
double end);
72 bool setDataFromTable(
Table *t,
const QString& xColName,
const QString& yColName,
int from = 1,
int to = -1,
bool sort =
false);
76 virtual bool setFormula(
const QString&,
bool =
true){
return true;};
110 double lcl(
int parIndex,
double confidenceLevel);
112 double ucl(
int parIndex,
double confidenceLevel);
150 virtual double eval(
double *,
double){
return 0.0;};
156 gsl_multimin_fminimizer *
fitSimplex(gsl_multimin_function f,
int &iterations,
int &status);
159 gsl_multifit_fdfsolver *
fitGSL(gsl_multifit_function_fdf f,
int &iterations,
int &status);
184 virtual QString
logFitInfo(
int iterations,
int status);
Fit(ApplicationWindow *parent, QwtPlotCurve *c)
Definition: Fit.cpp:49
double * residuals()
Returns a vector with the fit residuals.
Definition: Fit.cpp:634
Table * parametersTable(const QString &tableName)
Definition: Fit.cpp:550
void showConfidenceLimits(double confidenceLevel)
Definition: Fit.cpp:685
double chi_2
The sum of squares of the residuals from the best-fit line.
Definition: Fit.h:242
~Fit()
Definition: Fit.cpp:1180
bool setDataFromTable(Table *t, const QString &xColName, const QString &yColName, int from=1, int to=-1, bool sort=false)
Definition: Fit.cpp:228
virtual QString logFitInfo(int iterations, int status)
Output string added to the result log.
Definition: Fit.cpp:292
double * d_results
Stores the result parameters.
Definition: Fit.h:233
int(* fit_function)(const gsl_vector *, void *, gsl_vector *)
Definition: Fit.h:51
double * d_residuals
Stores fit residuals.
Definition: Fit.h:239
gsl_matrix * covar
Covariance matrix.
Definition: Fit.h:224
void setAlgorithm(Algorithm s)
Definition: Fit.h:90
void setParameterExplanations(const QStringList &lst)
Definition: Fit.h:81
fit_function_simplex d_fsimplex
Definition: Fit.h:189
A 2D-plotting widget.
Definition: Graph.h:123
int(* fit_function_fdf)(const gsl_vector *, void *, gsl_vector *, gsl_matrix *)
Definition: Fit.h:53
virtual bool setFormula(const QString &, bool=true)
Definition: Fit.h:76
gsl_multimin_fminimizer * fitSimplex(gsl_multimin_function f, int &iterations, int &status)
Pointer to the GSL multifit minimizer (for simplex algorithm)
Definition: Fit.cpp:164
virtual void fit()
Actually does the fit. Should be reimplemented in derived classes.
Definition: Fit.cpp:903
Matrix * covarianceMatrix(const QString &matrixName)
Definition: Fit.cpp:602
void setInitialGuesses(double *x_init)
Definition: Fit.cpp:279
QString fileName()
Definition: Fit.h:146
void setParameterRange(int parIndex, double left, double right)
Definition: Fit.cpp:1102
double ucl(int parIndex, double confidenceLevel)
Upper Confidence Limit.
Definition: Fit.cpp:795
double(* fit_function_simplex)(const gsl_vector *, void *)
Definition: Fit.h:50
virtual void generateFitCurve()
Adds the result curve to the plot.
Definition: Fit.cpp:979
void writeParametersToTable(Table *t, bool append=false)
Definition: Fit.cpp:568
virtual bool setParametersList(const QStringList &)
Definition: Fit.h:80
Abstract base class for data analysis operations.
Definition: Filter.h:43
double initialGuess(int parIndex)
Definition: Fit.h:83
double adjustedRSquare()
Returns adjusted R^2.
Definition: Fit.h:124
QString weighting_dataset
The name of the weighting dataset.
Definition: Fit.h:230
double lcl(int parIndex, double confidenceLevel)
Lower Confidence Limit.
Definition: Fit.cpp:786
void setFileName(const QString &fn)
Definition: Fit.h:147
void showPredictionLimits(double confidenceLevel)
Definition: Fit.cpp:804
Algorithm d_solver
Algorithm type.
Definition: Fit.h:215
virtual bool removeDataSingularities()
Removes any data singularities before fitting.
Definition: Fit.h:165
QStringList d_param_names
Names of the fit parameters.
Definition: Fit.h:206
QString d_result_formula
The result fit formula, where the fit parameters are replaced with the calculated values...
Definition: Fit.h:221
bool setWeightingData(WeightingMethod w, const QString &colName=QString::null)
Sets the data set to be used for weighting.
Definition: Fit.cpp:433
QwtPlotCurve * showResiduals()
Plot residuals and display data values in a column.
Definition: Fit.cpp:647
QStringList parameterNames()
Definition: Fit.h:79
void initWorkspace(int par)
Allocates the memory for the fit workspace.
Definition: Fit.cpp:1111
double * d_param_range_right
Stores the right limits of the research interval for the result parameters.
Definition: Fit.h:268
double * d_w
weighting data set used for the fit
Definition: Fit.h:203
FitType
Definition: Fit.h:57
double d_adjusted_r_square
Adjusted R^2.
Definition: Fit.h:248
Fit base class.
Definition: Fit.h:44
QString formula()
Definition: Fit.h:75
double chiSquare()
Returns the sum of squares of the residuals from the best-fit line.
Definition: Fit.h:118
int d_n
Size of the data arrays.
Definition: Filter.h:159
virtual bool run()
Actually does the job. Should be reimplemented in derived classes.
Definition: Fit.h:66
bool is_non_linear
Tells whether the fitter uses non-linear/simplex fitting with an initial parameters set...
Definition: Fit.h:200
bool load(const QString &fileName)
Definition: Fit.cpp:1078
double rmse()
Returns the Root Mean Squared Error.
Definition: Fit.h:130
double * errors()
Returns a vector with the standard deviations of the results.
Definition: Fit.cpp:619
void setType(FitType t)
Definition: Fit.h:144
double * d_param_range_left
Stores the left limits of the research interval for the result parameters.
Definition: Fit.h:265
QtiPlot's main window.
Definition: ApplicationWindow.h:133
fit_function_fdf d_fdf
Definition: Fit.h:188
Definition: FunctionCurve.h:37
QString d_file_name
Path of the XML file where the user stores the fit model.
Definition: Fit.h:262
Matrix worksheet class.
Definition: Matrix.h:57
double d_rss
Residual sum of squares.
Definition: Fit.h:245
FitType d_fit_type
Definition: Fit.h:259
WeightingMethod d_weighting
The kind of weighting to be performed on the data.
Definition: Fit.h:227
gsl_multifit_fdfsolver * fitGSL(gsl_multifit_function_fdf f, int &iterations, int &status)
Pointer to the GSL multifit solver.
Definition: Fit.cpp:106
void setDataCurve(QwtPlotCurve *curve, double start, double end)
Definition: Fit.cpp:247
void freeWorkspace()
Frees the memory allocated for the fit workspace.
Definition: Fit.cpp:1133
double rSquare()
Returns R^2.
Definition: Fit.cpp:379
QString resultFormula()
Definition: Fit.h:74
double * d_errors
Stores standard deviations of the result parameters.
Definition: Fit.h:236
void init()
Definition: Fit.cpp:67
Matrix * d_cov_matrix
Matrix window used for the output of covariance matrix.
Definition: Fit.h:257
int numParameters()
Definition: Fit.h:78
bool d_gen_function
Specifies weather the result curve is a FunctionCurve or a normal curve with the same x values as the...
Definition: Fit.h:212
void scaleErrors(bool yes=true)
Specifies wheather the errors must be scaled with sqrt(chi_2/dof)
Definition: Fit.h:133
virtual void guessInitialValues()
Definition: Fit.h:87
void generateFunction(bool yes, int points=100)
Specifies weather the result of the fit is a function curve.
Definition: Fit.cpp:285
int d_p
Number of fit parameters.
Definition: Fit.h:192
fit_function d_f
Definition: Fit.h:186
virtual void calculateFitCurveData(double *X, double *Y)
Calculates the data for the output fit curve and store itin the X an Y vectors.
Definition: Fit.h:181
double * results()
Returns a vector with the fit results.
Definition: Fit.h:99
QPointer< Table > d_param_table
Table window used for the output of fit parameters.
Definition: Fit.h:254
virtual FunctionCurve * insertFitFunctionCurve(const QString &name, int penWidth=1, bool updateData=true)
Adds the result curve as a FunctionCurve to the plot, if d_gen_function = true.
Definition: Fit.cpp:1020
QString d_formula
The fit formula given on input.
Definition: Fit.h:218
MDI window providing a spreadsheet table with column logic.
Definition: Table.h:57
virtual double eval(double *, double)
Calculates the data for the output fit curve.
Definition: Fit.h:150
int(* fit_function_df)(const gsl_vector *, void *, gsl_matrix *)
Definition: Fit.h:52
virtual void freeMemory()
Frees all the arrays with size d_n. Used when changing the source data sets.
Definition: Fit.cpp:1166
bool d_scale_errors
Specifies wheather the errors must be scaled with sqrt(chi_2/dof)
Definition: Fit.h:251
fit_function_df d_df
Definition: Fit.h:187
WeightingMethod
Definition: Fit.h:56
double rss()
Returns the Residual Sum of Squares.
Definition: Fit.h:127
virtual QString legendInfo()
Output string added to the plot as a new legend.
Definition: Fit.cpp:402
Algorithm
Definition: Fit.h:55
QStringList d_param_explain
Stores a list of short explanations for the significance of the fit parameters.
Definition: Fit.h:209
gsl_vector * d_param_init
Initial guesses for the fit parameters.
Definition: Fit.h:195
void setInitialGuess(int parIndex, double val)
Definition: Fit.h:84
FitType type()
Definition: Fit.h:143
bool save(const QString &fileName)
Definition: Fit.cpp:1043
virtual void customizeFitResults()
Customs and stores the fit results according to the derived class specifications. Used by exponential...
Definition: Fit.h:162