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. More... | |
typedef OutputTypeT | OutputType |
Defines the output type of the model. More... | |
typedef AbstractModel< InputTypeT, OutputTypeT, ParameterType > | ModelBaseType |
Defines the BaseType used by the model (this type). Useful for creating derived models. More... | |
typedef Batch< InputType >::type | BatchInputType |
defines the batch type of the input type. More... | |
typedef Batch< OutputType >::type | BatchOutputType |
defines the batch type of the output type More... | |
typedef TypedFlags< Feature > | Features |
typedef TypedFeatureNotAvailableException< Feature > | FeatureNotAvailableException |
Public Types inherited from shark::IParameterizable< ParameterType > | |
typedef ParameterType | 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. More... | |
bool | hasFirstInputDerivative () const |
Returns true when the first input derivative is implemented. More... | |
virtual Shape | inputShape () const =0 |
Returns the expected shape of the input. More... | |
virtual Shape | outputShape () const =0 |
Returns the shape of the output. More... | |
virtual boost::shared_ptr< State > | createState () const |
Creates an internal state of the model. More... | |
virtual void | read (InArchive &archive) |
From ISerializable, reads a model from an archive. More... | |
virtual void | write (OutArchive &archive) const |
writes a model to an archive More... | |
virtual void | eval (BatchInputType const &patterns, BatchOutputType &outputs) const |
Standard interface for evaluating the response of the model to a batch of patterns. More... | |
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. More... | |
virtual void | eval (InputType const &pattern, OutputType &output) const |
Standard interface for evaluating the response of the model to a single pattern. More... | |
Data< OutputType > | operator() (Data< InputType > const &patterns) const |
Model evaluation as an operator for a whole dataset. This is a convenience function. More... | |
OutputType | operator() (InputType const &pattern) const |
Model evaluation as an operator for a single pattern. This is a convenience function. More... | |
BatchOutputType | operator() (BatchInputType const &patterns) const |
Model evaluation as an operator for a single pattern. This is a convenience function. More... | |
virtual void | weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, RealVector &derivative) const |
calculates the weighted sum of derivatives w.r.t the parameters. More... | |
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 More... | |
virtual void | weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, RealVector ¶meterDerivative, BatchInputType &inputDerivative) const |
calculates weighted input and parameter derivative at the same time More... | |
Public Member Functions inherited from shark::IParameterizable< ParameterType > | |
virtual | ~IParameterizable () |
virtual ParameterVectorType | parameterVector () const |
Return the parameter vector. More... | |
virtual void | setParameterVector (ParameterVectorType const &newParameters) |
Set the parameter vector. More... | |
virtual std::size_t | numberOfParameters () const |
Return the number of parameters. More... | |
Public Member Functions inherited from shark::INameable | |
virtual | ~INameable () |
virtual std::string | name () const |
returns the name of the object More... | |
Public Member Functions inherited from shark::ISerializable | |
virtual | ~ISerializable () |
Virtual d'tor. More... | |
void | load (InArchive &archive, unsigned int version) |
Versioned loading of components, calls read(...). More... | |
void | save (OutArchive &archive, unsigned int version) const |
Versioned storing of components, calls write(...). More... | |
BOOST_SERIALIZATION_SPLIT_MEMBER () | |
Protected Attributes | |
Features | m_features |
Base class for all Models.
Definition at line 80 of file AbstractModel.h.
typedef Batch<InputType>::type shark::AbstractModel< InputTypeT, OutputTypeT, ParameterType >::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 96 of file AbstractModel.h.
typedef Batch<OutputType>::type shark::AbstractModel< InputTypeT, OutputTypeT, ParameterType >::BatchOutputType |
defines the batch type of the output type
Definition at line 98 of file AbstractModel.h.
typedef TypedFeatureNotAvailableException<Feature> shark::AbstractModel< InputTypeT, OutputTypeT, ParameterType >::FeatureNotAvailableException |
Definition at line 109 of file AbstractModel.h.
typedef TypedFlags<Feature> shark::AbstractModel< InputTypeT, OutputTypeT, ParameterType >::Features |
Definition at line 109 of file AbstractModel.h.
typedef InputTypeT shark::AbstractModel< InputTypeT, OutputTypeT, ParameterType >::InputType |
Defines the input type of the model.
Definition at line 84 of file AbstractModel.h.
typedef AbstractModel<InputTypeT,OutputTypeT,ParameterType> shark::AbstractModel< InputTypeT, OutputTypeT, ParameterType >::ModelBaseType |
Defines the BaseType used by the model (this type). Useful for creating derived models.
Definition at line 91 of file AbstractModel.h.
typedef OutputTypeT shark::AbstractModel< InputTypeT, OutputTypeT, ParameterType >::OutputType |
Defines the output type of the model.
Definition at line 86 of file AbstractModel.h.
enum shark::AbstractModel::Feature |
Enumerator | |
---|---|
HAS_FIRST_PARAMETER_DERIVATIVE | |
HAS_FIRST_INPUT_DERIVATIVE |
Definition at line 105 of file AbstractModel.h.
|
inline |
Definition at line 101 of file AbstractModel.h.
|
inlinevirtual |
Definition at line 103 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::NeuronLayer< NeuronType, VectorType >, shark::KernelExpansion< InputType >, shark::RBM< VisibleLayerT, HiddenLayerT, randomT >, shark::LinearModel< InputType, ActivationFunction >, shark::LinearModel< VectorType >, shark::Conv2DModel< VectorType, ActivationFunction >, shark::OneVersusOneClassifier< InputType, VectorType >, shark::ConcatenatedModel< VectorType >, shark::CMACMap, shark::RBFLayer, shark::DropoutLayer< VectorType >, shark::CARTree< LabelType >, shark::CARTree< unsigned int >, shark::Normalizer< VectorType >, and shark::MissingFeaturesKernelExpansion< InputType >.
Definition at line 131 of file AbstractModel.h.
Referenced by shark::AbstractModel< InputT, unsigned int >::eval().
|
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::NeuronLayer< NeuronType, VectorType >, shark::RBM< VisibleLayerT, HiddenLayerT, randomT >, shark::KernelExpansion< InputType >, shark::LinearModel< InputType, ActivationFunction >, shark::LinearModel< VectorType >, shark::ConcatenatedModel< VectorType >, shark::Normalizer< VectorType >, shark::Classifier< detail::BaseNearestNeighbor< InputType, unsigned int > >, shark::Classifier< LinearModel< VectorType > >, shark::Classifier< MeanModel< CARTree< unsigned int > > >, shark::Classifier< KernelExpansion< InputType > >, shark::DropoutLayer< VectorType >, shark::CARTree< LabelType >, shark::CARTree< unsigned int >, shark::MeanModel< ModelType >, shark::MeanModel< CARTree< LabelType > >, shark::MeanModel< CARTree< unsigned int > >, and shark::MissingFeaturesKernelExpansion< InputType >.
Definition at line 162 of file AbstractModel.h.
Referenced by shark::LinearModel< VectorType >::createState(), shark::AbstractModel< InputT, unsigned int >::eval(), shark::AbstractModel< InputT, unsigned int >::operator()(), and shark::MeanModel< CARTree< unsigned int > >::outputShape().
|
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::NeuronLayer< NeuronType, VectorType >, shark::KernelExpansion< InputType >, shark::RBM< VisibleLayerT, HiddenLayerT, randomT >, shark::LinearModel< InputType, ActivationFunction >, shark::LinearModel< VectorType >, shark::ConcatenatedModel< VectorType >, shark::Conv2DModel< VectorType, ActivationFunction >, shark::OneVersusOneClassifier< InputType, VectorType >, shark::Normalizer< VectorType >, shark::Classifier< detail::BaseNearestNeighbor< InputType, unsigned int > >, shark::Classifier< LinearModel< VectorType > >, shark::Classifier< MeanModel< CARTree< unsigned int > > >, shark::Classifier< KernelExpansion< InputType > >, shark::RBFLayer, shark::DropoutLayer< VectorType >, shark::MissingFeaturesKernelExpansion< InputType >, shark::CARTree< LabelType >, shark::CARTree< unsigned int >, shark::MeanModel< ModelType >, shark::MeanModel< CARTree< LabelType > >, shark::MeanModel< CARTree< unsigned int > >, shark::ClusteringModel< InputT, OutputT >, shark::ClusteringModel< InputT, RealVector >, and shark::ClusteringModel< InputT, unsigned int >.
|
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::NeuronLayer< NeuronType, VectorType >, shark::Classifier< Model >, shark::Classifier< detail::BaseNearestNeighbor< InputType, unsigned int > >, shark::Classifier< LinearModel< VectorType > >, shark::Classifier< MeanModel< CARTree< unsigned int > > >, shark::Classifier< KernelExpansion< InputType > >, shark::DropoutLayer< VectorType >, shark::SoftClusteringModel< InputT >, and shark::HardClusteringModel< InputT >.
Definition at line 178 of file AbstractModel.h.
|
inline |
Definition at line 109 of file AbstractModel.h.
|
inline |
Returns true when the first input derivative is implemented.
Definition at line 116 of file AbstractModel.h.
Referenced by shark::AbstractModel< InputT, unsigned int >::createState().
|
inline |
Returns true when the first parameter derivative is implemented.
Definition at line 112 of file AbstractModel.h.
Referenced by shark::AbstractModel< InputT, unsigned int >::createState(), shark::NegativeLogLikelihood::NegativeLogLikelihood(), and shark::VariationalAutoencoderError::VariationalAutoencoderError().
|
pure virtual |
Returns the expected shape of the input.
Implemented in shark::NeuronLayer< NeuronType, VectorType >, shark::RBM< VisibleLayerT, HiddenLayerT, randomT >, shark::CARTree< LabelType >, shark::CARTree< unsigned int >, shark::LinearModel< InputType, ActivationFunction >, shark::LinearModel< VectorType >, shark::OneVersusOneClassifier< InputType, VectorType >, shark::KernelExpansion< InputType >, shark::CMACMap, shark::Conv2DModel< VectorType, ActivationFunction >, shark::RBFLayer, shark::Classifier< Model >, shark::Classifier< detail::BaseNearestNeighbor< InputType, unsigned int > >, shark::Classifier< LinearModel< VectorType > >, shark::Classifier< MeanModel< CARTree< unsigned int > > >, shark::Classifier< KernelExpansion< InputType > >, shark::Normalizer< VectorType >, shark::DropoutLayer< VectorType >, shark::SoftClusteringModel< InputT >, shark::MeanModel< ModelType >, shark::MeanModel< CARTree< LabelType > >, shark::MeanModel< CARTree< unsigned int > >, shark::HardClusteringModel< InputT >, and shark::ConcatenatedModel< VectorType >.
Referenced by shark::AbstractModel< InputT, unsigned int >::hasFirstInputDerivative().
|
inline |
Model evaluation as an operator for a whole dataset. This is a convenience function.
patterns | the input of the model |
Definition at line 190 of file AbstractModel.h.
|
inline |
Model evaluation as an operator for a single pattern. This is a convenience function.
pattern | the input of the model |
Definition at line 198 of file AbstractModel.h.
|
inline |
Model evaluation as an operator for a single pattern. This is a convenience function.
patterns | the input of the model |
Definition at line 208 of file AbstractModel.h.
|
pure virtual |
Returns the shape of the output.
Implemented in shark::NeuronLayer< NeuronType, VectorType >, shark::RBM< VisibleLayerT, HiddenLayerT, randomT >, shark::CARTree< LabelType >, shark::CARTree< unsigned int >, shark::LinearModel< InputType, ActivationFunction >, shark::LinearModel< VectorType >, shark::OneVersusOneClassifier< InputType, VectorType >, shark::CMACMap, shark::Conv2DModel< VectorType, ActivationFunction >, shark::KernelExpansion< InputType >, shark::RBFLayer, shark::Classifier< Model >, shark::Classifier< detail::BaseNearestNeighbor< InputType, unsigned int > >, shark::Classifier< LinearModel< VectorType > >, shark::Classifier< MeanModel< CARTree< unsigned int > > >, shark::Classifier< KernelExpansion< InputType > >, shark::Normalizer< VectorType >, shark::DropoutLayer< VectorType >, shark::SoftClusteringModel< InputT >, shark::MeanModel< ModelType >, shark::MeanModel< CARTree< LabelType > >, shark::MeanModel< CARTree< unsigned int > >, shark::HardClusteringModel< InputT >, and shark::ConcatenatedModel< VectorType >.
Referenced by shark::AbstractModel< InputT, unsigned int >::hasFirstInputDerivative(), and shark::initRandomUniform().
|
inlinevirtual |
From ISerializable, reads a model from an archive.
Reimplemented from shark::ISerializable.
Reimplemented in shark::NeuronLayer< NeuronType, VectorType >, shark::LinearModel< InputType, ActivationFunction >, shark::LinearModel< VectorType >, shark::RBM< VisibleLayerT, HiddenLayerT, randomT >, shark::ConcatenatedModel< VectorType >, shark::KernelExpansion< InputType >, shark::Conv2DModel< VectorType, ActivationFunction >, shark::OneVersusOneClassifier< InputType, VectorType >, shark::Classifier< Model >, shark::Classifier< detail::BaseNearestNeighbor< InputType, unsigned int > >, shark::Classifier< LinearModel< VectorType > >, shark::Classifier< MeanModel< CARTree< unsigned int > > >, shark::Classifier< KernelExpansion< InputType > >, shark::RBFLayer, shark::Normalizer< VectorType >, shark::DropoutLayer< VectorType >, shark::CMACMap, shark::CARTree< LabelType >, shark::CARTree< unsigned int >, shark::MeanModel< ModelType >, shark::MeanModel< CARTree< LabelType > >, shark::MeanModel< CARTree< unsigned int > >, shark::ClusteringModel< InputT, OutputT >, shark::ClusteringModel< InputT, RealVector >, and shark::ClusteringModel< InputT, unsigned int >.
Definition at line 142 of file AbstractModel.h.
|
inlinevirtual |
Definition at line 109 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 to just calculate the derivatives one after another.
patterns | the patterns to evaluate |
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 257 of file AbstractModel.h.
|
inlinevirtual |
calculates the weighted sum of derivatives w.r.t the inputs
pattern | the patterns to evaluate |
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::Conv2DModel< VectorType, ActivationFunction >, and shark::DropoutLayer< VectorType >.
Definition at line 236 of file AbstractModel.h.
Referenced by shark::AbstractModel< InputT, unsigned int >::weightedDerivatives().
|
inlinevirtual |
calculates the weighted sum of derivatives w.r.t the parameters.
pattern | the patterns to evaluate |
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::NeuronLayer< NeuronType, VectorType >, shark::Conv2DModel< VectorType, ActivationFunction >, shark::ConcatenatedModel< VectorType >, shark::DropoutLayer< VectorType >, and shark::RBFLayer.
Definition at line 220 of file AbstractModel.h.
Referenced by shark::AbstractModel< InputT, unsigned int >::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::NeuronLayer< NeuronType, VectorType >, shark::LinearModel< InputType, ActivationFunction >, shark::LinearModel< VectorType >, shark::RBM< VisibleLayerT, HiddenLayerT, randomT >, shark::ConcatenatedModel< VectorType >, shark::Conv2DModel< VectorType, ActivationFunction >, shark::KernelExpansion< InputType >, shark::OneVersusOneClassifier< InputType, VectorType >, shark::Classifier< Model >, shark::Classifier< detail::BaseNearestNeighbor< InputType, unsigned int > >, shark::Classifier< LinearModel< VectorType > >, shark::Classifier< MeanModel< CARTree< unsigned int > > >, shark::Classifier< KernelExpansion< InputType > >, shark::Normalizer< VectorType >, shark::RBFLayer, shark::DropoutLayer< VectorType >, shark::CMACMap, shark::CARTree< LabelType >, shark::CARTree< unsigned int >, shark::MeanModel< ModelType >, shark::MeanModel< CARTree< LabelType > >, shark::MeanModel< CARTree< unsigned int > >, shark::ClusteringModel< InputT, OutputT >, shark::ClusteringModel< InputT, RealVector >, and shark::ClusteringModel< InputT, unsigned int >.
Definition at line 152 of file AbstractModel.h.
|
protected |
Definition at line 109 of file AbstractModel.h.
Referenced by shark::AbstractModel< InputT, unsigned int >::hasFirstInputDerivative(), shark::AbstractModel< InputT, unsigned int >::hasFirstParameterDerivative(), shark::AbstractModel< InputT, unsigned int >::read(), and shark::AbstractModel< InputT, unsigned int >::write().