33 #include "tnt_array1d.h" 34 #include "tnt_array1d_utils.h" 35 #include "tnt_array2d.h" 36 #include "tnt_array2d_utils.h" 38 #include <gsl/gsl_vector.h> 39 #include <gsl/gsl_matrix.h> 40 #include <gsl/gsl_blas.h> 41 #include <gsl/gsl_multifit_nlin.h> 59 typedef TNT::Array1D<double> NLVector;
60 typedef TNT::Array2D<double> NLMatrix;
63 NonLinearLSQ() : _fitParms(), _uncert(), _nIters(0), _maxIters(50),
64 _status(0), _userTerminated(
false), _userMessage() {}
69 virtual int nSize()
const = 0;
70 virtual int nParms()
const = 0;
87 virtual NLVector guess() = 0;
88 virtual NLVector f_x(
const NLVector &x) = 0;
89 virtual NLMatrix df_x(
const NLVector &x) = 0;
91 virtual double absErr()
const {
return (1.0
E-4); }
92 virtual double relErr()
const {
return (1.0
E-4); }
96 inline int status()
const {
return (_status); }
98 inline bool success()
const {
return (_status == GSL_SUCCESS); }
103 return (std::string(gsl_strerror(_status)));
107 return (std::string(gsl_strerror(
status)));
112 const NLVector &uncerts,
double cplxconj,
118 inline NLVector
coefs()
const {
return (_fitParms); }
120 inline NLVector
uncert()
const {
return (_uncert); }
125 void Terminate(
const std::string &message =
"");
126 void Abort(
const std::string &reason =
"");
128 bool doContinue()
const {
return (!_userTerminated); }
137 bool _userTerminated;
138 std::string _userMessage;
143 static int f(
const gsl_vector *x,
void *params, gsl_vector *fx);
144 static int df(
const gsl_vector *x,
void *params, gsl_matrix *J);
145 static int fdf(
const gsl_vector *x,
void *params, gsl_vector *fx,
148 NLVector gslToNlsq(
const gsl_vector *v)
const;
149 NLMatrix gslToNlsq(
const gsl_matrix *m)
const;
150 gsl_vector *NlsqTogsl(
const NLVector &v, gsl_vector *gv = 0)
const;
151 gsl_matrix *NlsqTogsl(
const NLMatrix &m, gsl_matrix *gm = 0)
const;
152 NLVector getUncertainty(
const gsl_matrix *m)
const;
virtual ~NonLinearLSQ()
Destructor.
std::string statusstr(int status) const
Return error message given status condition.
int maxIters() const
Maximum number iterations for valid solution.
int nIterations() const
Return number of iterations from last fit processing.
NonLinearLSQ Computes a fit using a Levenberg-Marquardt algorithm.
std::string statusstr() const
Return error message pertaining to last fit procesing.
NLVector uncert() const
Return uncertainties from last fit processing.
int status() const
Return status of last fit processing.
bool success(int status) const
Check status for success of the given condition.
const double E
Sets some basic constants for use in ISIS programming.
Namespace for ISIS/Bullet specific routines.
bool success() const
Determine success from last fit processing.
NLVector coefs() const
Return coefficients from last fit processing.
virtual int checkIteration(const int Iter, const NLVector &fitcoefs, const NLVector &uncerts, double cplxconj, int Istatus)
Default interation test simply returns input status.
void setMaxIters(int m)
Sets the maximum number of iterations.