Isis Developer Reference
|
Generic least square fitting class. More...
#include <LeastSquares.h>
Public Types | |
enum | SolveMethod { SVD , QRD , SPARSE } |
Public Member Functions | |
LeastSquares (Isis::BasisFunction &basis, bool sparse=false, int sparseRows=0, int sparseCols=0, bool jigsaw=false) | |
Creates a LeastSquares Object. | |
~LeastSquares () | |
Destroys the LeastSquares object. | |
void | AddKnown (const std::vector< double > &input, double expected, double weight=1.0) |
Invoke this method for each set of knowns. | |
std::vector< double > | GetInput (int row) const |
This method returns the data at the given row. | |
double | GetExpected (int row) const |
This method returns the expected value at the given row. | |
int | Rows () const |
This methods returns the number of rows in the matrix. | |
int | Solve (Isis::LeastSquares::SolveMethod method=SVD) |
After all the data has been registered through AddKnown, invoke this method to solve the system of equations. | |
double | Evaluate (const std::vector< double > &input) |
Invokes the BasisFunction Evaluate method. | |
std::vector< double > | Residuals () const |
Returns a vector of residuals (errors). | |
double | Residual (int i) const |
Returns the ith residual. | |
void | Weight (int index, double weight) |
Reset the weight for the ith known. | |
int | Knowns () const |
The number of knowns (or times AddKnown was invoked) linear combination of the variables. | |
double | GetSigma0 () |
int | GetDegreesOfFreedom () |
void | Reset () |
void | ResetSparse () |
std::vector< double > | GetEpsilons () const |
void | SetParameterWeights (const std::vector< double > weights) |
void | SetNumberOfConstrainedParameters (int n) |
Generic least square fitting class.
This class can be used to solved systems of linear equations through least squares fitting. The solution is derived through singular value decomposition or QR decomposition. For example:
\[ x + y = 3 \]
\[ -2x + 3y = 1 \]
\[ 2x - y = 2 \]
Is a simple system of equations that can be solved using this class.
Isis::LeastSquares::LeastSquares | ( | Isis::BasisFunction & | basis, |
bool | sparse = false, | ||
int | sparseRows = 0, | ||
int | sparseCols = 0, | ||
bool | jigsaw = false ) |
Creates a LeastSquares Object.
basis | A BasisFunction. This parameter allows for the least squares fitting to be applied to arbitrary equations. |
References _FILEINFO_, and Isis::IException::Programmer.
Isis::LeastSquares::~LeastSquares | ( | ) |
Destroys the LeastSquares object.
void Isis::LeastSquares::AddKnown | ( | const std::vector< double > & | data, |
double | result, | ||
double | weight = 1.0 ) |
Invoke this method for each set of knowns.
Given our example in the description, we have three knowns and expecteds. They are
\[ (1,1) = 3 \]
\[ (-2,3) = 1 \]
\[ (2,-1) = 2 \]
data | A vector of knowns. |
result | The expected value for the knowns. |
weight | (Default = 1.0) How strongly to weight this known. Weight less than 1 increases residual for this known, while weight greater than 1 decreases the residual for this known. |
Isis::IException::Programmer | - Number of elements in data does not match basis requirements |
References _FILEINFO_, Isis::BasisFunction::Name(), Isis::IException::Programmer, and Isis::BasisFunction::Variables().
Referenced by Isis::SurfaceModel::AddTriplet(), and Isis::OverlapNormalization::Solve().
double Isis::LeastSquares::Evaluate | ( | const std::vector< double > & | data | ) |
Invokes the BasisFunction Evaluate method.
data | The input variables to evaluate. |
Isis::IException::Programmer | - Unable to evaluate until a solution has been computed |
References _FILEINFO_, Isis::BasisFunction::Evaluate(), and Isis::IException::Programmer.
Referenced by Isis::SurfaceModel::Evaluate().
|
inline |
|
inline |
double Isis::LeastSquares::GetExpected | ( | int | row | ) | const |
This method returns the expected value at the given row.
row |
References _FILEINFO_, Isis::IException::Programmer, Rows(), and Isis::toString().
std::vector< double > Isis::LeastSquares::GetInput | ( | int | row | ) | const |
This method returns the data at the given row.
row |
References _FILEINFO_, Isis::IException::Programmer, Rows(), and Isis::toString().
|
inline |
|
inline |
The number of knowns (or times AddKnown was invoked) linear combination of the variables.
void Isis::LeastSquares::Reset | ( | ) |
Referenced by ResetSparse().
|
inline |
References Reset().
double Isis::LeastSquares::Residual | ( | int | i | ) | const |
Returns the ith residual.
That is, the difference between the evaluation of a known with the solution against the expected value. There is one residual for each time AddKnown was invoked.
i | The number of times AddKnown was invoked to be evaluated. |
Isis::IException::Programmer | - Unable to return residuals until a solution has been computed |
References _FILEINFO_, and Isis::IException::Programmer.
std::vector< double > Isis::LeastSquares::Residuals | ( | ) | const |
Returns a vector of residuals (errors).
That is, the difference between the evaluation of a known with the solution against the expected value.
Isis::IException::Programmer | - Unable to return residuals until a solution has been computed |
References _FILEINFO_, and Isis::IException::Programmer.
int Isis::LeastSquares::Rows | ( | ) | const |
This methods returns the number of rows in the matrix.
Referenced by GetExpected(), GetInput(), and Solve().
|
inline |
|
inline |
Referenced by Isis::OverlapNormalization::Solve().
int Isis::LeastSquares::Solve | ( | Isis::LeastSquares::SolveMethod | method = SVD | ) |
After all the data has been registered through AddKnown, invoke this method to solve the system of equations.
You can then use the Evaluate and Residual methods freely.
References _FILEINFO_, QRD, Rows(), SPARSE, SVD, and Isis::IException::Unknown.
Referenced by Isis::SurfaceModel::Solve(), and Isis::OverlapNormalization::Solve().
void Isis::LeastSquares::Weight | ( | int | index, |
double | weight ) |
Reset the weight for the ith known.
This weight will not be used unless the system is resolved using the Solve method.
index | The position in the array to assign the given weight value |
weight | A weight factor to apply to the ith known. A weight less than one increase the residual for this known while a weight greater than one decrease the residual for this known. |