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

Class container for the generic function. More...

#include <Function.hh>

Public Types

using InputType = typename std::conditional_t<FunInDim == 1, Real, Eigen::Vector<Real, FunInDim>>
 
using OutputType = typename std::conditional_t<FunOutDim == 1, Real, Eigen::Vector<Real, FunOutDim>>
 
using FirstDerivativeType = std::conditional_t<FunInDim == 1 && FunOutDim == 1, Real, Eigen::Matrix<Real, FunOutDim, FunInDim>>
 
using SecondDerivativeType
 

Public Member Functions

 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
 

Protected Attributes

std::vector< InputTypem_solutions
 
std::vector< InputTypem_guesses
 

Detailed Description

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
class Optimist::Function< Real, FunInDim, FunOutDim, 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
RealScalar number type.
FunInDimThe function problem input dimension.
FunOutDimThe function problem output dimension.
DerivedFunctionDerived function class.

Member Typedef Documentation

◆ FirstDerivativeType

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
using Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::FirstDerivativeType = std::conditional_t<FunInDim == 1 && FunOutDim == 1, Real, Eigen::Matrix<Real, FunOutDim, FunInDim>>

First derivative type.

◆ InputType

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
using Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::InputType = typename std::conditional_t<FunInDim == 1, Real, Eigen::Vector<Real, FunInDim>>

Basic constants. Input type.

◆ OutputType

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
using Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::OutputType = typename std::conditional_t<FunOutDim == 1, Real, Eigen::Vector<Real, FunOutDim>>

Output type.

◆ SecondDerivativeType

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
using Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::SecondDerivativeType
Initial value:
std::conditional_t<FunInDim == 1 && FunOutDim == 1, Real,
std::conditional_t<FunInDim == 1 || FunOutDim == 1, Eigen::Matrix<Real, FunInDim, FunInDim>,
std::vector<Eigen::Matrix<Real, FunInDim, FunInDim>>>>

Second derivative type.

Constructor & Destructor Documentation

◆ Function()

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::Function ( )
inline

Suggested initial guess used for testing. Class constructor for the function.

Member Function Documentation

◆ evaluate()

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
void Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::evaluate ( const InputType & x,
OutputType & out ) const
inline

Compute the function value at the input point.

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

◆ first_derivative()

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
void Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::first_derivative ( const InputType & x,
FirstDerivativeType & out ) const
inline

Compute the function first derivative at the input point.

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

◆ guess()

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
const InputType & Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::guess ( const Integer i) const
inline

Retrieve the initial guess at the index.

Parameters
[in]iThe index of the initial guess.
Returns
The initial guess.

◆ guesses()

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
const std::vector< InputType > & Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::guesses ( ) const
inline

Get the vector of initial guesses.

Returns
The vector of initial guesses.

◆ input_dimension()

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
Integer Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::input_dimension ( ) const
inlineconstexpr

Get the input dimension of the function.

Returns
The input dimension of the function.

◆ is_solution()

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
bool Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::is_solution ( const InputType & x,
const Real tol = EPSILON_LOW ) const
inline

Check if the input point is a known solution.

Parameters
[in]xInput point.
[in]tolTolerance.
Returns
True if the input point is a known solution, false otherwise.

◆ name()

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
std::string Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::name ( ) const
inline

Get the function name.

Returns
The function name.

◆ output_dimension()

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
Integer Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::output_dimension ( ) const
inlineconstexpr

Get the output dimension of the function.

Returns
The output dimension of the function.

◆ second_derivative()

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
void Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::second_derivative ( const InputType & x,
SecondDerivativeType & out ) const
inline

Compute the function second derivative at the input point.

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

◆ solution()

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
const InputType & Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::solution ( const Integer i) const
inline

Retrieve the known solution at the index.

Parameters
[in]iThe index of the known solution.
Returns
The known solution.

◆ solutions()

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
const std::vector< InputType > & Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::solutions ( ) const
inline

Get the vector of known solutions.

Returns
The vector of known solutions.

Member Data Documentation

◆ m_guesses

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
std::vector<InputType> Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::m_guesses
protected

Known solutions used for test purposes.

◆ m_solutions

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction>
std::vector<InputType> Optimist::Function< Real, FunInDim, FunOutDim, DerivedFunction >::m_solutions
protected

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