MUQ  0.4.3
muq::Approximation::LocalRegression Class Reference

#include <LocalRegression.h>

Inheritance diagram for muq::Approximation::LocalRegression:

Detailed Description

Definition at line 17 of file LocalRegression.h.

Public Member Functions

 LocalRegression (std::shared_ptr< muq::Modeling::ModPiece > function, boost::property_tree::ptree &pt)
 
 LocalRegression (std::shared_ptr< muq::Modeling::ModPiece > function, boost::property_tree::ptree &pt, std::shared_ptr< parcer::Communicator > comm)
 
 ~LocalRegression ()
 
 ~LocalRegression ()=default
 
void Add (std::vector< Eigen::VectorXd > const &inputs) const
 Add some points to the cache. More...
 
Eigen::VectorXd Add (Eigen::VectorXd const &input) const
 Add a single point to the cache. More...
 
unsigned int CacheSize () const
 Get the total size of the cache. More...
 
bool InCache (Eigen::VectorXd const &point) const
 Is a point in the cache? More...
 
Eigen::VectorXd CachePoint (unsigned int const index) const
 A point in the cache. More...
 
std::tuple< Eigen::VectorXd, double, unsigned int > PoisednessConstant (Eigen::VectorXd const &input) const
 Get the poisedness constant. More...
 
std::tuple< Eigen::VectorXd, double, unsigned int > PoisednessConstant (Eigen::VectorXd const &input, std::vector< Eigen::VectorXd > const &neighbors) const
 Get the poisedness constant. More...
 
std::pair< double, double > ErrorIndicator (Eigen::VectorXd const &input) const
 Get the error indicator. More...
 
std::pair< double, double > ErrorIndicator (Eigen::VectorXd const &input, std::vector< Eigen::VectorXd > const &neighbors) const
 Get the error indicator. More...
 
void NearestNeighbors (Eigen::VectorXd const &input, std::vector< Eigen::VectorXd > &neighbors) const
 Get the number of nearest neighbors. More...
 
void NearestNeighbors (Eigen::VectorXd const &input, std::vector< Eigen::VectorXd > &neighbors, std::vector< Eigen::VectorXd > &result) const
 Get the number of nearest neighbors (with result) More...
 
Eigen::VectorXd EvaluateRegressor (Eigen::VectorXd const &input, std::vector< Eigen::VectorXd > const &neighbors, std::vector< Eigen::VectorXd > const &result) const
 
void Probe () const
 
Eigen::VectorXd CacheCentroid () const
 Get the centroid of the cache. More...
 
void ClearCache ()
 Clear the cache. More...
 
unsigned int Order () const
 Polynomial order. More...
 
- Public Member Functions inherited from muq::Modeling::ModPiece
 ModPiece (std::vector< int > const &inputSizes, std::vector< int > const &outputSizes)
 
 ModPiece (Eigen::VectorXi const &inputSizes, Eigen::VectorXi const &outputSizes)
 
virtual ~ModPiece ()=default
 
virtual double GetRunTime (const std::string &method="Evaluate") const override
 Get the average run time for one of the implemented methods. More...
 
virtual void ResetCallTime () override
 Resets the number of call and times. More...
 
virtual unsigned long int GetNumCalls (const std::string &method="Evaluate") const override
 get the number of times one of the implemented methods has been called. More...
 
virtual std::vector< Eigen::VectorXd > const & Evaluate (std::vector< Eigen::VectorXd > const &input)
 Evaluate the ModPiece. More...
 
virtual std::vector< Eigen::VectorXd > const & Evaluate (ref_vector< Eigen::VectorXd > const &input)
 
 VARIADIC_TO_REFVECTOR (Evaluate, Eigen::VectorXd, std::vector< Eigen::VectorXd > const &)
 
virtual Eigen::VectorXd const & Gradient (unsigned int const outputDimWrt, unsigned int const inputDimWrt, std::vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sensitivity)
 Compute the Gradient \(J^Tv\). More...
 
virtual Eigen::VectorXd const & Gradient (unsigned int const outputDimWrt, unsigned int const inputDimWrt, ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sensitivity)
 
Eigen::VectorXd const & Gradient (unsigned int outWrt, unsigned int inWrt, Eigen::VectorXd const &last, Eigen::VectorXd const &sens)
 
template<typename... Args>
Eigen::VectorXd const & Gradient (unsigned int wrtOut, unsigned int wrtIn, Args const &... args)
 
Eigen::VectorXd const & ApplyHessian (unsigned int outWrt, unsigned int inWrt1, unsigned int inWrt2, Eigen::VectorXd const &last, Eigen::VectorXd const &sens, Eigen::VectorXd const &vec)
 
template<typename... Args>
Eigen::VectorXd const & ApplyHessian (unsigned int wrtOut, unsigned int wrtIn1, unsigned int wrtIn2, Args const &... args)
 
virtual Eigen::MatrixXd const & Jacobian (unsigned int const outputDimWrt, unsigned int const inputDimWrt, std::vector< Eigen::VectorXd > const &input)
 Compute the Jacobian of this ModPiece. More...
 
virtual Eigen::MatrixXd const & Jacobian (unsigned int const outputDimWrt, unsigned int const inputDimWrt, ref_vector< Eigen::VectorXd > const &input)
 
template<typename... Args>
Eigen::MatrixXd const & Jacobian (unsigned int outWrt, unsigned int inWrt, Args const &... args)
 
template<typename... Args>
Eigen::MatrixXd JacobianByFD (unsigned int outWrt, unsigned int inWrt, Args const &... args)
 
template<typename... Args>
Eigen::MatrixXd ApplyJacobianByFD (unsigned int outWrt, unsigned int inWrt, Args const &... args)
 
virtual Eigen::VectorXd const & ApplyJacobian (unsigned int const outputDimWrt, unsigned int const inputDimWrt, std::vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &vec)
 Apply the Jacobian of this ModPiece to a vector. More...
 
virtual Eigen::VectorXd const & ApplyJacobian (unsigned int const outputDimWrt, unsigned int const inputDimWrt, ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &vec)
 
Eigen::VectorXd const & ApplyJacobian (unsigned int outWrt, unsigned int inWrt, Eigen::VectorXd const &last, Eigen::VectorXd const &sens)
 
template<typename... Args>
Eigen::VectorXd const & ApplyJacobian (unsigned int wrtOut, unsigned int wrtIn, Args const &... args)
 
virtual Eigen::VectorXd GradientByFD (unsigned int const outputDimWrt, unsigned int const inputDimWrt, std::vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sensitivity)
 
virtual Eigen::VectorXd GradientByFD (unsigned int const outputDimWrt, unsigned int const inputDimWrt, ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sensitivity)
 
virtual Eigen::MatrixXd JacobianByFD (unsigned int const outputDimWrt, unsigned int const inputDimWrt, std::vector< Eigen::VectorXd > const &input)
 
virtual Eigen::MatrixXd JacobianByFD (unsigned int const outputDimWrt, unsigned int const inputDimWrt, ref_vector< Eigen::VectorXd > const &input)
 
virtual Eigen::VectorXd ApplyJacobianByFD (unsigned int const outputDimWrt, unsigned int const inputDimWrt, std::vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &vec)
 
virtual Eigen::VectorXd ApplyJacobianByFD (unsigned int const outputDimWrt, unsigned int const inputDimWrt, ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &vec)
 
virtual Eigen::VectorXd const & ApplyHessian (unsigned int const outWrt, unsigned int const inWrt1, unsigned int const inWrt2, std::vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sens, Eigen::VectorXd const &vec)
 
virtual Eigen::VectorXd const & ApplyHessian (unsigned int const outWrt, unsigned int const inWrt1, unsigned int const inWrt2, ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sens, Eigen::VectorXd const &vec)
 
virtual Eigen::VectorXd ApplyHessianByFD (unsigned int const outWrt, unsigned int const inWrt1, unsigned int const inWrt2, std::vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sens, Eigen::VectorXd const &vec)
 
virtual Eigen::VectorXd ApplyHessianByFD (unsigned int const outWrt, unsigned int const inWrt1, unsigned int const inWrt2, ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sens, Eigen::VectorXd const &vec)
 
void EnableCache ()
 
void DisableCache ()
 
bool CacheStatus () const
 
virtual void SetWarnLevel (unsigned int newLevel)
 
- 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...
 

Public Attributes

const unsigned int kn
 The number of nearest neighbors to use by the regressor. More...
 
- Public Attributes inherited from muq::Modeling::ModPiece
const Eigen::VectorXi inputSizes
 
const Eigen::VectorXi outputSizes
 
- 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

◆ LocalRegression() [1/2]

muq::Approximation::LocalRegression::LocalRegression ( std::shared_ptr< muq::Modeling::ModPiece function,
boost::property_tree::ptree &  pt 
)
Parameters
[in]functionThe function we wish to approximate with a local polynomial
[in]ptOptions for the regression

◆ LocalRegression() [2/2]

LocalRegression::LocalRegression ( std::shared_ptr< muq::Modeling::ModPiece function,
boost::property_tree::ptree &  pt,
std::shared_ptr< parcer::Communicator >  comm 
)
Parameters
[in]functionThe function we wish to approximate with a local polynomial
[in]ptOptions for the regression
[in]commThe parcer communicator

Definition at line 16 of file LocalRegression.cpp.

References SetUp().

◆ ~LocalRegression() [1/2]

LocalRegression::~LocalRegression ( )

Definition at line 20 of file LocalRegression.cpp.

References comm, and Probe().

◆ ~LocalRegression() [2/2]

muq::Approximation::LocalRegression::~LocalRegression ( )
default

Member Function Documentation

◆ Add() [1/2]

Eigen::VectorXd LocalRegression::Add ( Eigen::VectorXd const &  input) const

Add a single point to the cache.

Parameters
[in]inputPoint to add to the cache
Returns
The function result at the new point

Definition at line 90 of file LocalRegression.cpp.

References cache, comm, Probe(), and tagSingle.

◆ Add() [2/2]

void LocalRegression::Add ( std::vector< Eigen::VectorXd > const &  inputs) const

Add some points to the cache.

Parameters
[in]inputsPoints to add to the cache

Definition at line 108 of file LocalRegression.cpp.

◆ CacheCentroid()

Eigen::VectorXd LocalRegression::CacheCentroid ( ) const

Get the centroid of the cache.

Returns
The cache centroid

Definition at line 236 of file LocalRegression.cpp.

References cache.

◆ CachePoint()

Eigen::VectorXd LocalRegression::CachePoint ( unsigned int const  index) const

A point in the cache.

Parameters
[in]indexThe index of the input
Returns
The input point in the cache associated with the index

Definition at line 80 of file LocalRegression.cpp.

References cache.

◆ CacheSize()

unsigned int LocalRegression::CacheSize ( ) const

Get the total size of the cache.

Returns
The cache size

Definition at line 75 of file LocalRegression.cpp.

References cache.

◆ ClearCache()

void LocalRegression::ClearCache ( )

Clear the cache.

Definition at line 47 of file LocalRegression.cpp.

References cache.

◆ ErrorIndicator() [1/2]

std::pair< double, double > LocalRegression::ErrorIndicator ( Eigen::VectorXd const &  input) const

Get the error indicator.

Get the error indicator \(\Lambda \sqrt{k} \Delta^{p+1}\)

Parameters
[in]inputThe input point
Returns
first: the error indicator, second: the radius of the ball

Definition at line 135 of file LocalRegression.cpp.

References cache, and kn.

◆ ErrorIndicator() [2/2]

std::pair< double, double > LocalRegression::ErrorIndicator ( Eigen::VectorXd const &  input,
std::vector< Eigen::VectorXd > const &  neighbors 
) const

Get the error indicator.

Get the error indicator \(\Lambda \sqrt{k} \Delta^{p+1}\)

Parameters
[in]inputThe input point
[in]neighborsThe nearest neighbors
Returns
first: the error indicator, second: the radius of the ball

Definition at line 145 of file LocalRegression.cpp.

References kn, nlohmann::detail::dtoa_impl::n, and reg.

◆ EvaluateImpl()

void LocalRegression::EvaluateImpl ( muq::Modeling::ref_vector< Eigen::VectorXd > const &  inputs)
overrideprivatevirtual

◆ EvaluateRegressor()

Eigen::VectorXd LocalRegression::EvaluateRegressor ( Eigen::VectorXd const &  input,
std::vector< Eigen::VectorXd > const &  neighbors,
std::vector< Eigen::VectorXd > const &  result 
) const

Definition at line 173 of file LocalRegression.cpp.

References Probe(), and reg.

◆ FitRegression()

void LocalRegression::FitRegression ( Eigen::VectorXd const &  input) const
private

Fit the regression to the nearest neighbors.

Definition at line 52 of file LocalRegression.cpp.

References cache, kn, and reg.

Referenced by EvaluateImpl().

◆ InCache()

bool LocalRegression::InCache ( Eigen::VectorXd const &  point) const

Is a point in the cache?

Parameters
[in]pointWe want to know if this point is in the cache
Returns
true: it is in the cache, false: it is not in the cache

Definition at line 85 of file LocalRegression.cpp.

References cache.

◆ NearestNeighbors() [1/2]

void LocalRegression::NearestNeighbors ( Eigen::VectorXd const &  input,
std::vector< Eigen::VectorXd > &  neighbors 
) const

Get the number of nearest neighbors.

Parameters
[in]inputWe want the \(k\) nearest neighbors to this point
[out]neighborsThe \(k\) nearest neighbors

Definition at line 163 of file LocalRegression.cpp.

References cache, and kn.

◆ NearestNeighbors() [2/2]

void LocalRegression::NearestNeighbors ( Eigen::VectorXd const &  input,
std::vector< Eigen::VectorXd > &  neighbors,
std::vector< Eigen::VectorXd > &  result 
) const

Get the number of nearest neighbors (with result)

Parameters
[in]inputWe want the \(k\) nearest neighbors to this point
[out]neighborsThe \(k\) nearest neighbors
[out]resultsThe corresponding output of the function

Definition at line 168 of file LocalRegression.cpp.

References cache, and kn.

◆ Order()

unsigned int LocalRegression::Order ( ) const

Polynomial order.

Definition at line 143 of file LocalRegression.cpp.

References reg.

◆ PoisednessConstant() [1/2]

std::tuple< Eigen::VectorXd, double, unsigned int > LocalRegression::PoisednessConstant ( Eigen::VectorXd const &  input) const

Get the poisedness constant.

Get the poisedness constant associated with the nearest neighbors of the input point.

Parameters
[in]inputThe input point
Returns
first: the point where the Lagrange polynomials are maximized, second: the poisedness constant, third: the index of the nearest neighbor closest to the new point

Definition at line 112 of file LocalRegression.cpp.

References cache, and kn.

◆ PoisednessConstant() [2/2]

std::tuple< Eigen::VectorXd, double, unsigned int > LocalRegression::PoisednessConstant ( Eigen::VectorXd const &  input,
std::vector< Eigen::VectorXd > const &  neighbors 
) const

Get the poisedness constant.

Get the poisedness constant associated with the nearest neighbors of the input point.

Parameters
[in]inputThe input point
[in]neighborsThe nearest neighbors
Returns
first: the point where the Lagrange polynomials are maximized, second: the poisedness constant, third: the index of the nearest neighbor closest to the new point

Definition at line 120 of file LocalRegression.cpp.

References kn, and reg.

◆ Probe()

void LocalRegression::Probe ( ) const

Definition at line 186 of file LocalRegression.cpp.

References cache, comm, and tagSingle.

Referenced by Add(), EvaluateImpl(), EvaluateRegressor(), and ~LocalRegression().

◆ SetUp()

void LocalRegression::SetUp ( std::shared_ptr< muq::Modeling::ModPiece function,
boost::property_tree::ptree &  pt 
)
private

Set up the regressor.

Definition at line 31 of file LocalRegression.cpp.

References cache, muq::Modeling::ModPiece::inputSizes, muq::Modeling::ModPiece::outputSizes, and reg.

Referenced by LocalRegression().

Member Data Documentation

◆ cache

std::shared_ptr<muq::Modeling::FlannCache> muq::Approximation::LocalRegression::cache
private

A cache containing previous model evaluations.

Definition at line 155 of file LocalRegression.h.

Referenced by Add(), CacheCentroid(), CachePoint(), CacheSize(), ClearCache(), ErrorIndicator(), FitRegression(), InCache(), NearestNeighbors(), PoisednessConstant(), Probe(), and SetUp().

◆ comm

std::shared_ptr<parcer::Communicator> muq::Approximation::LocalRegression::comm = nullptr
private

Definition at line 161 of file LocalRegression.h.

Referenced by Add(), Probe(), and ~LocalRegression().

◆ kn

const unsigned int muq::Approximation::LocalRegression::kn

The number of nearest neighbors to use by the regressor.

Definition at line 130 of file LocalRegression.h.

Referenced by ErrorIndicator(), FitRegression(), NearestNeighbors(), and PoisednessConstant().

◆ reg

std::shared_ptr<Regression> muq::Approximation::LocalRegression::reg
private

◆ tagSingle

const int muq::Approximation::LocalRegression::tagSingle = 0
private

Definition at line 162 of file LocalRegression.h.

Referenced by Add(), and Probe().


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