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

Class container for the generic function. More...

#include <Function.hh>

Public Types

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

Public Member Functions

 FunctionBase ()
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, bool ForceEigen = false>
class Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >

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.
ForceEigenForce the use of Eigen types for input and output.

Member Typedef Documentation

◆ FirstDerivativeType

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction, bool ForceEigen = false>
using Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::FirstDerivativeType = std::conditional_t<ForceEigen || (FunInDim > 1) || (FunOutDim > 1), Eigen::Matrix<Real, FunOutDim, FunInDim>, Real>

First derivative type.

◆ InputType

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction, bool ForceEigen = false>
using Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::InputType = typename std::conditional_t<ForceEigen || (FunInDim > 1), Eigen::Vector<Real, FunInDim>, Real>

Basic constants. Input type.

◆ OutputType

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction, bool ForceEigen = false>
using Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::OutputType = typename std::conditional_t<ForceEigen || (FunOutDim > 1), Eigen::Vector<Real, FunOutDim>, Real>

Output type.

◆ SecondDerivativeType

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction, bool ForceEigen = false>
using Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::SecondDerivativeType
Initial value:
std::conditional_t<ForceEigen || (FunInDim > 1) || (FunOutDim > 1),
std::conditional_t<FunInDim == 1 || FunOutDim == 1, Eigen::Matrix<Real, FunInDim, FunInDim>,
std::vector<Eigen::Matrix<Real, FunInDim, FunInDim>>>, Real>

Second derivative type.

Constructor & Destructor Documentation

◆ FunctionBase()

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction, bool ForceEigen = false>
Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::FunctionBase ( )
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, bool ForceEigen = false>
void Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::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, bool ForceEigen = false>
void Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::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, bool ForceEigen = false>
const InputType & Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::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, bool ForceEigen = false>
const std::vector< InputType > & Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::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, bool ForceEigen = false>
Integer Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::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 ForceEigen = false>
bool Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::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, bool ForceEigen = false>
std::string Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::name ( ) const
inline

Get the function name.

Returns
The function name.

◆ output_dimension()

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction, bool ForceEigen = false>
Integer Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::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, bool ForceEigen = false>
void Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::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, bool ForceEigen = false>
const InputType & Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::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, bool ForceEigen = false>
const std::vector< InputType > & Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::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, bool ForceEigen = false>
std::vector<InputType> Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::m_guesses
protected

Known solutions used for test purposes.

◆ m_solutions

template<typename Real, Integer FunInDim, Integer FunOutDim, typename DerivedFunction, bool ForceEigen = false>
std::vector<InputType> Optimist::FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen >::m_solutions
protected

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