MUQ  0.4.3
muq::Approximation::Regression Class Reference

#include <Regression.h>

Inheritance diagram for muq::Approximation::Regression:

Detailed Description

Definition at line 19 of file Regression.h.

Classes

class  PoisednessConstraint
 
class  PoisednessCost
 

Public Member Functions

 Regression (boost::property_tree::ptree const &pt)
 
void Fit (std::vector< Eigen::VectorXd > xs, std::vector< Eigen::VectorXd > const &ys, Eigen::VectorXd const &center)
 Compute the coeffiecents of the polynomial given data. More...
 
void Fit (std::vector< Eigen::VectorXd > const &xs, std::vector< Eigen::VectorXd > const &ys)
 Compute the coeffiecents of the polynomial given data. More...
 
int NumInterpolationPoints () const
 
std::pair< Eigen::VectorXd, double > PoisednessConstant (std::vector< Eigen::VectorXd > xs, Eigen::VectorXd const &center, int kn=-1) const
 
- Public Member Functions inherited from muq::Modeling::WorkPiece
 WorkPiece ()
 Create a muq::Modeling::WorkPiece with no fixed number of inputs and outputs and variable input/output types. More...
 
 WorkPiece (int const num, WorkPiece::Fix const fix=WorkPiece::Fix::Inputs)
 Create a muq::Modeling::WorkPiece with either a fixed number of inputs or outputs and variable input/output types. More...
 
 WorkPiece (int const numIns, int const numOuts)
 Create a muq::Modeling::WorkPiece with a fixed number of inputs and outputs but variable input/output types. More...
 
 WorkPiece (std::vector< std::string > const &types, WorkPiece::Fix const fix=WorkPiece::Fix::Inputs)
 Create a muq::Modeling::WorkPiece with either a fixed number of inputs with specified types or a fixed number of outputs with specified types. More...
 
 WorkPiece (std::map< unsigned int, std::string > const &types, WorkPiece::Fix const fix=WorkPiece::Fix::Inputs)
 Create a muq::Modeling::WorkPiece where either some of the inputs have specified types or some of the outputs have specified types. More...
 
 WorkPiece (std::map< unsigned int, std::string > const &types, int const num, WorkPiece::Fix const fixTypes=WorkPiece::Fix::Inputs, WorkPiece::Fix const fixNum=WorkPiece::Fix::Inputs)
 Create a muq::Modeling::WorkPiece where either some of the inputs have specified types or some of the outputs have specified types and either the number of inputs or the number of outputs is fixed. More...
 
 WorkPiece (std::vector< std::string > const &types, int const num)
 Create a muq::Modeling::WorkPiece with a fixed number of inputs with specified types and a fixed number of outputs (of uknown type) More...
 
 WorkPiece (int const num, std::vector< std::string > const &types)
 Create a muq::Modeling::WorkPiece with a fixed number of outputs with specified types and a fixed number of inputs (of uknown type) More...
 
 WorkPiece (std::map< unsigned int, std::string > const &inTypes, int const numIns, int const numOuts)
 Create a muq::Modeling::WorkPiece where some of the inputs are known and we know the input and output numbers. More...
 
 WorkPiece (int const numIns, std::map< unsigned int, std::string > const &outTypes, int const numOuts)
 Create a muq::Modeling::WorkPiece where some of the outputs are known and we know the input and output numbers. More...
 
 WorkPiece (std::vector< std::string > const &inTypes, std::vector< std::string > const &outTypes)
 Create a muq::Modeling::WorkPiece with a fixed number of inputs and outputs with specified types. More...
 
 WorkPiece (std::map< unsigned int, std::string > const &inTypes, std::vector< std::string > const &outTypes)
 Create a muq::Modeling::WorkPiece where some of the inputs are known and all of the outputs have specified types. More...
 
 WorkPiece (std::map< unsigned int, std::string > const &inTypes, int const num, std::vector< std::string > const &outTypes)
 Create a muq::Modeling::WorkPiece where some of the inputs are known with a known number of inputs and all of the outputs have specified types. More...
 
 WorkPiece (std::vector< std::string > const &inTypes, std::map< unsigned int, std::string > const &outTypes)
 Create a muq::Modeling::WorkPiece where some of the outputs and all of the inputs have specified types. More...
 
 WorkPiece (std::vector< std::string > const &inTypes, std::map< unsigned int, std::string > const &outTypes, int const num)
 Create a muq::Modeling::WorkPiece where some of the outputs with a known number of outputs and all of the inputs have specified types. More...
 
 WorkPiece (std::map< unsigned int, std::string > const &inTypes, std::map< unsigned int, std::string > const &outTypes)
 Create a muq::Mdoeling::WorkPiece where some of the inputs and some of the outputs have specified types. More...
 
 WorkPiece (std::map< unsigned int, std::string > const &inTypes, int const numIn, std::map< unsigned int, std::string > const &outTypes)
 Create a muq::Mdoeling::WorkPiece where some of the inputs and some of the outputs have specified types with a fixed number of inputs. More...
 
 WorkPiece (std::map< unsigned int, std::string > const &inTypes, std::map< unsigned int, std::string > const &outTypes, int const numOut)
 Create a muq::Mdoeling::WorkPiece where some of the inputs and some of the outputs have specified types with a fixed number of outputs. More...
 
 WorkPiece (std::map< unsigned int, std::string > const &inTypes, int const numIn, std::map< unsigned int, std::string > const &outTypes, int const numOut)
 Create a muq::Mdoeling::WorkPiece where some of the inputs and some of the outputs have specified types with a fixed number of inputs and outputs. More...
 
virtual ~WorkPiece ()
 Default destructor. More...
 
std::vector< boost::any > const & Evaluate (std::vector< boost::any > const &ins)
 Evaluate this muq::Modeling::WorkPiece. More...
 
std::vector< boost::any > const & Evaluate (ref_vector< boost::any > const &ins)
 Evaluate this muq::Modeling::WorkPiece using references to the inputs. More...
 
std::vector< boost::any > const & Evaluate ()
 Evaluate this muq::Modeling::WorkPiece in the case that there are no inputs. More...
 
template<typename... Args>
std::vector< boost::any > const & Evaluate (Args... args)
 Evalaute this muq::Modeling::WorkPiece using multiple arguments. More...
 
std::string const & Name ()
 Get the (unique) name of this work piece. More...
 
void SetName (std::string const &newName)
 Set the name of this work piece. More...
 
std::string InputType (unsigned int inputNum, bool const demangle=true) const
 Get the input type (if we know it) for a specific input. More...
 
int InputSize (unsigned int inputNum) const
 Get the length of a vector valued input with fixed size. More...
 
void SetInputSize (unsigned int inputNum, int newSize)
 
std::string OutputType (unsigned int outputNum, bool const demangle=true) const
 Get the output type (if we know it) for a specific output. More...
 
std::map< unsigned int, std::string > OutputTypes () const
 Get the output types. More...
 
std::map< unsigned int, std::string > InputTypes () const
 Get the input types. More...
 
unsigned int ID () const
 Get the unique ID number. More...
 
virtual double GetRunTime (const std::string &method="Evaluate") const
 Get the average run time for one of the implemented methods. More...
 
virtual unsigned long int GetNumCalls (const std::string &method="Evaluate") const
 get the number of times one of the implemented methods has been called. More...
 
virtual void ResetCallTime ()
 Resets the number of call and times. More...
 

Public Attributes

const unsigned int order
 The order of the regression. More...
 
- Public Attributes inherited from muq::Modeling::WorkPiece
int numInputs
 The number of inputs. More...
 
int numOutputs
 The number of outputs. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from muq::Modeling::WorkPiece
static ref_vector< const boost::any > ToRefVector (std::vector< boost::any > const &anyVec)
 Create vector of references from a vector of boost::any's. More...
 
static ref_vector< const Eigen::VectorXd > ToRefVector (std::vector< Eigen::VectorXd > const &anyVec)
 

Constructor & Destructor Documentation

◆ Regression()

Regression::Regression ( boost::property_tree::ptree const &  pt)
  1. order The order of the polynomial regression (Order)
  2. The type of polynomial basis to use (defaults to Legendre) (PolynomialBasis)
Parameters
[in]ptOptions for the regression

Definition at line 18 of file Regression.cpp.

References alpha, muq::Approximation::IndexedScalarBasis::Construct(), inputDim, multi, optPt, order, and poly.

Member Function Documentation

◆ CenterPoints() [1/3]

Eigen::ArrayXd Regression::CenterPoints ( std::vector< Eigen::VectorXd > &  xs)
private

Center the input points.

Center the input points around currentCenter

Parameters
[in]xsInput points

Definition at line 216 of file Regression.cpp.

References currentCenter, and currentRadius.

Referenced by CenterPoints(), Fit(), and PoisednessConstant().

◆ CenterPoints() [2/3]

Eigen::ArrayXd Regression::CenterPoints ( std::vector< Eigen::VectorXd > &  xs,
Eigen::VectorXd const &  center 
) const
private

Center the input points.

Parameters
[in]xsInput points
[in]centerThe center point

Definition at line 189 of file Regression.cpp.

References CenterPoints().

◆ CenterPoints() [3/3]

Eigen::ArrayXd Regression::CenterPoints ( std::vector< Eigen::VectorXd > &  xs,
Eigen::VectorXd const &  center,
unsigned int const  kn 
) const
private

Center the input points.

Center the input points such that the first \(k_n\) of them are in a unit ball (the rest may be inside or outside, depending on the their magnitude.)

Parameters
[in]xsInput points
[in]centerThe center point
[in]knThe first \(kn\) points are in the unit ball

Definition at line 193 of file Regression.cpp.

◆ ComputeBasisDerivatives()

void Regression::ComputeBasisDerivatives ( Eigen::VectorXd const &  point,
std::vector< Eigen::VectorXd > &  gradient 
) const
private

Definition at line 263 of file Regression.cpp.

References inputDim, multi, poly, and nlohmann::detail::dtoa_impl::v.

◆ ComputeCoefficients()

Eigen::MatrixXd Regression::ComputeCoefficients ( std::vector< Eigen::VectorXd > const &  xs,
std::vector< Eigen::VectorXd > const &  ys 
) const
private

Compute the coefficients for the basis functions.

Given points, data, and a center compute the coefficients on the basis (inner product with the basis evalautes the local polynomial). The data can be a have multiple outputs (e.g., fitting more than one polynomial at once), which leads to more than one set of basis coefficents.

Parameters
[in]xsThe points
[in]ysThe output at each point
Returns
The coefficients for the basis

Definition at line 117 of file Regression.cpp.

References ComputeCoefficientsRHS(), NumInterpolationPoints(), and VandermondeMatrix().

Referenced by Fit(), and PoisednessConstant().

◆ ComputeCoefficientsRHS()

Eigen::MatrixXd Regression::ComputeCoefficientsRHS ( Eigen::MatrixXd const &  vand,
std::vector< Eigen::VectorXd > const &  ys_data 
) const
private

Compute the right hand side given data to compute the polynomial coefficients.

Parameters
[in]vandThe Vandermonde matrix
[in]ys_dataThe output at each point

Definition at line 140 of file Regression.cpp.

Referenced by ComputeCoefficients().

◆ EvaluateImpl()

void Regression::EvaluateImpl ( muq::Modeling::ref_vector< boost::any > const &  inputs)
overrideprivatevirtual

User-implemented function that determines the behavior of this muq::Modeling::WorkPiece.

This function determines how the WorkPiece::inputs determine WorkPiece::outputs. Must be implemented by a child.

WorkPiece::Evaluate() calls this function after checking the inputs and storing them in WorkPiece::inputs. This function populates WorkPiece::outputs, the outputs of this muq::Modeling::WorkPiece. WorkPiece::Evaluate() checks the outputs after calling this function.

Implements muq::Modeling::WorkPiece.

Definition at line 61 of file Regression.cpp.

References coeff, currentCenter, currentRadius, multi, muq::Modeling::WorkPiece::outputs, and VandermondeMatrix().

◆ Fit() [1/2]

void Regression::Fit ( std::vector< Eigen::VectorXd > const &  xs,
std::vector< Eigen::VectorXd > const &  ys 
)

Compute the coeffiecents of the polynomial given data.

Parameters
[in]xsThe input points
[in]ysThe output points

Definition at line 109 of file Regression.cpp.

References Fit().

◆ Fit() [2/2]

void Regression::Fit ( std::vector< Eigen::VectorXd >  xs,
std::vector< Eigen::VectorXd > const &  ys,
Eigen::VectorXd const &  center 
)

Compute the coeffiecents of the polynomial given data.

Parameters
[in]xsThe input points
[in]ysThe output points
[in]centerThe center of the inputs (used to recenter the inputs)

Definition at line 95 of file Regression.cpp.

References CenterPoints(), coeff, ComputeCoefficients(), and currentCenter.

Referenced by Fit().

◆ NumInterpolationPoints()

int Regression::NumInterpolationPoints ( ) const

Definition at line 83 of file Regression.cpp.

References multi.

Referenced by ComputeCoefficients().

◆ PoisednessConstant()

std::pair< Eigen::VectorXd, double > Regression::PoisednessConstant ( std::vector< Eigen::VectorXd >  xs,
Eigen::VectorXd const &  center,
int  kn = -1 
) const
Parameters
[in]xsThe input points in the ball (not necessarily normalized to the unit ball)
[in]centerThe center of the ball
[in]knMaximize the Lagrange polynomials in the smallest ball containing this number of points. If \(k_n<0\) (default) use the smallest ball that contains all of the points. It may not be zero.
Returns
A tuple: poisedness constant, radius, index of input point associated with the poisedness consant, the location that maximizes the Lagrange polynomial.

Definition at line 222 of file Regression.cpp.

References alpha, CenterPoints(), ComputeCoefficients(), inputDim, and optPt.

◆ VandermondeMatrix()

Eigen::MatrixXd Regression::VandermondeMatrix ( std::vector< Eigen::VectorXd > const &  xs) const
private

Create the Vandermonde matrix.

Parameters
[in]xsThe points
Returns
The Vandermonde matrix

Definition at line 157 of file Regression.cpp.

References alpha, multi, poly, and nlohmann::detail::dtoa_impl::v.

Referenced by ComputeCoefficients(), and EvaluateImpl().

Member Data Documentation

◆ alpha

const double muq::Approximation::Regression::alpha
private

The radius of the poisedness constraint.

Defaults to 1. Max is 1.

Definition at line 154 of file Regression.h.

Referenced by muq::Approximation::Regression::PoisednessConstraint::EvaluateImpl(), PoisednessConstant(), Regression(), and VandermondeMatrix().

◆ coeff

Eigen::MatrixXd muq::Approximation::Regression::coeff
private

Coeffients for the polynomial basis.

Definition at line 169 of file Regression.h.

Referenced by EvaluateImpl(), and Fit().

◆ currentCenter

Eigen::VectorXd muq::Approximation::Regression::currentCenter
private

Current center of the inputs.

Definition at line 163 of file Regression.h.

Referenced by CenterPoints(), EvaluateImpl(), and Fit().

◆ currentRadius

Eigen::ArrayXd muq::Approximation::Regression::currentRadius
private

Current radius of inputs.

Definition at line 166 of file Regression.h.

Referenced by CenterPoints(), and EvaluateImpl().

◆ inputDim

const unsigned int muq::Approximation::Regression::inputDim
private

The input dimension.

Definition at line 148 of file Regression.h.

Referenced by ComputeBasisDerivatives(), PoisednessConstant(), and Regression().

◆ multi

std::shared_ptr<muq::Utilities::MultiIndexSet> muq::Approximation::Regression::multi
private

The multi-index to so we know the order of each term.

Definition at line 157 of file Regression.h.

Referenced by ComputeBasisDerivatives(), EvaluateImpl(), NumInterpolationPoints(), Regression(), and VandermondeMatrix().

◆ optPt

boost::property_tree::ptree muq::Approximation::Regression::optPt
private

Parameters for the poisedness cosntant optimization.

Definition at line 172 of file Regression.h.

Referenced by PoisednessConstant(), and Regression().

◆ order

const unsigned int muq::Approximation::Regression::order

The order of the regression.

Definition at line 57 of file Regression.h.

Referenced by Regression().

◆ poly

std::shared_ptr<IndexedScalarBasis> muq::Approximation::Regression::poly
private

The polynomial basis (in one variable) used to compute the Vandermonde matrix.

Definition at line 160 of file Regression.h.

Referenced by ComputeBasisDerivatives(), Regression(), and VandermondeMatrix().


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