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. More... | |
~LeastSquares () | |
Destroys the LeastSquares object. More... | |
void | AddKnown (const std::vector< double > &input, double expected, double weight=1.0) |
Invoke this method for each set of knowns. More... | |
std::vector< double > | GetInput (int row) const |
This method returns the data at the given row. More... | |
double | GetExpected (int row) const |
This method returns the expected value at the given row. More... | |
int | Rows () const |
This methods returns the number of rows in the matrix. More... | |
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. More... | |
double | Evaluate (const std::vector< double > &input) |
Invokes the BasisFunction Evaluate method. More... | |
std::vector< double > | Residuals () const |
Returns a vector of residuals (errors). More... | |
double | Residual (int i) const |
Returns the ith residual. More... | |
void | Weight (int index, double weight) |
Reset the weight for the ith known. More... | |
int | Knowns () const |
The number of knowns (or times AddKnown was invoked) linear combination of the variables. More... | |
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(), Isis::ReseauDistortionMap::SetFocalPlane(), Isis::VimsGroundMap::SetGround(), Isis::SpicePosition::SetPolynomial(), Isis::SpiceRotation::SetPolynomial(), Isis::VimsSkyMap::SetSky(), Isis::ReseauDistortionMap::SetUndistortedFocalPlane(), and Isis::Affine::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(), Isis::ReseauDistortionMap::SetFocalPlane(), Isis::VimsGroundMap::SetGround(), Isis::VimsSkyMap::SetSky(), and Isis::ReseauDistortionMap::SetUndistortedFocalPlane().
|
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.
Referenced by Isis::VimsGroundMap::SetGround(), and Isis::VimsSkyMap::SetSky().
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 |
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::ReseauDistortionMap::SetFocalPlane(), Isis::VimsGroundMap::SetGround(), Isis::SpicePosition::SetPolynomial(), Isis::SpiceRotation::SetPolynomial(), Isis::VimsSkyMap::SetSky(), Isis::ReseauDistortionMap::SetUndistortedFocalPlane(), Isis::SurfaceModel::Solve(), and Isis::Affine::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. |