libkpl  5.0
A Library for Graphical Presentation of Data Sets and Functions
lmfit.h
1 /***************************************************************************
2  lmfit.h - description
3  -------------------
4  begin : Sat May 22 1999
5  copyright : (C) 2017 by Werner Stille
6  email : kpl@werner-stille.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef LMDIF_H
19 #define LMDIF_H
20 
21 #include <QObject>
22 
23 class QString;
24 class ArrayItem;
25 class FunItem;
26 
41 class Q_DECL_EXPORT LMFit : public QObject
42 {
43  Q_OBJECT
44 public:
54  LMFit(const QList<const ArrayItem*>* aList, QList<FunItem*>* fList,
55  const bool* bFit, double* par, QObject* parent = 0,
56  const double* sigma = 0);
58  ~LMFit();
65  static double enorm(int n, const double x[]);
72  static double igamc(double a, double x);
84  bool linFit(int n, int nPar, double par[], double resVector[], double fJac[],
85  int iPvt[]);
99  void lmdif(int n, int nPar, double par[], double resVector[], double tol,
100  int itMax, int* info, double fJac[], int iPvt[]);
108  static int minv(double a[], double x[], int n);
113  inline void setSigma(const double* sigma) { m_sigma = sigma; };
118  inline void setUserBreak(bool userBreak = true) { m_userBreak = userBreak; };
120  inline bool userBreak() const { return m_userBreak; };
121 
122 protected:
123  void fcn(int n, int np, const double p[], double fvec[], int* iflag);
124  void fdjac2(int m, int n, double x[], const double fvec[], double fjac[],
125  int ldfjac, int* iflag, double epsfcn, double wa[]);
126  void lmdif(int m, int np, double px[], double fvec[], double ftol,
127  double ptol, double gtol, int maxfev, double epsfcn,
128  double diag[], int mode, double factor, int nprint,
129  int* info, int* nfev, double fjac[], int ldfjac,
130  int ipvt[], double qtf[], double wa1[], double wa2[],
131  double wa3[], double wa4[]);
132  bool m_userBreak;
133  const bool* m_bFit;
134  double* m_par;
135  const double* m_sigma;
136  const QList<const ArrayItem*>* m_aList;
137  QList<FunItem*>* m_fList;
138 
139 signals:
144  void updateMessage(const QString& message);
145 };
146 
147 #endif
Array item class.
Definition: arrayitem.h:37
Function item class.
Definition: funitem.h:40
Parameter fit class.
Definition: lmfit.h:42
void lmdif(int n, int nPar, double par[], double resVector[], double tol, int itMax, int *info, double fJac[], int iPvt[])
Performs nonlinear Levenberg-Marquardt parameter fit.
static double igamc(double a, double x)
Calculates complemented incomplete gamma integral.
bool linFit(int n, int nPar, double par[], double resVector[], double fJac[], int iPvt[])
Performs general linear least square parameter fit.
void updateMessage(const QString &message)
Emitted when a message should be displayed.
void setSigma(const double *sigma)
Sets data error array.
Definition: lmfit.h:113
static double enorm(int n, const double x[])
Calculates the euclidean norm of x.
static int minv(double a[], double x[], int n)
Finds the inverse of a square matrix.
void setUserBreak(bool userBreak=true)
Sets condition to stop calculations.
Definition: lmfit.h:118
bool userBreak() const
Returns current break condition for calculations.
Definition: lmfit.h:120
~LMFit()
Destructor.
LMFit(const QList< const ArrayItem * > *aList, QList< FunItem * > *fList, const bool *bFit, double *par, QObject *parent=0, const double *sigma=0)
Constructor.