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
16namespace MEAL {
17
20 {
21
22 public:
23
24 typedef std::vector< std::vector<double> > matrix;
25
27 virtual std::string get_name () const = 0;
28
31
33 unsigned get_maximum_iterations () const { return maximum_iterations; }
34
36 void set_convergence_chisq (float chisq);
37
39 void set_convergence_delta (float delta_parameters);
40
42 void set_maximum_reduced_chisq (float maximum_reduced_chisq);
43
45 void set_debug (bool flag = true) { debug = flag; }
46
48 void set_solved (bool val) { solved = val; }
49
51 bool get_solved () const { return solved; }
52
54 void set_singular (bool val) { singular = val; }
55
57 bool get_singular () const { return singular; }
58
60 unsigned get_iterations () const { return iterations; }
61
63 float get_chisq () const { return best_chisq; }
64
66 unsigned get_nfree () const { return nfree; }
67
69 unsigned get_nparam_infit () const { return nparam_infit; }
70
72 unsigned get_ndat_constraint () const { return ndat_constraint; }
73
75 double get_log_det_curvature () const { return log_det_Hessian; }
76
78 double get_log_cond_curvature () const { return log_cond_Hessian; }
79
81 void get_covariance (matrix& c) const { c = covariance; }
82
83 protected:
84
86 unsigned maximum_iterations = 50;
87
89 float convergence_chisq = 0.0;
90
92 float convergence_delta = 0.01;
93
95 float maximum_reduced = 0.0;
96
98 unsigned iterations = 0;
99
101 double log_det_Hessian = 0.0;
102
104 double log_cond_Hessian = 0.0;
105
107 float best_chisq = 0.0;
108
110 unsigned nfree = 0;
111
113 unsigned nparam_infit = 0;
114
116 unsigned ndat_constraint = 0;
117
119 bool debug = false;
120
122 bool solved = false;
123
125 bool singular = false;
126
129 };
130}
131
132#endif
133
Definition LeastSquares.h:20
double log_cond_Hessian
Logarithm of the condition number of the Hessian matrix.
Definition LeastSquares.h:104
void set_debug(bool flag=true)
Set the verbosity during solve.
Definition LeastSquares.h:45
void set_maximum_reduced_chisq(float maximum_reduced_chisq)
Set the reduced chi-squared above which the fit is considered bad.
Definition LeastSquares.C:20
float get_chisq() const
The chi-squared in last call to solve method.
Definition LeastSquares.h:63
void get_covariance(matrix &c) const
Get the covariance matrix of the last fit.
Definition LeastSquares.h:81
void set_convergence_delta(float delta_parameters)
Set the convergence threshold as relative change in parameters.
Definition LeastSquares.C:15
unsigned ndat_constraint
The total number of constraints (multi-dimensional data)
Definition LeastSquares.h:116
bool debug
The fit debug mode.
Definition LeastSquares.h:119
bool get_singular() const
Return true when the fit has failed due to singularity.
Definition LeastSquares.h:57
double get_log_cond_curvature() const
The logarithm of the condition number of the chi-squared curvature matrix.
Definition LeastSquares.h:78
float convergence_delta
The convergence delta.
Definition LeastSquares.h:92
double get_log_det_curvature() const
The logarithm of the determinant of the chi-squared curvature matrix.
Definition LeastSquares.h:75
float convergence_chisq
The convergence chisq.
Definition LeastSquares.h:89
void set_solved(bool val)
Set the solved flag (can be used to flag bad data)
Definition LeastSquares.h:48
void set_maximum_iterations(unsigned maximum_iterations)
Set the maximum number of iterations in fit algorithm.
unsigned get_ndat_constraint() const
The total number of constraints (one-dimensional data)
Definition LeastSquares.h:72
unsigned maximum_iterations
The maximum number of iterations in during fit.
Definition LeastSquares.h:86
float best_chisq
The best chi-squared in last call to solve method.
Definition LeastSquares.h:107
double log_det_Hessian
Logarithm of the determinant of the Hessian matrix.
Definition LeastSquares.h:101
unsigned get_nfree() const
The number of degrees of freedom in last call to solve method.
Definition LeastSquares.h:66
float maximum_reduced
The maximum reduced chi-squared allowed.
Definition LeastSquares.h:95
bool solved
Set true when fit has been solved.
Definition LeastSquares.h:122
unsigned nfree
The number of free parameters in last call to solve method.
Definition LeastSquares.h:110
void set_singular(bool val)
Set the singular flag (can be used to flag bad data)
Definition LeastSquares.h:54
unsigned get_nparam_infit() const
Get the number of parameters in fit.
Definition LeastSquares.h:69
bool get_solved() const
Return true when the fit has been solved.
Definition LeastSquares.h:51
virtual std::string get_name() const =0
Return the name of the fit algorithm.
unsigned nparam_infit
The number of parameters to be fit.
Definition LeastSquares.h:113
matrix covariance
The covariance matrix set after fitting.
Definition LeastSquares.h:128
bool singular
Set true when the fit failed due to a singular Hessian matrix.
Definition LeastSquares.h:125
unsigned get_maximum_iterations() const
Get the maximum number of iterations in fit algorithm.
Definition LeastSquares.h:33
unsigned get_iterations() const
The number of iterations in last call to solve method.
Definition LeastSquares.h:60
unsigned iterations
The number of iterations in last call to solve method.
Definition LeastSquares.h:98
void set_convergence_chisq(float chisq)
Set the convergence threshold as an absolute value of chisq.
Definition LeastSquares.C:10
Namespace in which all modeling and calibration related code is declared.
Definition ExampleComplex2.h:16

Generated using doxygen 1.14.0