Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
Optimist::CostFunction< Real, N, DerivedFunction > Class Template Reference

Class container for the cost function. More...

#include <CostFunction.hh>

Inherits Optimist::Function< Real, N, 1, DerivedFunction >.

Public Types

using Vector = typename Function<Real, N, 1, DerivedFunction>::InputType
 
using RowVector = typename Function<Real, N, 1, DerivedFunction>::FirstDerivativeType
 
using Matrix = typename Function<Real, N, 1, DerivedFunction>::SecondDerivativeType
 
- Public Types inherited from Optimist::Function< Real, N, 1, DerivedFunction >
using InputType
 
using OutputType
 
using FirstDerivativeType
 
using SecondDerivativeType
 

Public Member Functions

 CostFunction ()
 
std::string name () const
 
void evaluate (const Vector &x, Vector &out) const
 
void gradient (const Vector &x, RowVector &out) const
 
void hessian (const Vector &x, Matrix &out) const
 
- Public Member Functions inherited from Optimist::Function< Real, N, 1, DerivedFunction >
 Function ()
 
std::string name () const
 
void evaluate (const InputType &x, OutputType &out) const
 
void first_derivative (const InputType &x, FirstDerivativeType &out) const
 
void second_derivative (const InputType &x, SecondDerivativeType &out) const
 
constexpr Integer input_dimension () const
 
constexpr Integer output_dimension () const
 
const std::vector< InputType > & solutions () const
 
const std::vector< InputType > & guesses () const
 
const InputTypesolution (const Integer i) const
 
const InputTypeguess (const Integer i) const
 
bool is_solution (const InputType &x, const Real tol=EPSILON_LOW) const
 

Public Attributes

friend Function< Real, N, 1, CostFunction< Real, N, DerivedFunction > >
 

Additional Inherited Members

- Protected Attributes inherited from Optimist::Function< Real, N, 1, DerivedFunction >
std::vector< InputTypem_solutions
 
std::vector< InputTypem_guesses
 

Detailed Description

template<typename Real, Integer N, typename DerivedFunction>
class Optimist::CostFunction< Real, N, DerivedFunction >

Function

The Function class in Optimist provides a common interface for representing and evaluating mathematical functions. This class is designed to handle a generic function \(\mathbf{f}(\mathbf{x}): \mathbb{R}^{n} \rightarrow \mathbb{R}^{m}\), where \(\mathbf{x}\) is a vector of input variables and \(\mathbf{f}(\mathbf{x})\) is a vector of output values.

The Function class serves as a base class for developing specific function representations that can be used in various numerical algorithms. In general, the Function class and its derived classes are designed to support:

  • Root-finding problems of the form

    \[ \mathbf{f}(\mathbf{x}) = \mathbf{0} \text{,} \quad \text{with} \quad \mathbf{f}: \mathbb{R}^{n} \rightarrow \mathbb{R}^{n} \text{,} \]

  • Optimization problems of the form

    \[ \min_{\mathbf{x}} f(\mathbf{x}) \text{,} \quad f: \mathbb{R}^{n} \rightarrow \mathbb{R} \text{.} \]

If \(n > 1\), the function is multi-dimensional, otherwise, it is scalar. The linear algebra operations required for multi-dimensional functions are performed using the Eigen library, which provides a high-level interface for matrix operations. For scalar functions ( \(n = 1\)), the base type changes to Real, a scalar type defined in the Optimist library.

Template Parameters
NThe dimension of the cost function input.
DerivedFunctionDerived cost function class.

Member Typedef Documentation

◆ Matrix

template<typename Real, Integer N, typename DerivedFunction>
using Optimist::CostFunction< Real, N, DerivedFunction >::Matrix = typename Function<Real, N, 1, DerivedFunction>::SecondDerivativeType

Hessian matrix type.

◆ RowVector

template<typename Real, Integer N, typename DerivedFunction>
using Optimist::CostFunction< Real, N, DerivedFunction >::RowVector = typename Function<Real, N, 1, DerivedFunction>::FirstDerivativeType

Gradient (row) vector type.

◆ Vector

template<typename Real, Integer N, typename DerivedFunction>
using Optimist::CostFunction< Real, N, DerivedFunction >::Vector = typename Function<Real, N, 1, DerivedFunction>::InputType

Vector type.

Constructor & Destructor Documentation

◆ CostFunction()

template<typename Real, Integer N, typename DerivedFunction>
Optimist::CostFunction< Real, N, DerivedFunction >::CostFunction ( )
inline

Class constructor for the function.

Member Function Documentation

◆ evaluate()

template<typename Real, Integer N, typename DerivedFunction>
void Optimist::CostFunction< Real, N, DerivedFunction >::evaluate ( const Vector & x,
Vector & out ) const
inline

Compute the function value at the input point.

Parameters
[in]xInput point.
[out]outThe function value.

◆ gradient()

template<typename Real, Integer N, typename DerivedFunction>
void Optimist::CostFunction< Real, N, DerivedFunction >::gradient ( const Vector & x,
RowVector & out ) const
inline

Compute the function first derivative at the input point.

Parameters
[in]xInput point.
[out]outThe function first derivative.

◆ hessian()

template<typename Real, Integer N, typename DerivedFunction>
void Optimist::CostFunction< Real, N, DerivedFunction >::hessian ( const Vector & x,
Matrix & out ) const
inline

Compute the function second derivative at the input point.

Parameters
[in]xInput point.
[out]outThe function second derivative.

◆ name()

template<typename Real, Integer N, typename DerivedFunction>
std::string Optimist::CostFunction< Real, N, DerivedFunction >::name ( ) const
inline

Get the function name.

Returns
The function name.

Member Data Documentation

◆ Function< Real, N, 1, CostFunction< Real, N, DerivedFunction > >

template<typename Real, Integer N, typename DerivedFunction>
friend Optimist::CostFunction< Real, N, DerivedFunction >::Function< Real, N, 1, CostFunction< Real, N, DerivedFunction > >

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