shark::EvaluationArchive< PointType, ResultT > Class Template Reference

Objective function wrapper storing all function evaluations. More...

#include <shark/ObjectiveFunctions/EvaluationArchive.h>

+ Inheritance diagram for shark::EvaluationArchive< PointType, ResultT >:

Classes

class  PointResultPairType
 Pair of point and result. More...
 

Public Types

typedef base_type::SearchPointType SearchPointType
 
typedef base_type::ResultType ResultType
 
typedef base_type::FirstOrderDerivative FirstOrderDerivative
 
typedef base_type::SecondOrderDerivative SecondOrderDerivative
 
typedef std::set< PointResultPairTypePointResultPairContainer
 
typedef PointResultPairContainer::iterator PointResultPairIterator
 
typedef PointResultPairContainer::const_iterator PointResultPairConstIterator
 
- Public Types inherited from shark::AbstractObjectiveFunction< PointType, ResultT >
enum  Feature {
  HAS_VALUE = 1, HAS_FIRST_DERIVATIVE = 2, HAS_SECOND_DERIVATIVE = 4, CAN_PROPOSE_STARTING_POINT = 8,
  IS_CONSTRAINED_FEATURE = 16, HAS_CONSTRAINT_HANDLER = 32, CAN_PROVIDE_CLOSEST_FEASIBLE = 64, IS_THREAD_SAFE = 128,
  IS_NOISY = 256
}
 List of features that are supported by an implementation. More...
 
typedef PointType SearchPointType
 
typedef ResultT ResultType
 
typedef boost::mpl::if_< std::is_arithmetic< ResultT >, SearchPointType, RealMatrix >::type FirstOrderDerivative
 
typedef TypedFlags< FeatureFeatures
 This statement declares the member m_features. See Core/Flags.h for details. More...
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 

Public Member Functions

 EvaluationArchive (base_type *objective)
 Constructor. More...
 
base_typeobjective ()
 Access to the underlying objective function. More...
 
const base_typeobjective () const
 Access to the underlying objective function. More...
 
void init ()
 Wrapper function. More...
 
virtual std::size_t numberOfObjectives () const
 Wrapper function. More...
 
bool hasScalableObjectives () const
 Wrapper function. More...
 
void setNumberOfObjectives (std::size_t numberOfObjectives)
 Wrapper function. More...
 
bool isFeasible (const SearchPointType &input) const
 Wrapper function. More...
 
void closestFeasible (SearchPointType &input) const
 Wrapper function. More...
 
void proposeStartingPoint (SearchPointType &startingPoint) const
 Wrapper function. More...
 
std::size_t numberOfVariables () const
 Wrapper function; conditional on vector space property. More...
 
ResultType eval (const SearchPointType &input) const
 Wrapper function storing point and result. More...
 
ResultType operator() (const SearchPointType &input) const
 
ResultType evalDerivative (const SearchPointType &input, FirstOrderDerivative &derivative) const
 Wrapper function storing point and result. More...
 
ResultType evalDerivative (const SearchPointType &input, SecondOrderDerivative &derivative) const
 Wrapper function storing point and result. More...
 
std::size_t size () const
 Return the size of the archive; which is the number of point/result pairs. More...
 
PointResultPairIterator begin ()
 Begin iterator to the point/result pairs. More...
 
PointResultPairConstIterator begin () const
 Begin iterator to the point/result pairs. More...
 
PointResultPairIterator end ()
 End iterator to the point/result pairs. More...
 
PointResultPairConstIterator end () const
 End iterator to the point/result pairs. More...
 
- Public Member Functions inherited from shark::AbstractObjectiveFunction< PointType, ResultT >
const Featuresfeatures () const
 
virtual void updateFeatures ()
 
bool hasValue () const
 returns whether this function can calculate it's function value More...
 
bool hasFirstDerivative () const
 returns whether this function can calculate the first derivative More...
 
bool hasSecondDerivative () const
 returns whether this function can calculate the second derivative More...
 
bool canProposeStartingPoint () const
 returns whether this function can propose a starting point. More...
 
bool isConstrained () const
 returns whether this function can return More...
 
bool hasConstraintHandler () const
 returns whether this function can return More...
 
bool canProvideClosestFeasible () const
 Returns whether this function can calculate thee closest feasible to an infeasible point. More...
 
bool isThreadSafe () const
 Returns true, when the function can be usd in parallel threads. More...
 
bool isNoisy () const
 Returns true, when the function can be usd in parallel threads. More...
 
 AbstractObjectiveFunction ()
 Default ctor. More...
 
virtual ~AbstractObjectiveFunction ()
 Virtual destructor. More...
 
void setRng (random::rng_type *rng)
 Sets the Rng used by the objective function. More...
 
virtual bool hasScalableDimensionality () const
 
virtual void setNumberOfVariables (std::size_t numberOfVariables)
 Adjusts the number of variables if the function is scalable. More...
 
std::size_t evaluationCounter () const
 Accesses the evaluation counter of the function. More...
 
AbstractConstraintHandler< SearchPointType > const & getConstraintHandler () const
 Returns the constraint handler of the function if it has one. More...
 
virtual SearchPointType proposeStartingPoint () const
 Proposes a starting point in the feasible search space of the function. More...
 
ResultType operator() (SearchPointType const &input) const
 Evaluates the function. Useful together with STL-Algorithms like std::transform. More...
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 
virtual std::string name () const
 returns the name of the object More...
 

Additional Inherited Members

- Protected Member Functions inherited from shark::AbstractObjectiveFunction< PointType, ResultT >
void announceConstraintHandler (AbstractConstraintHandler< SearchPointType > const *handler)
 helper function which is called to announce the presence of an constraint handler. More...
 
- Protected Attributes inherited from shark::AbstractObjectiveFunction< PointType, ResultT >
Features m_features
 
std::size_t m_evaluationCounter
 Evaluation counter, default value: 0. More...
 
AbstractConstraintHandler< SearchPointType > const * m_constraintHandler
 
random::rng_type * mep_rng
 

Detailed Description

template<typename PointType, typename ResultT>
class shark::EvaluationArchive< PointType, ResultT >

Objective function wrapper storing all function evaluations.

Template Parameters
PointTypeThe search space the function is defined upon.
ResultTThe objective space the function is defined upon.
The EvaluationArchive class serves as an archive of all evaluated points and the corresponding result. It can be used transparently instead of the original objective function, e.g., by an optimizer. Point/result pairs are added to the archive only if the specific combination is not yet stored.
For fast-to-evaluate objective functions the archive wrapper can be a considerable performance killer. However, whenever function evaluations are costly (and an archive makes sense) then the storage and maintenance overhead should be negligible.

Definition at line 68 of file EvaluationArchive.h.

Member Typedef Documentation

◆ FirstOrderDerivative

template<typename PointType, typename ResultT>
typedef base_type::FirstOrderDerivative shark::EvaluationArchive< PointType, ResultT >::FirstOrderDerivative

Definition at line 75 of file EvaluationArchive.h.

◆ PointResultPairConstIterator

template<typename PointType, typename ResultT>
typedef PointResultPairContainer::const_iterator shark::EvaluationArchive< PointType, ResultT >::PointResultPairConstIterator

Definition at line 118 of file EvaluationArchive.h.

◆ PointResultPairContainer

template<typename PointType, typename ResultT>
typedef std::set<PointResultPairType> shark::EvaluationArchive< PointType, ResultT >::PointResultPairContainer

Definition at line 116 of file EvaluationArchive.h.

◆ PointResultPairIterator

template<typename PointType, typename ResultT>
typedef PointResultPairContainer::iterator shark::EvaluationArchive< PointType, ResultT >::PointResultPairIterator

Definition at line 117 of file EvaluationArchive.h.

◆ ResultType

template<typename PointType, typename ResultT>
typedef base_type::ResultType shark::EvaluationArchive< PointType, ResultT >::ResultType

Definition at line 73 of file EvaluationArchive.h.

◆ SearchPointType

template<typename PointType, typename ResultT>
typedef base_type::SearchPointType shark::EvaluationArchive< PointType, ResultT >::SearchPointType

Definition at line 72 of file EvaluationArchive.h.

◆ SecondOrderDerivative

template<typename PointType, typename ResultT>
typedef base_type::SecondOrderDerivative shark::EvaluationArchive< PointType, ResultT >::SecondOrderDerivative

Definition at line 76 of file EvaluationArchive.h.

Constructor & Destructor Documentation

◆ EvaluationArchive()

template<typename PointType, typename ResultT>
shark::EvaluationArchive< PointType, ResultT >::EvaluationArchive ( base_type objective)
inline

Constructor.

The constructor takes the objective function to be wrapped as an argument. It is assumed that the objective object's life time exceeds the life time of the present instance.

Definition at line 126 of file EvaluationArchive.h.

References shark::AbstractObjectiveFunction< PointType, ResultT >::m_constraintHandler, and shark::AbstractObjectiveFunction< PointType, ResultT >::m_features.

Member Function Documentation

◆ begin() [1/2]

template<typename PointType, typename ResultT>
PointResultPairIterator shark::EvaluationArchive< PointType, ResultT >::begin ( )
inline

Begin iterator to the point/result pairs.

Definition at line 221 of file EvaluationArchive.h.

◆ begin() [2/2]

template<typename PointType, typename ResultT>
PointResultPairConstIterator shark::EvaluationArchive< PointType, ResultT >::begin ( ) const
inline

Begin iterator to the point/result pairs.

Definition at line 225 of file EvaluationArchive.h.

◆ closestFeasible()

template<typename PointType, typename ResultT>
void shark::EvaluationArchive< PointType, ResultT >::closestFeasible ( SearchPointType input) const
inlinevirtual

Wrapper function.

Reimplemented from shark::AbstractObjectiveFunction< PointType, ResultT >.

Definition at line 165 of file EvaluationArchive.h.

◆ end() [1/2]

template<typename PointType, typename ResultT>
PointResultPairIterator shark::EvaluationArchive< PointType, ResultT >::end ( )
inline

End iterator to the point/result pairs.

Definition at line 229 of file EvaluationArchive.h.

◆ end() [2/2]

template<typename PointType, typename ResultT>
PointResultPairConstIterator shark::EvaluationArchive< PointType, ResultT >::end ( ) const
inline

End iterator to the point/result pairs.

Definition at line 233 of file EvaluationArchive.h.

◆ eval()

template<typename PointType, typename ResultT>
ResultType shark::EvaluationArchive< PointType, ResultT >::eval ( const SearchPointType input) const
inlinevirtual

◆ evalDerivative() [1/2]

template<typename PointType, typename ResultT>
ResultType shark::EvaluationArchive< PointType, ResultT >::evalDerivative ( const SearchPointType input,
FirstOrderDerivative derivative 
) const
inlinevirtual

◆ evalDerivative() [2/2]

template<typename PointType, typename ResultT>
ResultType shark::EvaluationArchive< PointType, ResultT >::evalDerivative ( const SearchPointType input,
SecondOrderDerivative derivative 
) const
inlinevirtual

◆ hasScalableObjectives()

template<typename PointType, typename ResultT>
bool shark::EvaluationArchive< PointType, ResultT >::hasScalableObjectives ( ) const
inlinevirtual

Wrapper function.

Reimplemented from shark::AbstractObjectiveFunction< PointType, ResultT >.

Definition at line 153 of file EvaluationArchive.h.

◆ init()

template<typename PointType, typename ResultT>
void shark::EvaluationArchive< PointType, ResultT >::init ( )
inlinevirtual

◆ isFeasible()

template<typename PointType, typename ResultT>
bool shark::EvaluationArchive< PointType, ResultT >::isFeasible ( const SearchPointType input) const
inlinevirtual

Wrapper function.

Reimplemented from shark::AbstractObjectiveFunction< PointType, ResultT >.

Definition at line 161 of file EvaluationArchive.h.

◆ numberOfObjectives()

template<typename PointType, typename ResultT>
virtual std::size_t shark::EvaluationArchive< PointType, ResultT >::numberOfObjectives ( ) const
inlinevirtual

Wrapper function.

Reimplemented from shark::AbstractObjectiveFunction< PointType, ResultT >.

Definition at line 149 of file EvaluationArchive.h.

◆ numberOfVariables()

template<typename PointType, typename ResultT>
std::size_t shark::EvaluationArchive< PointType, ResultT >::numberOfVariables ( ) const
inlinevirtual

Wrapper function; conditional on vector space property.

Implements shark::AbstractObjectiveFunction< PointType, ResultT >.

Definition at line 173 of file EvaluationArchive.h.

◆ objective() [1/2]

template<typename PointType, typename ResultT>
base_type* shark::EvaluationArchive< PointType, ResultT >::objective ( )
inline

Access to the underlying objective function.

Definition at line 135 of file EvaluationArchive.h.

◆ objective() [2/2]

template<typename PointType, typename ResultT>
const base_type* shark::EvaluationArchive< PointType, ResultT >::objective ( ) const
inline

Access to the underlying objective function.

Definition at line 139 of file EvaluationArchive.h.

◆ operator()()

template<typename PointType, typename ResultT>
ResultType shark::EvaluationArchive< PointType, ResultT >::operator() ( const SearchPointType input) const
inline

◆ proposeStartingPoint()

template<typename PointType, typename ResultT>
void shark::EvaluationArchive< PointType, ResultT >::proposeStartingPoint ( SearchPointType startingPoint) const
inline

Wrapper function.

Definition at line 169 of file EvaluationArchive.h.

◆ setNumberOfObjectives()

template<typename PointType, typename ResultT>
void shark::EvaluationArchive< PointType, ResultT >::setNumberOfObjectives ( std::size_t  numberOfObjectives)
inlinevirtual

Wrapper function.

Reimplemented from shark::AbstractObjectiveFunction< PointType, ResultT >.

Definition at line 157 of file EvaluationArchive.h.

◆ size()

template<typename PointType, typename ResultT>
std::size_t shark::EvaluationArchive< PointType, ResultT >::size ( ) const
inline

Return the size of the archive; which is the number of point/result pairs.

Definition at line 217 of file EvaluationArchive.h.


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