Base class for all Models. More...
#include <shark/Models/AbstractModel.h>
Public Types | |
enum | Feature { HAS_FIRST_PARAMETER_DERIVATIVE = 1 , HAS_FIRST_INPUT_DERIVATIVE = 4 } |
typedef InputTypeT | InputType |
Defines the input type of the model. | |
typedef OutputTypeT | OutputType |
Defines the output type of the model. | |
typedef AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType > | ModelBaseType |
Defines the BaseType used by the model (this type). Useful for creating derived models. | |
typedef Batch< InputType >::type | BatchInputType |
defines the batch type of the input type. | |
typedef Batch< OutputType >::type | BatchOutputType |
defines the batch type of the output type | |
typedef TypedFlags< Feature > | Features |
typedef TypedFeatureNotAvailableException< Feature > | FeatureNotAvailableException |
Public Types inherited from shark::IParameterizable< VectorType > | |
typedef VectorType | ParameterVectorType |
Public Member Functions | |
AbstractModel () | |
virtual | ~AbstractModel () |
const Features & | features () const |
virtual void | updateFeatures () |
bool | hasFirstParameterDerivative () const |
Returns true when the first parameter derivative is implemented. | |
bool | hasFirstInputDerivative () const |
Returns true when the first input derivative is implemented. | |
virtual Shape | inputShape () const =0 |
Returns the expected shape of the input. | |
virtual Shape | outputShape () const =0 |
Returns the shape of the output. | |
virtual boost::shared_ptr< State > | createState () const |
Creates an internal state of the model. | |
virtual void | read (InArchive &archive) |
From ISerializable, reads a model from an archive. | |
virtual void | write (OutArchive &archive) const |
writes a model to an archive | |
virtual void | eval (BatchInputType const &patterns, BatchOutputType &outputs) const |
Standard interface for evaluating the response of the model to a batch of patterns. | |
virtual void | eval (BatchInputType const &patterns, BatchOutputType &outputs, State &state) const =0 |
Standard interface for evaluating the response of the model to a batch of patterns. | |
virtual void | eval (InputType const &pattern, OutputType &output) const |
Standard interface for evaluating the response of the model to a single pattern. | |
Data< OutputType > | operator() (Data< InputType > const &patterns) const |
Model evaluation as an operator for a whole dataset. This is a convenience function. | |
OutputType | operator() (InputType const &pattern) const |
Model evaluation as an operator for a single pattern. This is a convenience function. | |
BatchOutputType | operator() (BatchInputType const &patterns) const |
Model evaluation as an operator for a single pattern. This is a convenience function. | |
virtual void | weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, ParameterVectorType &derivative) const |
calculates the weighted sum of derivatives w.r.t the parameters. | |
virtual void | weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const |
calculates the weighted sum of derivatives w.r.t the inputs | |
virtual void | weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, ParameterVectorType ¶meterDerivative, BatchInputType &inputDerivative) const |
calculates weighted input and parameter derivative at the same time | |
Public Member Functions inherited from shark::IParameterizable< VectorType > | |
virtual | ~IParameterizable () |
virtual ParameterVectorType | parameterVector () const |
Return the parameter vector. | |
virtual void | setParameterVector (ParameterVectorType const &newParameters) |
Set the parameter vector. | |
virtual std::size_t | numberOfParameters () const |
Return the number of parameters. | |
Public Member Functions inherited from shark::INameable | |
virtual | ~INameable () |
virtual std::string | name () const |
returns the name of the object | |
Public Member Functions inherited from shark::ISerializable | |
virtual | ~ISerializable () |
Virtual d'tor. | |
void | load (InArchive &archive, unsigned int version) |
Versioned loading of components, calls read(...). | |
void | save (OutArchive &archive, unsigned int version) const |
Versioned storing of components, calls write(...). | |
BOOST_SERIALIZATION_SPLIT_MEMBER () | |
Protected Attributes | |
Features | m_features |
Base class for all Models.
Definition at line 81 of file AbstractModel.h.
typedef Batch<InputType>::type shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::BatchInputType |
defines the batch type of the input type.
This could for example be std::vector<InputType> but for example for RealVector it could be RealMatrix
Definition at line 97 of file AbstractModel.h.
typedef Batch<OutputType>::type shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::BatchOutputType |
defines the batch type of the output type
Definition at line 99 of file AbstractModel.h.
typedef TypedFeatureNotAvailableException<Feature> shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::FeatureNotAvailableException |
Definition at line 110 of file AbstractModel.h.
typedef TypedFlags<Feature> shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::Features |
Definition at line 110 of file AbstractModel.h.
typedef InputTypeT shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::InputType |
Defines the input type of the model.
Definition at line 85 of file AbstractModel.h.
typedef AbstractModel<InputTypeT,OutputTypeT,ParameterVectorType> shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::ModelBaseType |
Defines the BaseType used by the model (this type). Useful for creating derived models.
Definition at line 92 of file AbstractModel.h.
typedef OutputTypeT shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::OutputType |
Defines the output type of the model.
Definition at line 87 of file AbstractModel.h.
enum shark::AbstractModel::Feature |
Enumerator | |
---|---|
HAS_FIRST_PARAMETER_DERIVATIVE | |
HAS_FIRST_INPUT_DERIVATIVE |
Definition at line 106 of file AbstractModel.h.
|
inline |
Definition at line 102 of file AbstractModel.h.
|
inlinevirtual |
Definition at line 104 of file AbstractModel.h.
|
inlinevirtual |
Creates an internal state of the model.
The state is needed when the derivatives are to be calculated. Eval can store a state which is then reused to speed up the calculations of the derivatives. This also allows eval to be evaluated in parallel!
Reimplemented in shark::CMACMap, shark::ConcatenatedModel< VectorType >, shark::Conv2DModel< VectorType, ActivationFunction >, shark::DropoutLayer< VectorType >, shark::KernelExpansion< InputType >, shark::MissingFeaturesKernelExpansion< InputType >, shark::LinearModel< InputType, ActivationFunction >, shark::LinearModel< RealVector >, shark::NeuronLayer< NeuronType, VectorType >, shark::Normalizer< VectorType >, shark::OneVersusOneClassifier< InputType, VectorType >, shark::PoolingLayer< VectorType >, shark::RBFLayer, shark::ResizeLayer< VectorType >, shark::CARTree< LabelType >, and shark::RBM< VisibleLayerT, HiddenLayerT, randomT >.
Definition at line 132 of file AbstractModel.h.
References shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::hasFirstInputDerivative(), shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::hasFirstParameterDerivative(), and SHARKEXCEPTION.
Referenced by shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::eval(), shark::NegativeLogLikelihood::evalDerivative(), and shark::VariationalAutoencoderError< SearchPointType >::evalDerivative().
|
inlinevirtual |
Standard interface for evaluating the response of the model to a batch of patterns.
patterns | the inputs of the model |
outputs | the predictions or response of the model to every pattern |
Reimplemented in shark::Normalizer< VectorType >, shark::DropoutLayer< VectorType >, shark::LinearModel< InputType, ActivationFunction >, shark::NeuronLayer< NeuronType, VectorType >, shark::KernelExpansion< InputType >, shark::ConcatenatedModel< VectorType >, shark::MissingFeaturesKernelExpansion< InputType >, shark::LinearModel< InputType, ActivationFunction >, shark::OneVersusOneClassifier< InputType, VectorType >, shark::CARTree< LabelType >, and shark::RBM< VisibleLayerT, HiddenLayerT, randomT >.
Definition at line 163 of file AbstractModel.h.
References shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::createState(), and shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::eval().
Referenced by shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::eval(), shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::eval(), shark::NegativeLogLikelihood::evalDerivative(), shark::VariationalAutoencoderError< SearchPointType >::evalDerivative(), shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::operator()(), and shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::operator()().
|
pure virtual |
Standard interface for evaluating the response of the model to a batch of patterns.
patterns | the inputs of the model |
outputs | the predictions or response of the model to every pattern |
state | intermediate results stored by eval which can be reused for derivative computation. |
Implemented in shark::Normalizer< VectorType >, shark::ResizeLayer< VectorType >, shark::Conv2DModel< VectorType, ActivationFunction >, shark::DropoutLayer< VectorType >, shark::LinearModel< InputType, ActivationFunction >, shark::NeuronLayer< NeuronType, VectorType >, shark::PoolingLayer< VectorType >, shark::OneVersusOneClassifier< InputType, VectorType >, shark::ClusteringModel< InputT, OutputT >, shark::ConcatenatedModel< VectorType >, shark::KernelExpansion< InputType >, shark::MissingFeaturesKernelExpansion< InputType >, shark::RBFLayer, shark::CARTree< LabelType >, shark::RBM< VisibleLayerT, HiddenLayerT, randomT >, shark::LinearModel< InputType, ActivationFunction >, and shark::OneVersusOneClassifier< InputType, VectorType >.
|
inlinevirtual |
Standard interface for evaluating the response of the model to a single pattern.
pattern | the input of the model |
output | the prediction or response of the model to the pattern |
Reimplemented in shark::Classifier< Model >, shark::Classifier< detail::BaseNearestNeighbor< InputType, unsigned int > >, shark::Classifier< KernelExpansion< InputType > >, shark::Classifier< LinearModel< RealVector > >, shark::HardClusteringModel< InputT >, shark::SoftClusteringModel< InputT >, shark::LinearModel< InputType, ActivationFunction >, and shark::OneVersusOneClassifier< InputType, VectorType >.
Definition at line 179 of file AbstractModel.h.
References shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::eval(), and shark::getBatchElement().
|
inline |
Definition at line 110 of file AbstractModel.h.
|
inline |
Returns true when the first input derivative is implemented.
Definition at line 117 of file AbstractModel.h.
References shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::HAS_FIRST_INPUT_DERIVATIVE, and shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::m_features.
Referenced by shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::createState().
|
inline |
Returns true when the first parameter derivative is implemented.
Definition at line 113 of file AbstractModel.h.
References shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::HAS_FIRST_PARAMETER_DERIVATIVE, and shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::m_features.
Referenced by shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::createState(), shark::NegativeLogLikelihood::NegativeLogLikelihood(), and shark::VariationalAutoencoderError< SearchPointType >::VariationalAutoencoderError().
|
pure virtual |
Returns the expected shape of the input.
Implemented in shark::Classifier< Model >, shark::Classifier< detail::BaseNearestNeighbor< InputType, unsigned int > >, shark::Classifier< KernelExpansion< InputType > >, shark::Classifier< LinearModel< RealVector > >, shark::HardClusteringModel< InputT >, shark::SoftClusteringModel< InputT >, shark::CMACMap, shark::ConcatenatedModel< VectorType >, shark::Conv2DModel< VectorType, ActivationFunction >, shark::DropoutLayer< VectorType >, shark::KernelExpansion< InputType >, shark::LinearModel< InputType, ActivationFunction >, shark::LinearModel< RealVector >, shark::NeuronLayer< NeuronType, VectorType >, shark::Normalizer< VectorType >, shark::OneVersusOneClassifier< InputType, VectorType >, shark::PoolingLayer< VectorType >, shark::RBFLayer, shark::ResizeLayer< VectorType >, shark::CARTree< LabelType >, and shark::RBM< VisibleLayerT, HiddenLayerT, randomT >.
|
inline |
Model evaluation as an operator for a single pattern. This is a convenience function.
patterns | the input of the model |
Definition at line 209 of file AbstractModel.h.
References shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::eval().
|
inline |
Model evaluation as an operator for a whole dataset. This is a convenience function.
patterns | the input of the model |
Definition at line 191 of file AbstractModel.h.
References shark::transform().
|
inline |
Model evaluation as an operator for a single pattern. This is a convenience function.
pattern | the input of the model |
Definition at line 199 of file AbstractModel.h.
References shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::eval().
|
pure virtual |
Returns the shape of the output.
Implemented in shark::Classifier< Model >, shark::Classifier< detail::BaseNearestNeighbor< InputType, unsigned int > >, shark::Classifier< KernelExpansion< InputType > >, shark::Classifier< LinearModel< RealVector > >, shark::HardClusteringModel< InputT >, shark::SoftClusteringModel< InputT >, shark::CMACMap, shark::ConcatenatedModel< VectorType >, shark::Conv2DModel< VectorType, ActivationFunction >, shark::DropoutLayer< VectorType >, shark::KernelExpansion< InputType >, shark::LinearModel< InputType, ActivationFunction >, shark::LinearModel< RealVector >, shark::NeuronLayer< NeuronType, VectorType >, shark::Normalizer< VectorType >, shark::OneVersusOneClassifier< InputType, VectorType >, shark::PoolingLayer< VectorType >, shark::RBFLayer, shark::ResizeLayer< VectorType >, shark::CARTree< LabelType >, and shark::RBM< VisibleLayerT, HiddenLayerT, randomT >.
|
inlinevirtual |
From ISerializable, reads a model from an archive.
Reimplemented from shark::ISerializable.
Reimplemented in shark::Classifier< Model >, shark::Classifier< detail::BaseNearestNeighbor< InputType, unsigned int > >, shark::Classifier< KernelExpansion< InputType > >, shark::Classifier< LinearModel< RealVector > >, shark::ClusteringModel< InputT, OutputT >, shark::ClusteringModel< InputT, RealVector >, shark::ClusteringModel< InputT, unsigned int >, shark::CMACMap, shark::ConcatenatedModel< VectorType >, shark::Conv2DModel< VectorType, ActivationFunction >, shark::DropoutLayer< VectorType >, shark::KernelExpansion< InputType >, shark::LinearModel< InputType, ActivationFunction >, shark::LinearModel< RealVector >, shark::NeuronLayer< NeuronType, VectorType >, shark::Normalizer< VectorType >, shark::OneVersusOneClassifier< InputType, VectorType >, shark::PoolingLayer< VectorType >, shark::RBFLayer, shark::ResizeLayer< VectorType >, shark::CARTree< LabelType >, and shark::RBM< VisibleLayerT, HiddenLayerT, randomT >.
Definition at line 143 of file AbstractModel.h.
References shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::m_features, shark::TypedFlags< Flag >::read(), and shark::IParameterizable< VectorType >::setParameterVector().
|
inlinevirtual |
Definition at line 110 of file AbstractModel.h.
|
inlinevirtual |
calculates weighted input and parameter derivative at the same time
Sometimes, both derivatives are needed at the same time. But sometimes, when calculating the weighted parameter derivative, the input derivative can be calculated for free. This is for example true for the feed-forward neural networks. However, there exists the obvious default implementation that just calculates the derivatives one after another.
patterns | the patterns to evaluate |
outputs | the target outputs |
coefficients | the coefficients which are used to calculate the weighted sum |
state | intermediate results stored by eval to sped up calculations of the derivatives |
parameterDerivative | the calculated parameter derivative as sum over all derivates of all patterns |
inputDerivative | the calculated derivative for every pattern |
Reimplemented in shark::ConcatenatedModel< VectorType >.
Definition at line 261 of file AbstractModel.h.
References shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::weightedInputDerivative(), and shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::weightedParameterDerivative().
Referenced by shark::VariationalAutoencoderError< SearchPointType >::evalDerivative().
|
inlinevirtual |
calculates the weighted sum of derivatives w.r.t the inputs
pattern | the patterns to evaluate |
outputs | the target outputs |
coefficients | the coefficients which are used to calculate the weighted sum for every pattern |
state | intermediate results stored by eval to sped up calculations of the derivatives |
derivative | the calculated derivative for every pattern |
Reimplemented in shark::NeuronLayer< NeuronType, VectorType >, shark::PoolingLayer< VectorType >, shark::Conv2DModel< VectorType, ActivationFunction >, shark::ResizeLayer< VectorType >, and shark::DropoutLayer< VectorType >.
Definition at line 239 of file AbstractModel.h.
References shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::HAS_FIRST_INPUT_DERIVATIVE, and SHARK_FEATURE_EXCEPTION.
Referenced by shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::weightedDerivatives().
|
inlinevirtual |
calculates the weighted sum of derivatives w.r.t the parameters.
pattern | the patterns to evaluate |
outputs | the target outputs |
coefficients | the coefficients which are used to calculate the weighted sum for every pattern |
state | intermediate results stored by eval to speed up calculations of the derivatives |
derivative | the calculated derivative as sum over all derivates of all patterns |
Reimplemented in shark::Conv2DModel< VectorType, ActivationFunction >, shark::NeuronLayer< NeuronType, VectorType >, shark::PoolingLayer< VectorType >, shark::ResizeLayer< VectorType >, shark::RBFLayer, shark::ConcatenatedModel< VectorType >, and shark::DropoutLayer< VectorType >.
Definition at line 222 of file AbstractModel.h.
References shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::HAS_FIRST_PARAMETER_DERIVATIVE, and SHARK_FEATURE_EXCEPTION.
Referenced by shark::NegativeLogLikelihood::evalDerivative(), shark::VariationalAutoencoderError< SearchPointType >::evalDerivative(), and shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::weightedDerivatives().
|
inlinevirtual |
writes a model to an archive
the default implementation just saves the parameters, not the structure!
Reimplemented from shark::ISerializable.
Reimplemented in shark::Classifier< Model >, shark::Classifier< detail::BaseNearestNeighbor< InputType, unsigned int > >, shark::Classifier< KernelExpansion< InputType > >, shark::Classifier< LinearModel< RealVector > >, shark::ClusteringModel< InputT, OutputT >, shark::ClusteringModel< InputT, RealVector >, shark::ClusteringModel< InputT, unsigned int >, shark::CMACMap, shark::ConcatenatedModel< VectorType >, shark::Conv2DModel< VectorType, ActivationFunction >, shark::DropoutLayer< VectorType >, shark::KernelExpansion< InputType >, shark::LinearModel< InputType, ActivationFunction >, shark::LinearModel< RealVector >, shark::NeuronLayer< NeuronType, VectorType >, shark::Normalizer< VectorType >, shark::OneVersusOneClassifier< InputType, VectorType >, shark::PoolingLayer< VectorType >, shark::RBFLayer, shark::ResizeLayer< VectorType >, shark::CARTree< LabelType >, and shark::RBM< VisibleLayerT, HiddenLayerT, randomT >.
Definition at line 153 of file AbstractModel.h.
References shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::m_features, shark::IParameterizable< VectorType >::parameterVector(), and shark::TypedFlags< Flag >::write().
|
protected |
Definition at line 110 of file AbstractModel.h.
Referenced by shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::hasFirstInputDerivative(), shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::hasFirstParameterDerivative(), shark::LinearModel< InputType, ActivationFunction >::LinearModel(), shark::LinearModel< InputType, ActivationFunction >::LinearModel(), shark::LinearModel< InputType, ActivationFunction >::LinearModel(), shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::read(), and shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >::write().