LeastSquares.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2008 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/More/MEAL/MEAL/LeastSquares.h
10 
11 #ifndef __MEAL_LeastSquares_H
12 #define __MEAL_LeastSquares_H
13 
14 #include "Reference.h"
15 
16 namespace MEAL {
17 
19  class LeastSquares : public Reference::Able
20  {
21 
22  public:
23 
24  typedef std::vector< std::vector<double> > matrix;
25 
27  LeastSquares ();
28 
30  virtual std::string get_name () const = 0;
31 
34 
36  unsigned get_maximum_iterations () const { return maximum_iterations; }
37 
39  void set_convergence_chisq (float chisq);
40 
42  void set_convergence_delta (float delta_parameters);
43 
45  void set_maximum_reduced_chisq (float maximum_reduced_chisq);
46 
48  void set_debug (bool flag = true) { debug = flag; }
49 
51  void set_solved (bool val) { solved = val; }
52 
54  bool get_solved () const { return solved; }
55 
57  void set_singular (bool val) { singular = val; }
58 
60  bool get_singular () const { return singular; }
61 
63  unsigned get_iterations () const { return iterations; }
64 
66  float get_chisq () const { return best_chisq; }
67 
69  unsigned get_nfree () const { return nfree; }
70 
72  unsigned get_nparam_infit () const { return nparam_infit; }
73 
75  unsigned get_ndat_constraint () const { return ndat_constraint; }
76 
78  void get_covariance (matrix& c) const { c = covariance; }
79 
80  protected:
81 
83  unsigned maximum_iterations;
84 
86  float convergence_chisq;
87 
89  float convergence_delta;
90 
92  float maximum_reduced;
93 
95  unsigned iterations;
96 
98  float best_chisq;
99 
101  unsigned nfree;
102 
104  unsigned nparam_infit;
105 
107  unsigned ndat_constraint;
108 
110  bool debug;
111 
113  bool solved;
114 
116  bool singular;
117 
119  matrix covariance;
120 
121  };
122 
123 }
124 
125 #endif
126 
unsigned maximum_iterations
The maximum number of iterations in during fit.
Definition: LeastSquares.h:93
bool debug
The fit debug mode.
Definition: LeastSquares.h:120
void set_maximum_reduced_chisq(float maximum_reduced_chisq)
Set the reduced chi-squared above which the fit is considered bad.
Definition: LeastSquares.C:45
unsigned get_ndat_constraint() const
The total number of constraints (one-dimensional data)
Definition: LeastSquares.h:85
bool get_solved() const
Return true when the fit has been solved.
Definition: LeastSquares.h:64
void set_solved(bool val)
Set the solved flag (can be used to flag bad data)
Definition: LeastSquares.h:61
float best_chisq
The best chi-squared in last call to solve method.
Definition: LeastSquares.h:108
float maximum_reduced
The maximum reduced chi-squared allowed.
Definition: LeastSquares.h:102
float convergence_delta
The convergence delta.
Definition: LeastSquares.h:99
float convergence_chisq
The convergence chisq.
Definition: LeastSquares.h:96
unsigned get_nparam_infit() const
Get the number of parameters in fit.
Definition: LeastSquares.h:82
Namespace in which all modeling and calibration related code is declared.
Definition: ExampleComplex2.h:16
unsigned nparam_infit
The number of parameters to be fit.
Definition: LeastSquares.h:114
LeastSquares()
Default constructor.
Definition: LeastSquares.C:10
void get_covariance(matrix &c) const
Get the covariance matrix of the last fit.
Definition: LeastSquares.h:88
bool singular
Set true when the fit failed due to a singular Hessian matrix.
Definition: LeastSquares.h:126
unsigned iterations
The number of iterations in last call to solve method.
Definition: LeastSquares.h:105
void set_maximum_iterations(unsigned maximum_iterations)
Set the maximum number of iterations in fit algorithm.
virtual std::string get_name() const =0
Return the name of the fit algorithm.
void set_convergence_delta(float delta_parameters)
Set the convergence threshold as relative change in parameters.
Definition: LeastSquares.C:40
bool solved
Set true when fit has been solved.
Definition: LeastSquares.h:123
unsigned get_iterations() const
The number of iterations in last call to solve method.
Definition: LeastSquares.h:73
void set_convergence_chisq(float chisq)
Set the convergence threshold as an absolute value of chisq.
Definition: LeastSquares.C:35
float get_chisq() const
The chi-squared in last call to solve method.
Definition: LeastSquares.h:76
bool get_singular() const
Return true when the fit has failed due to singularity.
Definition: LeastSquares.h:70
matrix covariance
The covariance matrix set after fitting.
Definition: LeastSquares.h:129
unsigned get_maximum_iterations() const
Get the maximum number of iterations in fit algorithm.
Definition: LeastSquares.h:46
unsigned nfree
The number of free parameters in last call to solve method.
Definition: LeastSquares.h:111
void set_debug(bool flag=true)
Set the verbosity during solve.
Definition: LeastSquares.h:58
unsigned ndat_constraint
The total number of constraints (multi-dimensional data)
Definition: LeastSquares.h:117
unsigned get_nfree() const
The number of degrees of freedom in last call to solve method.
Definition: LeastSquares.h:79
void set_singular(bool val)
Set the singular flag (can be used to flag bad data)
Definition: LeastSquares.h:67

Generated using doxygen 1.8.17