lucid  0.0.1
Lifting-based Uncertain Control Invariant Dynamics
Loading...
Searching...
No Matches
lucid::ModelEstimator Class Referencefinal

Dummy estimator that uses a user-defined function to make predictions. More...

#include <ModelEstimator.h>

Inheritance diagram for lucid::ModelEstimator:
lucid::Estimator lucid::Parametrizable

Public Member Functions

 ModelEstimator (std::function< Matrix(ConstMatrixRef)> model_function)
 Construct a new Model Estimator object.
 
std::unique_ptr< Estimatorclone () const override
 Clone the estimator by creating a new instance with the same parameters.
 
Matrix predict (ConstMatrixRef x) const override
 A model is a function that takes a \( n \times d_x \) matrix of row vectors in the input space \( \mathcal{X} \) and returns a \( n \times d_y \) matrix of row vectors in the output space \( \mathcal{Y} \).
 
double score (ConstMatrixRef evaluation_inputs, ConstMatrixRef evaluation_outputs) const override
 Score the estimator assigning a numerical value to its accuracy in predicting the evaluation_outputs given the evaluation_inputs.
 
std::string to_string () const override
 Obtain the string representation of this object.
 
- Public Member Functions inherited from lucid::Estimator
 Estimator (Parameters parameters=NoParameters, const std::shared_ptr< const Tuner > &tuner=nullptr)
 Construct a new Estimator object.
 
Matrix operator() (ConstMatrixRef x) const
 A model is a function that takes a \( n \times d_x \) matrix of row vectors in the input space \( \mathcal{X} \) and returns a \( n \times d_y \) matrix of row vectors in the output space \( \mathcal{Y} \).
 
Estimatorfit (ConstMatrixRef training_inputs, ConstMatrixRef training_outputs, const Tuner &tuner)
 Fit the model to the given data.
 
Estimatorfit (ConstMatrixRef training_inputs, ConstMatrixRef training_outputs)
 Fit the model to the given data.
 
Estimatorfit_online (ConstMatrixRef training_inputs, const OutputComputer &training_outputs, const Tuner &tuner)
 Fit the model to the data produced by the training_outputs OutputComputer.
 
Estimatorfit_online (ConstMatrixRef training_inputs, const OutputComputer &training_outputs)
 Fit the model to the data produced by the training_outputs OutputComputer.
 
Estimatorconsolidate (ConstMatrixRef training_inputs, ConstMatrixRef training_outputs, const Request request=Request::_)
 Consolidate the model, making sure it is ready for use.
 
Estimatorconsolidate (ConstMatrixRef training_inputs, ConstMatrixRef training_outputs, Requests requests)
 Consolidate the model, making sure it is ready for use.
 
const std::shared_ptr< const Tuner > & tuner () const
 Get read-only access to the tuner of the estimator.
 
std::shared_ptr< const Tuner > & m_tuner ()
 Get read-write access to the tuner of the estimator.
 
- Public Member Functions inherited from lucid::Parametrizable
template<IsAnyOf< int, double, const Vector & > T>
get (Parameter parameter) const
 Get the value of the specified parameter.
 
template<Parameter P>
internal::ParameterType< P >::ref_type get () const
 Get the value of the specified parameter.
 
std::variant< int, double, Vector > get (Parameter parameter) const
 Get the value of the specified parameter.
 
void set (Parameter parameter, const std::variant< int, double, Vector > &value)
 Set the parameter to the indicated value.
 
template<Parameter P>
void set (const std::variant< int, double, Vector > &value)
 Set the parameter to the indicated value.
 
void set (Parameter parameter, std::size_t idx, const std::variant< std::vector< int >, std::vector< double >, std::vector< Vector > > &values)
 Set the parameter to the index-th value among the indicated values.
 
template<Parameter P>
void set (std::size_t idx, const std::variant< std::vector< int >, std::vector< double >, std::vector< Vector > > &values)
 Set the parameter to the index-th value among the indicated values.
 
virtual void set (Parameter parameter, int value)
 Set the parameter to the indicated value.
 
virtual void set (Parameter parameter, double value)
 Set the parameter to the indicated value.
 
virtual void set (Parameter parameter, const Vector &value)
 Set the parameter to the indicated value.
 
template<Parameter P>
void set (typename internal::ParameterType< P >::ref_type value)
 Set the parameter to the indicated value.
 
bool has (const Parameter parameter) const
 Check whether the parameter is present in this object.
 
Parameters parameters () const
 Get read-only access to the parameters of the parametrizable object.
 
std::vector< Parameterparameters_list () const
 Get read-only access to the list of parameters of the parametrizable object.
 
Parametrizableload (const Parametrizable &o)
 Load parameters from another Parametrizable object.
 

Private Member Functions

Estimatorconsolidate_impl (ConstMatrixRef training_inputs, ConstMatrixRef training_outputs, Requests requests) override
 Concrete implementation of the consolidate method.
 

Private Attributes

std::function< Matrix(ConstMatrixRef)> model_function_
 Function that defines the model.
 

Additional Inherited Members

- Protected Member Functions inherited from lucid::Parametrizable
virtual int get_i (Parameter parameter) const
 Get the value of the specified parameter.
 
virtual double get_d (Parameter parameter) const
 Get the value of the specified parameter.
 
virtual const Vector & get_v (Parameter parameter) const
 Get the value of the specified parameter.
 
- Protected Attributes inherited from lucid::Parametrizable
Parameters parameters_
 Parameters supported by this object.
 

Detailed Description

Dummy estimator that uses a user-defined function to make predictions.

Useful for testing, in a context that assumes perfect knowledge of the system dynamics.

Constructor & Destructor Documentation

◆ ModelEstimator()

lucid::ModelEstimator::ModelEstimator ( std::function< Matrix(ConstMatrixRef)> model_function)
explicit

Construct a new Model Estimator object.

Parameters
model_functionFunction that defines the model.

Member Function Documentation

◆ clone()

std::unique_ptr< Estimator > lucid::ModelEstimator::clone ( ) const
nodiscardoverridevirtual

Clone the estimator by creating a new instance with the same parameters.

Returns
new instance of the estimator

Implements lucid::Estimator.

◆ consolidate_impl()

Estimator & lucid::ModelEstimator::consolidate_impl ( ConstMatrixRef training_inputs,
ConstMatrixRef training_outputs,
Requests requests )
overrideprivatevirtual

Concrete implementation of the consolidate method.

Parameters
training_inputstraining input data
training_outputstraining output data
requestsrequests for the consolidation process
Returns
reference to the estimator

Implements lucid::Estimator.

◆ predict()

Matrix lucid::ModelEstimator::predict ( ConstMatrixRef x) const
nodiscardoverridevirtual

A model is a function that takes a \( n \times d_x \) matrix of row vectors in the input space \( \mathcal{X} \) and returns a \( n \times d_y \) matrix of row vectors in the output space \( \mathcal{Y} \).

Precondition
The estimator should be fitted before calling this method.
Parameters
x\( n \times d_x \) matrix of row vectors in \( \mathcal{X} \)
Returns
\( n \times d_y \) matrix of row vectors in \( \mathcal{Y} \)

Implements lucid::Estimator.

◆ score()

double lucid::ModelEstimator::score ( ConstMatrixRef evaluation_inputs,
ConstMatrixRef evaluation_outputs ) const
nodiscardoverridevirtual

Score the estimator assigning a numerical value to its accuracy in predicting the evaluation_outputs given the evaluation_inputs.

Given the evaluation inputs \( x = \{ x_1, \dots, x_n \} \), where \( x_i \in \mathcal{X} \subseteq \mathbb{R}^{d_x}, 0 \le i \le n \), we want to give a numerical score to the model's predictions \( \hat{y} = \{ \hat{y}_1, \dots, \hat{y}_n \} \) with respect to the true outputs \( y = \{ y_1, \dots, y_n \} \), where \( y_i \in \mathcal{Y} \subseteq \mathbb{R}^{d_y}, 0 \le i \le n \).

Note
By default, the score is computed using the scorer::r2_score.
Precondition
The methods fit or consolidate should have been called at least once before calling this method.
Parameters
evaluation_inputs\( \texttip{n}{Number of samples} \times \texttip{d_x}{Dimension of the input vector space} \) evaluation input data
evaluation_outputs\( \texttip{n}{Number of samples} \times \texttip{d_y}{Dimension of the output vector space} \) evaluation output data
Returns
score of the model

Implements lucid::Estimator.

◆ to_string()

std::string lucid::ModelEstimator::to_string ( ) const
nodiscardoverridevirtual

Obtain the string representation of this object.

Returns
string representation of this object

Reimplemented from lucid::Estimator.


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