USGS

Isis 3.0 Object Programmers' Reference

Home

LeastSquares.h
Go to the documentation of this file.
1 #ifndef LeastSquares_h
2 #define LeastSquares_h
3 
25 #include <vector>
26 
27 #include "tnt/tnt_array2d.h"
28 
29 #ifndef __sun__
30 #include "gmm/gmm.h"
31 #endif
32 
33 #include "BasisFunction.h"
34 
35 namespace Isis {
115  class LeastSquares {
116  public:
117 
118  LeastSquares(Isis::BasisFunction &basis, bool sparse = false,
119  int sparseRows = 0, int sparseCols = 0, bool jigsaw = false);
120  ~LeastSquares();
121  void AddKnown(const std::vector<double> &input, double expected,
122  double weight = 1.0);
123 
124  std::vector<double> GetInput(int row) const;
125  double GetExpected(int row) const;
126  int Rows() const;
127 
128  enum SolveMethod { SVD,
129  QRD,
131  };
132 
134  double Evaluate(const std::vector<double> &input);
135  std::vector<double> Residuals() const;
136  double Residual(int i) const;
137  void Weight(int index, double weight);
138 
145  int Knowns() const {
146  return p_expected.size();
147  };
148 
149  double GetSigma0() { return p_sigma0; }
150  int GetDegreesOfFreedom() { return p_degreesOfFreedom; }
151  void Reset ();
152 
153 #ifndef __sun__
154  void ResetSparse() { Reset(); }
155  bool SparseErrorPropagation();
156  std::vector<double> GetEpsilons () const { return p_epsilonsSparse; }
157  void SetParameterWeights(const std::vector<double> weights) { p_parameterWeights = weights; }
158  void SetNumberOfConstrainedParameters(int n) { p_constrainedParameters = n; }
159  const gmm::row_matrix<gmm::rsvector<double> >& GetCovarianceMatrix () const { return p_normals; }
160 #endif
161 
162  private:
163  void SolveSVD();
164  void SolveQRD();
165  void SolveCholesky () {}
166 
167 #ifndef __sun__
168  int SolveSparse();
169  void FillSparseA(const std::vector<double> &data);
170  bool ApplyParameterWeights();
171 
172  std::vector<double> p_xSparse;
173  std::vector<double> p_epsilonsSparse;
174  std::vector<double> p_parameterWeights;
176  gmm::row_matrix<gmm::rsvector<double> > p_sparseA;
177  private:
178  gmm::row_matrix<gmm::rsvector<double> > p_normals;
179  private:
180  gmm::dense_matrix<double> p_ATb;
181  gmm::SuperLU_factor<double> p_SLU_Factor;
182 #endif
183  bool p_jigsaw;
184  bool p_sparse;
185  bool p_solved;
187  int p_currentFillRow;
188  int p_sparseRows;
189  int p_sparseCols;
193  double p_sigma0;
195  std::vector<std::vector<double> > p_input;
197  std::vector<double> p_expected;
199  std::vector<double> p_sqrtWeight;
202  std::vector<double> p_residuals;
207 
208 
209 
210  };
211 };
212 
213 
214 #endif