Isis 3 Programmer Reference
Isis::BasisFunction Class Reference

Generic linear equation class. More...

#include <BasisFunction.h>

Inheritance diagram for Isis::BasisFunction:
Inheritance graph
Collaboration diagram for Isis::BasisFunction:
Collaboration graph

Public Member Functions

 BasisFunction (const QString &name, int numVars, int numCoefs)
 Creates a BasisFunction object. More...
 
virtual ~BasisFunction ()
 Destroys the BasisFunction object. More...
 
void SetCoefficients (const std::vector< double > &coefs)
 Set the coefficients for the equation. More...
 
double Evaluate (const std::vector< double > &vars)
 Compute the equation using the input variables. More...
 
double Evaluate (const double &var)
 Compute the equation using the input variable. More...
 
virtual void Expand (const std::vector< double > &vars)
 This is the function you should replace depending on your needs. More...
 
int Coefficients () const
 Returns the number of coefficients for the equation. More...
 
int Variables () const
 Returns the number of variables in the equation. More...
 
QString Name () const
 Returns the name of the equation. More...
 
double Term (int c) const
 Returns the cth term. More...
 
double Coefficient (int i) const
 Returns the ith coefficient. More...
 

Protected Attributes

QString p_name
 The name of the equation. Call it by using Name() More...
 
int p_numVars
 The number of variables in the equation. Call it by using Variables() More...
 
int p_numCoefs
 The number of coefficients in the equation. More...
 
std::vector< double > p_coefs
 A vector of the coefficients in the equation. More...
 
std::vector< double > p_terms
 A vector of the terms in the equation. More...
 

Detailed Description

Generic linear equation class.

This is a base class for generating "generic" equations for the Isis least squares fitting algorithm (IsisLSQ). It allows the programmer to set up equations in the form of:

\[ x = C1*T1 + C2*T2 + ... + CN*TN; \]

where C1-CN are coefficients and T1-TN are terms. Note that terms can be comprised of multiple variables and/or functions. For example,

\[ x = C1 + C2*y + C3*y**2; \]

\[ x = C1 + C2*y + C3*z + C4*y*z; \]

By deriving different functions off of this base class this allows the least squares class to be generalized.

Author
2004-06-24 Jeff Anderson
Todo:
Add coded example
History:

2005-03-16 Leah Dahmer - modified file to support Doxygen documentation.

2015-02-20 Jeannie Backer - Improved error messages.

2016-06-10 Marjorie Hahn - Added new signature for Evaluate() that only takes in a single value. Fixes #1679

Definition at line 64 of file BasisFunction.h.

Constructor & Destructor Documentation

◆ BasisFunction()

Isis::BasisFunction::BasisFunction ( const QString &  name,
int  numVars,
int  numCoefs 
)

Creates a BasisFunction object.

Parameters
nameName of the BasisFunction. For example, "affine".
numVarsNumber of variables in the equation. For example:

\[ x = C1 + C2*y + C3*z \]

has two variables: y and z.
numCoefsNumber of coefficients in the equation. For example:

\[ x = C1 + C2*y + C3*z \]

has three coefficients: C1, C2 & C3.

Definition at line 45 of file BasisFunction.cpp.

References p_name, p_numCoefs, and p_numVars.

◆ ~BasisFunction()

virtual Isis::BasisFunction::~BasisFunction ( )
inlinevirtual

Destroys the BasisFunction object.

Definition at line 68 of file BasisFunction.h.

Member Function Documentation

◆ Coefficient()

double Isis::BasisFunction::Coefficient ( int  i) const
inline

Returns the ith coefficient.

Parameters
iThe index for the desired coefficient.
Returns
The ith coefficient

Definition at line 123 of file BasisFunction.h.

References p_coefs.

Referenced by Isis::PolynomialUnivariate::DerivativeVar(), Isis::SpicePosition::LoadHermiteCache(), Isis::SurfaceModel::MinMax(), Isis::SpicePosition::SetPolynomial(), Isis::SpiceRotation::SetPolynomial(), and Isis::Affine::Solve().

◆ Coefficients()

int Isis::BasisFunction::Coefficients ( ) const
inline

◆ Evaluate() [1/2]

double Isis::BasisFunction::Evaluate ( const std::vector< double > &  vars)

Compute the equation using the input variables.

Parameters
varsA vector of double values to use for the equation. After setting the coefficients, this can be invoked many times to compute output values given input values.
Returns
The output value.

Definition at line 80 of file BasisFunction.cpp.

References _FILEINFO_, Expand(), p_coefs, p_numCoefs, p_numVars, p_terms, Isis::IException::Programmer, and Isis::toString().

Referenced by Evaluate(), Isis::LeastSquares::Evaluate(), Isis::SpiceRotation::EvaluatePolyFunction(), Isis::SpicePosition::LoadHermiteCache(), Isis::SpicePosition::SetEphemerisTimePolyFunction(), Isis::SpiceRotation::setEphemerisTimePolyFunction(), Isis::LeastSquares::SolveQRD(), and Isis::LeastSquares::SolveSVD().

◆ Evaluate() [2/2]

double Isis::BasisFunction::Evaluate ( const double &  var)

Compute the equation using the input variable.

Parameters
varA single double value to use for the equation.
Returns
The output double value resulting from the equation.

Definition at line 117 of file BasisFunction.cpp.

References Evaluate().

◆ Expand()

void Isis::BasisFunction::Expand ( const std::vector< double > &  vars)
virtual

This is the function you should replace depending on your needs.

It will expand the variables into the terms of the equation. For example,

\[ x = C1 + C2*y + C3*z + C4*y*z \]

must be expanded into the p_terms vector as (1.0, y, z, y*z). Note that the term expansion is not limited, you can use cos, sin, sqrt, abs, etc. This virtual method is automatically invoked by the Evaluate method. We provide a default expansion of p_terms = vars, just a linear combination of the variables.

Parameters
varsA vector of double values to use for the expansion.

Reimplemented in Isis::PolynomialUnivariate, and Isis::PolynomialBivariate.

Definition at line 139 of file BasisFunction.cpp.

References p_terms.

Referenced by Evaluate(), Isis::LeastSquares::FillSparseA(), Isis::LeastSquares::SolveQRD(), and Isis::LeastSquares::SolveSVD().

◆ Name()

QString Isis::BasisFunction::Name ( ) const
inline

Returns the name of the equation.

Returns
The name of the equation.

Definition at line 96 of file BasisFunction.h.

References p_name.

Referenced by Isis::LeastSquares::AddKnown().

◆ SetCoefficients()

◆ Term()

double Isis::BasisFunction::Term ( int  c) const
inline

Returns the cth term.

This is only valid after a Evalute/Expand has been invoked. It represents the expansion of the variables into the ith term. For example,

\[ x = C1 + C2*x + C3*y + C4*x*y \]

would return x*y for the 3rd term (zero-based)

Parameters
cThe index for the desired coefficient.
Returns
The cth term.

Definition at line 113 of file BasisFunction.h.

References p_terms.

Referenced by Isis::LeastSquares::FillSparseA(), Isis::LeastSquares::SolveQRD(), and Isis::LeastSquares::SolveSVD().

◆ Variables()

int Isis::BasisFunction::Variables ( ) const
inline

Returns the number of variables in the equation.

Returns
The number of variables.

Definition at line 88 of file BasisFunction.h.

References p_numVars.

Referenced by Isis::LeastSquares::AddKnown().

Member Data Documentation

◆ p_coefs

std::vector<double> Isis::BasisFunction::p_coefs
protected

A vector of the coefficients in the equation.

Call it by using Coefficient()

Definition at line 139 of file BasisFunction.h.

Referenced by Coefficient(), Evaluate(), and SetCoefficients().

◆ p_name

QString Isis::BasisFunction::p_name
protected

The name of the equation. Call it by using Name()

Definition at line 125 of file BasisFunction.h.

Referenced by BasisFunction(), and Name().

◆ p_numCoefs

int Isis::BasisFunction::p_numCoefs
protected

The number of coefficients in the equation.

Call it by using Coefficients()

Definition at line 135 of file BasisFunction.h.

Referenced by BasisFunction(), Coefficients(), Evaluate(), and SetCoefficients().

◆ p_numVars

int Isis::BasisFunction::p_numVars
protected

The number of variables in the equation. Call it by using Variables()

Definition at line 131 of file BasisFunction.h.

Referenced by BasisFunction(), Evaluate(), and Variables().

◆ p_terms

std::vector<double> Isis::BasisFunction::p_terms
protected

A vector of the terms in the equation.

Call it by using Term()

Definition at line 143 of file BasisFunction.h.

Referenced by Evaluate(), Isis::PolynomialBivariate::Expand(), Isis::PolynomialUnivariate::Expand(), Expand(), and Term().


The documentation for this class was generated from the following files: