gramods
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
gramods::gmMisc::PolyFit Class Reference

This is a polygonal fitter for any number of in- and output dimensions allowing for inter- and extrapolation. More...

#include <PolyFit.hh>

Classes

struct  Impl
 

Public Types

typedef Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > polco
 Matrix holding the polynomial coefficients, one row for each output dimension.
 

Public Member Functions

 PolyFit (size_t idim, size_t odim, size_t ord)
 Creates a PolyFit instance for the specified number of input and output dimensions, and polynomial order.
 
 PolyFit (const std::vector< std::vector< double > > &invals, const std::vector< std::vector< double > > &outvals, size_t ord)
 Creates a PolyFit instance and adds the specified sample values.
 
void addSample (const std::vector< double > &inval, const std::vector< double > &outval)
 Add a sample specifying the relation between input and output values.
 
polco estimateCoefficients () const
 Estimate and return the coefficients of the polynomial that best fits the data.
 
std::vector< double > getValue (const std::vector< double > &inval) const
 Estimates the polynomial result from the specified input.
 
Eigen::MatrixXd getJacobian (const std::vector< double > &in_values) const
 Estimates the polynomial Jacobian from the specified input.
 
double getSingle (double inval) const
 Convenience method for 1D polynomials.
 
double getDerivative (double inval) const
 Estimates the polynomial derivative from the specified input for 1D polynomials.
 
void clear ()
 Resets the contents of this object.
 

Detailed Description

This is a polygonal fitter for any number of in- and output dimensions allowing for inter- and extrapolation.

Member Typedef Documentation

◆ polco

typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> gramods::gmMisc::PolyFit::polco

Matrix holding the polynomial coefficients, one row for each output dimension.

Constructor & Destructor Documentation

◆ PolyFit() [1/2]

gramods::gmMisc::PolyFit::PolyFit ( size_t  idim,
size_t  odim,
size_t  ord 
)

Creates a PolyFit instance for the specified number of input and output dimensions, and polynomial order.

Parameters
[in]idimInput dimensionality.
[in]odimOutput dimensionality.
[in]ordOrder of the polynomial.

◆ PolyFit() [2/2]

gramods::gmMisc::PolyFit::PolyFit ( const std::vector< std::vector< double > > &  invals,
const std::vector< std::vector< double > > &  outvals,
size_t  ord 
)

Creates a PolyFit instance and adds the specified sample values.

Member Function Documentation

◆ addSample()

void gramods::gmMisc::PolyFit::addSample ( const std::vector< double > &  inval,
const std::vector< double > &  outval 
)

Add a sample specifying the relation between input and output values.

The dimensions must match the dimensionality of the object or exception will be thrown.

Parameters
[in]invalThe parameter value that should give rise to the specified output value.
[in]outvalThe output value for the specified inval.

◆ clear()

void gramods::gmMisc::PolyFit::clear ( )

Resets the contents of this object.

◆ estimateCoefficients()

PolyFit::polco gramods::gmMisc::PolyFit::estimateCoefficients ( ) const

Estimate and return the coefficients of the polynomial that best fits the data.

The order for these components matches the recursive expansion of [ 1, x, x², ... ] × [ 1, y, y², ... ] × ... into [ 1, x, x², ..., yx, yx², ..., y²x, y²x², ... ] (column wise) for each output (row wise).

This method will cache the coefficients until new samples have been added.

◆ getDerivative()

double gramods::gmMisc::PolyFit::getDerivative ( double  inval) const

Estimates the polynomial derivative from the specified input for 1D polynomials.

This method calls estimateCoefficients (if necessary) and calculates the resulting polynomial with the specified input.

◆ getJacobian()

Eigen::MatrixXd gramods::gmMisc::PolyFit::getJacobian ( const std::vector< double > &  in_values) const

Estimates the polynomial Jacobian from the specified input.

This method calls estimateCoefficients (if necessary) and calculates the Jacobian of the polynomial with the specified input. For n input variables, x₀ to xₙ, and m output variables, y₀ to yₘ, the returned matrix follows the convention

\[
\left(
  \begin{array}{cccc}
    \frac{\partial y_0}{\partial x_0} & \frac{\partial y_0}{\partial x_1} & \dots & \frac{\partial y_0}{\partial x_n} \\
    \frac{\partial y_1}{\partial x_0} & \frac{\partial y_1}{\partial x_1} & \dots & \frac{\partial y_1}{\partial x_n} \\
    \vdots \\
    \frac{\partial y_m}{\partial x_0} & \frac{\partial y_m}{\partial x_1} & \dots & \frac{\partial y_m}{\partial x_n}
  \end{array}
\right)
\]

The dimensions of the input must match the dimensionality of the object or exception will be thrown.

◆ getSingle()

double gramods::gmMisc::PolyFit::getSingle ( double  inval) const

Convenience method for 1D polynomials.

See also
getValue(const std::vector<double>&)

◆ getValue()

std::vector< double > gramods::gmMisc::PolyFit::getValue ( const std::vector< double > &  inval) const

Estimates the polynomial result from the specified input.

This method calls estimateCoefficients (if necessary) and calculates the resulting polynomial with the specified input. This method can be used both for inter- and extrapolation.

The dimensions of the input must match the dimensionality of the object or exception will be thrown.


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