Interior-point-optimisation  1.0-1
Interior-pointoptimisationlibrary
ipo::detail::BarrierFunction Class Reference

Function for the logarithmic barrier. More...

#include <BarrierFunction.hpp>

Inheritance diagram for ipo::detail::BarrierFunction:
Inheritance graph
Collaboration diagram for ipo::detail::BarrierFunction:
Collaboration graph

Public Types

enum  Sign { Sign::positive, Sign::negative }
 Enumerated type used to determine sign of objective in BarrierFunction. More...
 

Public Member Functions

 BarrierFunction (Model &model, Sign const sign=Sign::positive, double const t=0.1)
 The constructor needs a Model. More...
 
virtual double operator() (gsl::vector const &vector)
 Evaluate the function. More...
 
virtual gsl::vector gradient (gsl::vector const &vector)
 Compute or estimate a gradient value from objective and constraints. More...
 
virtual gsl::matrix hessian (gsl::vector const &vector)
 Compute or estimate a Hessian value from objective and constraints. More...
 
virtual gsl::vector gradient ()
 Get gradient value from last call to setValue();. More...
 
virtual gsl::matrix hessian ()
 Get Hessian value from last call to setValue();. More...
 
void set_t (double const t)
 Set t to a new value. More...
 
double get_t () const
 Get t value. More...
 
virtual void setVector (gsl::vector const &vector)
 Set value of vector. More...
 
- Public Member Functions inherited from ipo_function::Function
 Function (size_t const size=0)
 Constructor. More...
 
virtual std::tuple
< gsl::vector, gsl::matrix > 
derivatives (gsl::vector const &vector)
 Compute or estimate derivative values. More...
 
- Public Member Functions inherited from ipo_function::detail::FunctionBase
 FunctionBase (size_t const size=0)
 Constructor. More...
 
virtual ~FunctionBase ()=0
 Make the class abstract. More...
 
size_t getSize () const
 Get size of vector for function arguments or zero for arbitrary size. More...
 
- Public Member Functions inherited from ipo_function::DerivativesEstimates
 DerivativesEstimates (size_t const size=0)
 Constructor. More...
 
virtual gsl::matrix hessian () const
 
- Public Member Functions inherited from ipo_function::GradientEstimate
 GradientEstimate (size_t const size=0)
 Constructor. More...
 
virtual double value () const
 
virtual gsl::vector gradient () const
 

Protected Member Functions

void initialiseResultFromObjective (gsl::vector &subvector, bool const simul=false)
 Update result from objective. More...
 
void updateResultFromConstraint (Constraint &constraint, gsl::vector &subvector, double const &lowerBound, double const &functionValue, double const &upperBound)
 Update result from a constraint. More...
 
void updateResultFromVariable (std::map< Variable, size_t >::value_type &entry, gsl::vector const &vector)
 Update result from a variable. More...
 
gsl::vector initialiseGradientFromObjective (gsl::vector &subvector, bool const simul=false)
 Update gradient from objective. More...
 
gsl::vector updateGradientFromConstraint (size_t const constraintIndex, gsl::vector &subvector, double const &lowerBound, double const &functionValue, double const &upperBound, bool const simul=false)
 Update gradient from a constraint. More...
 
void updateGradientFromVariable (std::map< Variable, size_t >::value_type &entry, gsl::vector const &vector)
 Update gradient from a variable. More...
 
void initialiseHessianFromObjective (gsl::vector &subvector, bool const simul=false)
 Update gradient from objective. More...
 
void updateHessianFromConstraint (size_t const constraintIndex, gsl::vector &subvector, double const &lowerBound, double const &functionValue, double const &upperBound, gsl::vector &gradient, bool const simul=false)
 Update Hessian from a constraint. More...
 
void updateHessianFromVariable (std::map< Variable, size_t >::value_type &entry, gsl::vector const &vector)
 Update hessian from a variable. More...
 

Protected Attributes

Modelmodel
 The value t used to determine the barrier. More...
 
Sign const sign
 Set this to true or false according as the objective is to be added or subtracted. More...
 
double t
 The value t used to determine the barrier. More...
 
- Protected Attributes inherited from ipo_function::Function
double h = std::sqrt( std::numeric_limits<double>::epsilon() )
 Value used for default gradient estimates. More...
 
double h2 = std::sqrt( h )
 Value used for default Hessian estimates. More...
 
- Protected Attributes inherited from ipo_function::detail::FunctionBase
size_t const size
 Size of vector arguments to supply to subclass functions. More...
 
- Protected Attributes inherited from ipo_function::DerivativesEstimates
gsl::matrix functionHessian
 The Hessian value. More...
 
- Protected Attributes inherited from ipo_function::GradientEstimate
double functionValue
 The function value. More...
 
gsl::vector functionGradient
 The gradient value. More...
 

Detailed Description

Function for the logarithmic barrier.

Definition at line 35 of file BarrierFunction.hpp.

Member Enumeration Documentation

Enumerated type used to determine sign of objective in BarrierFunction.

Enumerator
positive 

Use +objective.

negative 

Use -objective.

Definition at line 41 of file BarrierFunction.hpp.

Constructor & Destructor Documentation

BarrierFunction::BarrierFunction ( Model model,
Sign const  sign = Sign::positive,
double const  t = 0.1 
)

The constructor needs a Model.

It can also take a parameter t that is used together with logarithms to approximate an indicator function. The larger t is the better the approximation. Typically t is set useing set_t() during optimisation.

Parameters
modelThe Model
signThe Sign: positive or negative
tThe value of t

Definition at line 28 of file BarrierFunction.cc.

Member Function Documentation

double BarrierFunction::get_t ( ) const

Get t value.

Returns
The value of t

Definition at line 42 of file BarrierFunction.cc.

References t.

gsl::vector BarrierFunction::gradient ( gsl::vector const &  vector)
virtual

Compute or estimate a gradient value from objective and constraints.

Parameters
vectorThe vector at which to evaluate the function
Returns
The gradient value

Reimplemented from ipo_function::Function.

Definition at line 77 of file BarrierFunction.cc.

References ipo::Model::constraintIndices, ipo::Model::constraints, ipo_function::GradientEstimate::functionGradient, ipo::Model::indexMap, ipo::infinity, initialiseGradientFromObjective(), lowerBound, ipo::minusInfinity, model, ipo::Model::objectiveIndices, updateGradientFromConstraint(), updateGradientFromVariable(), and upperBound.

virtual gsl::vector ipo::detail::BarrierFunction::gradient ( )
inlinevirtual

Get gradient value from last call to setValue();.

Returns
The gradient value

Definition at line 74 of file BarrierFunction.hpp.

Referenced by hessian(), initialiseGradientFromObjective(), setVector(), and updateGradientFromConstraint().

gsl::matrix BarrierFunction::hessian ( gsl::vector const &  vector)
virtual

Compute or estimate a Hessian value from objective and constraints.

Parameters
vectorThe vector at which to evaluate the function
Returns
The Hessian value

Reimplemented from ipo_function::Function.

Definition at line 107 of file BarrierFunction.cc.

References ipo::Model::constraintIndices, ipo::Model::constraints, ipo_function::DerivativesEstimates::functionHessian, gradient(), ipo::Model::indexMap, ipo::infinity, initialiseHessianFromObjective(), lowerBound, ipo::minusInfinity, model, ipo::Model::objectiveIndices, updateHessianFromConstraint(), updateHessianFromVariable(), and upperBound.

virtual gsl::matrix ipo::detail::BarrierFunction::hessian ( )
inlinevirtual

Get Hessian value from last call to setValue();.

Returns
The Hessian value

Definition at line 79 of file BarrierFunction.hpp.

Referenced by initialiseHessianFromObjective(), and updateHessianFromConstraint().

gsl::vector BarrierFunction::initialiseGradientFromObjective ( gsl::vector &  subvector,
bool const  simul = false 
)
protected

Update gradient from objective.

Parameters
subvectorThe subvector for the objective
simulSet to true to try to estimate function value and derivatives simultaneously: assumes gradient already calculated
Returns
The gradient of the objective function

Definition at line 185 of file BarrierFunction.cc.

References ipo_function::DerivativesEstimates::DerivativesEstimates(), ipo_function::GradientEstimate::functionGradient, ipo::detail::ModelFunction::getFunction(), ipo_function::Function::gradient(), gradient(), ipo::Model::indexMap, model, ipo::Model::objective, ipo::Model::objectiveIndices, positive, sign, and t.

Referenced by gradient(), and setVector().

void BarrierFunction::initialiseHessianFromObjective ( gsl::vector &  subvector,
bool const  simul = false 
)
protected

Update gradient from objective.

Parameters
subvectorThe subvector for the objective
simulSet to true to try to estimate function value and derivatives simultaneously

Definition at line 252 of file BarrierFunction.cc.

References ipo_function::DerivativesEstimates::DerivativesEstimates(), ipo_function::DerivativesEstimates::functionHessian, ipo::detail::ModelFunction::getFunction(), ipo_function::Function::hessian(), hessian(), ipo::Model::indexMap, model, ipo::Model::objective, ipo::Model::objectiveIndices, positive, sign, and t.

Referenced by hessian(), and setVector().

void BarrierFunction::initialiseResultFromObjective ( gsl::vector &  subvector,
bool const  simul = false 
)
protected

Update result from objective.

Parameters
subvectorThe subvector for the objective
simulSet to true to try to estimate function value and derivatives simultaneously

Definition at line 138 of file BarrierFunction.cc.

References ipo_function::DerivativesEstimates::DerivativesEstimates(), ipo_function::GradientEstimate::functionValue, ipo::detail::ModelFunction::getFunction(), model, ipo::Model::objective, positive, sign, and t.

Referenced by operator()(), and setVector().

double BarrierFunction::operator() ( gsl::vector const &  vector)
virtual
void BarrierFunction::set_t ( double const  t)

Set t to a new value.

Parameters
tThe new vector value

Definition at line 37 of file BarrierFunction.cc.

References t.

void BarrierFunction::setVector ( gsl::vector const &  vector)
virtual

Set value of vector.

This also calculates and stores function value, gradient and Hessian more efficiently than if all three are computed seprately. It is even more efficient on objective and constraint functions that are also derived classes of DerivativesEstimates.

Implements ipo_function::GradientEstimate.

Definition at line 327 of file BarrierFunction.cc.

References ipo::Model::constraintIndices, ipo::Model::constraints, ipo_function::DerivativesEstimates::DerivativesEstimates(), gradient(), ipo::Model::indexMap, ipo::infinity, initialiseGradientFromObjective(), initialiseHessianFromObjective(), initialiseResultFromObjective(), lowerBound, ipo::minusInfinity, model, ipo::Model::objectiveIndices, updateGradientFromConstraint(), updateGradientFromVariable(), updateHessianFromConstraint(), updateHessianFromVariable(), updateResultFromConstraint(), updateResultFromVariable(), and upperBound.

gsl::vector BarrierFunction::updateGradientFromConstraint ( size_t const  constraintIndex,
gsl::vector &  subvector,
double const &  lowerBound,
double const &  functionValue,
double const &  upperBound,
bool const  simul = false 
)
protected

Update gradient from a constraint.

Parameters
constraintIndexThe constraintIndex
subvectorThe subvector for constraint
lowerBoundThe lower bound on the constraint
functionValueThe constraint function value
upperBoundThe upper bound on the constraint
Returns
The gradient of the constraint function
Parameters
simulSet to true to try to estimate function value and derivatives simultaneously: assumes gradient already calculated

Definition at line 205 of file BarrierFunction.cc.

References ipo::Model::constraintIndices, ipo::Model::constraints, ipo_function::DerivativesEstimates::DerivativesEstimates(), ipo_function::GradientEstimate::functionGradient, gradient(), ipo::infinity, ipo::minusInfinity, and model.

Referenced by gradient(), and setVector().

void BarrierFunction::updateGradientFromVariable ( std::map< Variable, size_t >::value_type &  entry,
gsl::vector const &  vector 
)
protected

Update gradient from a variable.

Parameters
entryThe indexMap entry for the variable
vectorThe vector of variable values

Definition at line 230 of file BarrierFunction.cc.

References ipo_function::GradientEstimate::functionGradient, ipo::infinity, lowerBound, ipo::minusInfinity, and upperBound.

Referenced by gradient(), and setVector().

void BarrierFunction::updateHessianFromConstraint ( size_t const  constraintIndex,
gsl::vector &  subvector,
double const &  lowerBound,
double const &  functionValue,
double const &  upperBound,
gsl::vector &  gradient,
bool const  simul = false 
)
protected

Update Hessian from a constraint.

Parameters
constraintIndexThe constraintIndex
subvectorThe subvector for constraint
lowerBoundThe lower bound on the constraint
functionValueThe constraint function value
upperBoundThe upper bound on the constraint
gradientThe gradient at subvector
simulSet to true to try to estimate function value and derivatives simultaneously

Definition at line 272 of file BarrierFunction.cc.

References ipo::Model::constraintIndices, ipo::Model::constraints, ipo_function::DerivativesEstimates::DerivativesEstimates(), ipo_function::DerivativesEstimates::functionHessian, hessian(), ipo::infinity, ipo::minusInfinity, and model.

Referenced by hessian(), and setVector().

void BarrierFunction::updateHessianFromVariable ( std::map< Variable, size_t >::value_type &  entry,
gsl::vector const &  vector 
)
protected

Update hessian from a variable.

Parameters
entryThe indexMap entry for the variable
vectorThe vector of variable values

Definition at line 301 of file BarrierFunction.cc.

References ipo_function::DerivativesEstimates::functionHessian, ipo::infinity, lowerBound, ipo::minusInfinity, and upperBound.

Referenced by hessian(), and setVector().

void BarrierFunction::updateResultFromConstraint ( Constraint constraint,
gsl::vector &  subvector,
double const &  lowerBound,
double const &  functionValue,
double const &  upperBound 
)
protected

Update result from a constraint.

Parameters
constraintThe constraint
subvectorThe subvector for constraint
lowerBoundThe lower bound on the constraint
functionValueThe constraint function value
upperBoundThe upper bound on the constraint

Definition at line 157 of file BarrierFunction.cc.

References ipo::infinity, and ipo::minusInfinity.

Referenced by operator()(), and setVector().

void BarrierFunction::updateResultFromVariable ( std::map< Variable, size_t >::value_type &  entry,
gsl::vector const &  vector 
)
protected

Update result from a variable.

Parameters
entryThe indexMap entry for the variable
vectorThe vector of variable values

Definition at line 169 of file BarrierFunction.cc.

References ipo_function::GradientEstimate::functionValue, ipo::infinity, lowerBound, ipo::minusInfinity, and upperBound.

Referenced by operator()(), and setVector().

Member Data Documentation

Model& ipo::detail::BarrierFunction::model
protected
Sign const ipo::detail::BarrierFunction::sign
protected

Set this to true or false according as the objective is to be added or subtracted.

Definition at line 193 of file BarrierFunction.hpp.

Referenced by initialiseGradientFromObjective(), initialiseHessianFromObjective(), and initialiseResultFromObjective().

double ipo::detail::BarrierFunction::t
protected

The value t used to determine the barrier.

Definition at line 197 of file BarrierFunction.hpp.

Referenced by get_t(), initialiseGradientFromObjective(), initialiseHessianFromObjective(), initialiseResultFromObjective(), and set_t().


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