shark::LooError< ModelTypeT, LabelType > Class Template Reference

Leave-one-out error objective function. More...

#include <shark/ObjectiveFunctions/LooError.h>

+ Inheritance diagram for shark::LooError< ModelTypeT, LabelType >:

Public Types

typedef ModelTypeT ModelType
 
typedef ModelType::InputType InputType
 
typedef ModelType::OutputType OutputType
 
typedef LabeledData< InputType, LabelType > DatasetType
 
typedef AbstractTrainer< ModelType, LabelType > TrainerType
 
typedef AbstractLoss< LabelType, typename ModelType::OutputType > LossType
 
- Public Types inherited from shark::AbstractObjectiveFunction< RealVector, double >
enum  Feature
 List of features that are supported by an implementation. More...
 
typedef RealVector SearchPointType
 
typedef double ResultType
 
typedef boost::mpl::if_< std::is_arithmetic< double >, 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

 LooError (DatasetType const &dataset, ModelType *model, TrainerType *trainer, LossType *loss, IParameterizable<> *meta=NULL)
 Constructor. More...
 
std::string name () const
 From INameable: return the class name. More...
 
std::size_t numberOfVariables () const
 Accesses the number of variables. More...
 
double eval () const
 
double eval (const RealVector &parameters) const
 
- Public Member Functions inherited from shark::AbstractObjectiveFunction< RealVector, double >
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...
 
virtual void init ()
 
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...
 
virtual std::size_t numberOfObjectives () const
 
virtual bool hasScalableObjectives () const
 
virtual void setNumberOfObjectives (std::size_t numberOfObjectives)
 Adjusts the number of objectives 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 bool isFeasible (const SearchPointType &input) const
 Tests whether a point in SearchSpace is feasible, e.g., whether the constraints are fulfilled. More...
 
virtual void closestFeasible (SearchPointType &input) const
 If supported, the supplied point is repaired such that it satisfies all of the function's constraints. 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...
 
virtual ResultType evalDerivative (SearchPointType const &input, FirstOrderDerivative &derivative) const
 Evaluates the objective function and calculates its gradient. More...
 
virtual ResultType evalDerivative (SearchPointType const &input, SecondOrderDerivative &derivative) const
 Evaluates the objective function and calculates its gradient. More...
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 

Protected Attributes

DataView< DatasetType const > m_dataset
 
IParameterizablemep_meta
 
ModelTypemep_model
 
TrainerTypemep_trainer
 
LossTypemep_loss
 
- Protected Attributes inherited from shark::AbstractObjectiveFunction< RealVector, double >
Features m_features
 
std::size_t m_evaluationCounter
 Evaluation counter, default value: 0. More...
 
AbstractConstraintHandler< SearchPointType > const * m_constraintHandler
 
random::rng_type * mep_rng
 

Additional Inherited Members

- Protected Member Functions inherited from shark::AbstractObjectiveFunction< RealVector, double >
void announceConstraintHandler (AbstractConstraintHandler< SearchPointType > const *handler)
 helper function which is called to announce the presence of an constraint handler. More...
 

Detailed Description

template<class ModelTypeT, class LabelType = typename ModelTypeT::OutputType>
class shark::LooError< ModelTypeT, LabelType >

Leave-one-out error objective function.

The leave-one-out measure is the average prediction performance of a learning machine on a dataset, where each sample is predicted by a machine trained on all but the sample to be predicted. This is an extreme form of cross-validation, with a fold size of one.
In general the leave-one-out error is costly to compute, since it requires training of a large number of learning machines. However, certain machines allow for a more efficient implementation. Refer to LooErrorCSvm for an example.

Definition at line 63 of file LooError.h.

Member Typedef Documentation

◆ DatasetType

template<class ModelTypeT , class LabelType = typename ModelTypeT::OutputType>
typedef LabeledData<InputType, LabelType> shark::LooError< ModelTypeT, LabelType >::DatasetType

Definition at line 69 of file LooError.h.

◆ InputType

template<class ModelTypeT , class LabelType = typename ModelTypeT::OutputType>
typedef ModelType::InputType shark::LooError< ModelTypeT, LabelType >::InputType

Definition at line 67 of file LooError.h.

◆ LossType

template<class ModelTypeT , class LabelType = typename ModelTypeT::OutputType>
typedef AbstractLoss<LabelType, typename ModelType::OutputType> shark::LooError< ModelTypeT, LabelType >::LossType

Definition at line 71 of file LooError.h.

◆ ModelType

template<class ModelTypeT , class LabelType = typename ModelTypeT::OutputType>
typedef ModelTypeT shark::LooError< ModelTypeT, LabelType >::ModelType

Definition at line 66 of file LooError.h.

◆ OutputType

template<class ModelTypeT , class LabelType = typename ModelTypeT::OutputType>
typedef ModelType::OutputType shark::LooError< ModelTypeT, LabelType >::OutputType

Definition at line 68 of file LooError.h.

◆ TrainerType

template<class ModelTypeT , class LabelType = typename ModelTypeT::OutputType>
typedef AbstractTrainer<ModelType, LabelType> shark::LooError< ModelTypeT, LabelType >::TrainerType

Definition at line 70 of file LooError.h.

Constructor & Destructor Documentation

◆ LooError()

template<class ModelTypeT , class LabelType = typename ModelTypeT::OutputType>
shark::LooError< ModelTypeT, LabelType >::LooError ( DatasetType const &  dataset,
ModelType model,
TrainerType trainer,
LossType loss,
IParameterizable<> *  meta = NULL 
)
inline

Constructor.

Parameters
datasetFull data set for leave-one-out.
modelModel built on subsets of the data.
trainerTrainer for learning on each subset.
lossLoss function for judging the validation output.
metaMeta object with parameters that influences the process, typically a trainer.

Definition at line 82 of file LooError.h.

References shark::AbstractObjectiveFunction< RealVector, double >::HAS_VALUE, and shark::AbstractObjectiveFunction< RealVector, double >::m_features.

Member Function Documentation

◆ eval() [1/2]

template<class ModelTypeT , class LabelType = typename ModelTypeT::OutputType>
double shark::LooError< ModelTypeT, LabelType >::eval ( ) const
inline

Evaluate the leave-one-out error: train sub-models, evaluate objective, return the average.

Definition at line 114 of file LooError.h.

References shark::LooError< ModelTypeT, LabelType >::m_dataset, and shark::AbstractObjectiveFunction< RealVector, double >::m_evaluationCounter.

Referenced by shark::LooError< ModelTypeT, LabelType >::eval().

◆ eval() [2/2]

template<class ModelTypeT , class LabelType = typename ModelTypeT::OutputType>
double shark::LooError< ModelTypeT, LabelType >::eval ( const RealVector &  parameters) const
inlinevirtual

Evaluate the leave-one-out error for the given parameters passed to the meta object (typically these parameters need to be optimized in a model selection procedure).

Reimplemented from shark::AbstractObjectiveFunction< RealVector, double >.

Definition at line 138 of file LooError.h.

References shark::LooError< ModelTypeT, LabelType >::eval(), shark::LooError< ModelTypeT, LabelType >::mep_meta, shark::IParameterizable< VectorType >::setParameterVector(), and SHARK_ASSERT.

◆ name()

template<class ModelTypeT , class LabelType = typename ModelTypeT::OutputType>
std::string shark::LooError< ModelTypeT, LabelType >::name ( ) const
inlinevirtual

◆ numberOfVariables()

template<class ModelTypeT , class LabelType = typename ModelTypeT::OutputType>
std::size_t shark::LooError< ModelTypeT, LabelType >::numberOfVariables ( ) const
inlinevirtual

Member Data Documentation

◆ m_dataset

template<class ModelTypeT , class LabelType = typename ModelTypeT::OutputType>
DataView<DatasetType const> shark::LooError< ModelTypeT, LabelType >::m_dataset
protected

Definition at line 144 of file LooError.h.

Referenced by shark::LooError< ModelTypeT, LabelType >::eval().

◆ mep_loss

template<class ModelTypeT , class LabelType = typename ModelTypeT::OutputType>
LossType* shark::LooError< ModelTypeT, LabelType >::mep_loss
protected

Definition at line 148 of file LooError.h.

Referenced by shark::LooError< ModelTypeT, LabelType >::name().

◆ mep_meta

template<class ModelTypeT , class LabelType = typename ModelTypeT::OutputType>
IParameterizable* shark::LooError< ModelTypeT, LabelType >::mep_meta
protected

◆ mep_model

template<class ModelTypeT , class LabelType = typename ModelTypeT::OutputType>
ModelType* shark::LooError< ModelTypeT, LabelType >::mep_model
protected

Definition at line 146 of file LooError.h.

Referenced by shark::LooError< ModelTypeT, LabelType >::name().

◆ mep_trainer

template<class ModelTypeT , class LabelType = typename ModelTypeT::OutputType>
TrainerType* shark::LooError< ModelTypeT, LabelType >::mep_trainer
protected

Definition at line 147 of file LooError.h.

Referenced by shark::LooError< ModelTypeT, LabelType >::name().


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