File failed to load: https://isis.astrogeology.usgs.gov/6.0.0/Object/assets/jax/output/NativeMML/config.js
Isis Developer Reference
LeastSquares.h
Go to the documentation of this file.
1 #ifndef LeastSquares_h
2 #define LeastSquares_h
3 
8 /* SPDX-License-Identifier: CC0-1.0 */
9 #include <vector>
10 
11 #include "tnt/tnt_array2d.h"
12 
13 #include <armadillo>
14 
15 #include "BasisFunction.h"
16 
17 namespace Isis {
99  class LeastSquares {
100  public:
101 
102  LeastSquares(Isis::BasisFunction &basis, bool sparse = false,
103  int sparseRows = 0, int sparseCols = 0, bool jigsaw = false);
104  ~LeastSquares();
105  void AddKnown(const std::vector<double> &input, double expected,
106  double weight = 1.0);
107 
108  std::vector<double> GetInput(int row) const;
109  double GetExpected(int row) const;
110  int Rows() const;
111 
112  enum SolveMethod { SVD,
113  QRD,
114  SPARSE
115  };
116 
118  double Evaluate(const std::vector<double> &input);
119  std::vector<double> Residuals() const;
120  double Residual(int i) const;
121  void Weight(int index, double weight);
122 
129  int Knowns() const {
130  return p_expected.size();
131  };
132 
133  double GetSigma0() { return p_sigma0; }
134  int GetDegreesOfFreedom() { return p_degreesOfFreedom; }
135  void Reset ();
136 
137  void ResetSparse() { Reset(); }
138  std::vector<double> GetEpsilons () const { return p_epsilonsSparse; }
139  void SetParameterWeights(const std::vector<double> weights) { p_parameterWeights = weights; }
140  void SetNumberOfConstrainedParameters(int n) { p_constrainedParameters = n; }
141 
142  private:
143  void SolveSVD();
144  void SolveQRD();
145  void SolveCholesky () {}
146 
147  int SolveSparse();
148  void FillSparseA(const std::vector<double> &data);
149  bool ApplyParameterWeights();
150 
151  arma::mat p_xSparse;
152  std::vector<double> p_epsilonsSparse;
153  std::vector<double> p_parameterWeights;
155  arma::SpMat<double> p_sparseA;
156  arma::SpMat<double> p_normals;
157  arma::mat p_ATb;
158  arma::mat p_SLU_Factor;
160  bool p_jigsaw;
161  bool p_sparse;
162  bool p_solved;
164  int p_currentFillRow;
165  int p_sparseRows;
166  int p_sparseCols;
167  int p_constrainedParameters;
168  int p_degreesOfFreedom;
170  double p_sigma0;
172  std::vector<std::vector<double> > p_input;
174  std::vector<double> p_expected;
176  std::vector<double> p_sqrtWeight;
179  std::vector<double> p_residuals;
183  Isis::BasisFunction *p_basis;
184 
185 
186 
187  };
188 };
189 
190 
191 #endif
Isis::LeastSquares::LeastSquares
LeastSquares(Isis::BasisFunction &basis, bool sparse=false, int sparseRows=0, int sparseCols=0, bool jigsaw=false)
Creates a LeastSquares Object.
Definition: LeastSquares.cpp:23
Isis::LeastSquares::Solve
int Solve(Isis::LeastSquares::SolveMethod method=SVD)
After all the data has been registered through AddKnown, invoke this method to solve the system of eq...
Definition: LeastSquares.cpp:205
Isis::LeastSquares::GetDegreesOfFreedom
int GetDegreesOfFreedom()
Definition: LeastSquares.h:134
Isis::LeastSquares::GetInput
std::vector< double > GetInput(int row) const
This method returns the data at the given row.
Definition: LeastSquares.cpp:158
Isis::BasisFunction::SetCoefficients
void SetCoefficients(const std::vector< double > &coefs)
Set the coefficients for the equation.
Definition: BasisFunction.cpp:42
Isis::LeastSquares::Knowns
int Knowns() const
The number of knowns (or times AddKnown was invoked) linear combination of the variables.
Definition: LeastSquares.h:129
Isis::BasisFunction
Generic linear equation class.
Definition: BasisFunction.h:48
Isis::IException::Unknown
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition: IException.h:118
Isis::LeastSquares::SPARSE
@ SPARSE
Sparse.
Definition: LeastSquares.h:114
Isis::LeastSquares::Evaluate
double Evaluate(const std::vector< double > &input)
Invokes the BasisFunction Evaluate method.
Definition: LeastSquares.cpp:553
Isis::BasisFunction::Term
double Term(int c) const
Returns the cth term.
Definition: BasisFunction.h:97
Isis::BasisFunction::Name
QString Name() const
Returns the name of the equation.
Definition: BasisFunction.h:80
Isis::LeastSquares::SolveMethod
SolveMethod
Definition: LeastSquares.h:112
Isis::LeastSquares::Rows
int Rows() const
This methods returns the number of rows in the matrix.
Definition: LeastSquares.cpp:187
Isis::LeastSquares::Residual
double Residual(int i) const
Returns the ith residual.
Definition: LeastSquares.cpp:590
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
IString.h
Isis::LeastSquares::Reset
void Reset()
Definition: LeastSquares.cpp:523
Isis::LeastSquares::~LeastSquares
~LeastSquares()
Destroys the LeastSquares object.
Definition: LeastSquares.cpp:62
Isis::LeastSquares
Generic least square fitting class.
Definition: LeastSquares.h:99
_FILEINFO_
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:24
Isis::BasisFunction::Expand
virtual void Expand(const std::vector< double > &vars)
This is the function you should replace depending on your needs.
Definition: BasisFunction.cpp:123
Isis::LeastSquares::SetParameterWeights
void SetParameterWeights(const std::vector< double > weights)
Definition: LeastSquares.h:139
Isis::LeastSquares::GetEpsilons
std::vector< double > GetEpsilons() const
Definition: LeastSquares.h:138
LeastSquares.h
Isis::LeastSquares::GetExpected
double GetExpected(int row) const
This method returns the expected value at the given row.
Definition: LeastSquares.cpp:173
Isis::IException
Isis exception class.
Definition: IException.h:91
BasisFunction.h
Isis::LeastSquares::QRD
@ QRD
QR Decomposition.
Definition: LeastSquares.h:113
Isis::BasisFunction::Variables
int Variables() const
Returns the number of variables in the equation.
Definition: BasisFunction.h:72
IException.h
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
Isis::LeastSquares::SetNumberOfConstrainedParameters
void SetNumberOfConstrainedParameters(int n)
Definition: LeastSquares.h:140
Isis::LeastSquares::ResetSparse
void ResetSparse()
Definition: LeastSquares.h:137
Isis::LeastSquares::AddKnown
void AddKnown(const std::vector< double > &input, double expected, double weight=1.0)
Invoke this method for each set of knowns.
Definition: LeastSquares.cpp:96
Isis::LeastSquares::SVD
@ SVD
Singular Value Decomposition.
Definition: LeastSquares.h:112
Isis::BasisFunction::Evaluate
double Evaluate(const std::vector< double > &vars)
Compute the equation using the input variables.
Definition: BasisFunction.cpp:64
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::BasisFunction::Coefficients
int Coefficients() const
Returns the number of coefficients for the equation.
Definition: BasisFunction.h:64
Isis::LeastSquares::Weight
void Weight(int index, double weight)
Reset the weight for the ith known.
Definition: LeastSquares.cpp:614
Isis::LeastSquares::GetSigma0
double GetSigma0()
Definition: LeastSquares.h:133
Isis::LeastSquares::Residuals
std::vector< double > Residuals() const
Returns a vector of residuals (errors).
Definition: LeastSquares.cpp:570

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 03/21/2022 06:50:59