Fit.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : Fit.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2006 by Ion Vasilief, Tilman Hoener zu Siederdissen
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr, thzs*gmx.net
00007     Description          : Fit base class
00008                            
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *  This program is free software; you can redistribute it and/or modify   *
00014  *  it under the terms of the GNU General Public License as published by   *
00015  *  the Free Software Foundation; either version 2 of the License, or      *
00016  *  (at your option) any later version.                                    *
00017  *                                                                         *
00018  *  This program is distributed in the hope that it will be useful,        *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00021  *  GNU General Public License for more details.                           *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public License     *
00024  *   along with this program; if not, write to the Free Software           *
00025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00026  *   Boston, MA  02110-1301  USA                                           *
00027  *                                                                         *
00028  ***************************************************************************/
00029 #ifndef FIT_H
00030 #define FIT_H
00031 
00032 #include <QObject>
00033 
00034 #include "ApplicationWindow.h"
00035 #include "Filter.h"
00036 
00037 #include <gsl/gsl_multifit_nlin.h>
00038 #include <gsl/gsl_multimin.h>
00039 
00040 class Table;
00041 class Matrix;
00042 
00044 class Fit : public Filter
00045 {
00046     Q_OBJECT
00047 
00048     public:
00049 
00050         typedef double (*fit_function_simplex)(const gsl_vector *, void *);
00051         typedef int (*fit_function)(const gsl_vector *, void *, gsl_vector *);
00052         typedef int (*fit_function_df)(const gsl_vector *, void *, gsl_matrix *);
00053         typedef int (*fit_function_fdf)(const gsl_vector *, void *, gsl_vector *, gsl_matrix *);
00054 
00055         enum Algorithm{ScaledLevenbergMarquardt, UnscaledLevenbergMarquardt, NelderMeadSimplex};
00056         enum WeightingMethod{NoWeighting, Instrumental, Statistical, Dataset};
00057 
00058         Fit(ApplicationWindow *parent, Graph *g = 0, const char * name = 0);
00059         ~Fit();
00060 
00062         virtual void fit();
00063         virtual bool run(){return false;};
00064 
00066         bool setWeightingData(WeightingMethod w, const QString& colName = QString::null);
00067 
00068         void setDataCurve(int curve, double start, double end);
00069 
00070         QString formula(){return d_formula;};
00071         int numParameters() {return d_p;}
00072 
00073         void setInitialGuess(int parIndex, double val){gsl_vector_set(d_param_init, parIndex, val);};
00074         void setInitialGuesses(double *x_init);
00075 
00076         virtual void guessInitialValues(){};
00077 
00078         void setAlgorithm(Algorithm s){d_solver = s;};
00079 
00081         void generateFunction(bool yes, int points = 100);
00082 
00084         virtual QString legendInfo();
00085 
00087         double* results(){return d_results;};
00088 
00090         double* errors();
00091 
00093         double chiSquare() {return chi_2;};
00094 
00096         double rSquare();
00097 
00099         void scaleErrors(bool yes = true){d_scale_errors = yes;};
00100 
00101         Table* parametersTable(const QString& tableName);
00102         Matrix* covarianceMatrix(const QString& matrixName);
00103 
00104     private:
00106         gsl_multimin_fminimizer * fitSimplex(gsl_multimin_function f, int &iterations, int &status);
00107 
00109         gsl_multifit_fdfsolver * fitGSL(gsl_multifit_function_fdf f, int &iterations, int &status);
00110 
00112         virtual void storeCustomFitResults(double *par);
00113 
00114     protected:
00116         void insertFitFunctionCurve(const QString& name, double *x, double *y, int penWidth = 1);
00117 
00119         virtual void generateFitCurve(double *par);
00120 
00122         virtual void calculateFitCurveData(double *par, double *X, double *Y) { Q_UNUSED(par) Q_UNUSED(X) Q_UNUSED(Y)   };
00123 
00125         virtual QString logFitInfo(double *par, int iterations, int status, const QString& plotName);
00126 
00127         fit_function d_f;
00128         fit_function_df d_df;
00129         fit_function_fdf d_fdf;
00130         fit_function_simplex d_fsimplex;
00131 
00133         int d_p;
00134 
00136         gsl_vector *d_param_init;
00137 
00141         bool is_non_linear;
00142 
00144         double *d_w;
00145 
00147         QStringList d_param_names;
00148 
00150         QStringList d_param_explain;
00151 
00153         bool d_gen_function;
00154 
00156         Algorithm d_solver;
00157 
00159         QString d_formula;
00160 
00162         gsl_matrix *covar;
00163 
00165         WeightingMethod d_weihting;
00166 
00168         QString weighting_dataset;
00169 
00171         double *d_results;
00172 
00174         double *d_errors;
00175 
00177         double chi_2;
00178 
00180         bool d_scale_errors;
00181 };
00182 
00183 #endif

Generated on Mon Oct 15 06:11:41 2007 for QtiPlot by  doxygen 1.5.3