Base class for all Models. More...
#include <shark/Models/AbstractModel.h>
Public Types | |
enum | Feature { HAS_FIRST_PARAMETER_DERIVATIVE = 1, HAS_SECOND_PARAMETER_DERIVATIVE = 2, HAS_FIRST_INPUT_DERIVATIVE = 4, HAS_SECOND_INPUT_DERIVATIVE = 8, IS_SEQUENTIAL = 16 } |
typedef InputTypeT | InputType |
Defines the input type of the model. More... | |
typedef OutputTypeT | OutputType |
Defines the output type of the model. 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 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 | hasSecondParameterDerivative () const |
Returns true when the second parameter derivative is implemented. More... | |
bool | hasFirstInputDerivative () const |
Returns true when the first input derivative is implemented. More... | |
bool | hasSecondInputDerivative () const |
Returns true when the second parameter derivative is implemented. More... | |
bool | isSequential () const |
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 &coefficients, State const &state, RealVector &derivative) const |
calculates the weighted sum of derivatives w.r.t the parameters. More... | |
virtual void | weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, Batch< RealMatrix >::type const &errorHessian, State const &state, RealVector &derivative, RealMatrix &hessian) const |
calculates the weighted sum of derivatives w.r.t the parameters More... | |
virtual void | weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const |
calculates the weighted sum of derivatives w.r.t the inputs More... | |
virtual void | weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, typename Batch< RealMatrix >::type const &errorHessian, State const &state, RealMatrix &derivative, Batch< RealMatrix >::type &hessian) const |
calculates the weighted sum of derivatives w.r.t the inputs More... | |
virtual void | weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &coefficients, State const &state, RealVector ¶meterDerivative, BatchInputType &inputDerivative) const |
calculates weighted input and parameter derivative at the same time More... | |
![]() | |
virtual | ~IParameterizable () |
virtual RealVector | parameterVector () const |
Return the parameter vector. More... | |
virtual void | setParameterVector (RealVector const &newParameters) |
Set the parameter vector. More... | |
virtual std::size_t | numberOfParameters () const |
Return the number of parameters. More... | |
![]() | |
virtual | ~INameable () |
virtual std::string | name () const |
returns the name of the object More... | |
![]() | |
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 78 of file AbstractModel.h.
typedef Batch<InputType>::type shark::AbstractModel< InputTypeT, OutputTypeT >::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 90 of file AbstractModel.h.
typedef Batch<OutputType>::type shark::AbstractModel< InputTypeT, OutputTypeT >::BatchOutputType |
defines the batch type of the output type
Definition at line 92 of file AbstractModel.h.
typedef TypedFeatureNotAvailableException<Feature> shark::AbstractModel< InputTypeT, OutputTypeT >::FeatureNotAvailableException |
Definition at line 106 of file AbstractModel.h.
typedef TypedFlags<Feature> shark::AbstractModel< InputTypeT, OutputTypeT >::Features |
Definition at line 106 of file AbstractModel.h.
typedef InputTypeT shark::AbstractModel< InputTypeT, OutputTypeT >::InputType |
Defines the input type of the model.
Definition at line 82 of file AbstractModel.h.
typedef OutputTypeT shark::AbstractModel< InputTypeT, OutputTypeT >::OutputType |
Defines the output type of the model.
Definition at line 84 of file AbstractModel.h.
enum shark::AbstractModel::Feature |
Enumerator | |
---|---|
HAS_FIRST_PARAMETER_DERIVATIVE | |
HAS_SECOND_PARAMETER_DERIVATIVE | |
HAS_FIRST_INPUT_DERIVATIVE | |
HAS_SECOND_INPUT_DERIVATIVE | |
IS_SEQUENTIAL |
Definition at line 99 of file AbstractModel.h.
|
inline |
Definition at line 95 of file AbstractModel.h.
|
inlinevirtual |
Definition at line 97 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::ConcatenatedModel< InputType, OutputType >, shark::FFNet< HiddenNeuron, OutputNeuron >, shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >, shark::KernelExpansion< InputType >, shark::KernelExpansion< RealVector >, shark::RBM< VisibleLayerT, HiddenLayerT, RngT >, shark::LinearModel< InputType >, shark::LinearModel< VectorType >, shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >, shark::Autoencoder< HiddenNeuron, OutputNeuron >, shark::OneVersusOneClassifier< InputType >, shark::ConvexCombination, shark::NBClassifier< InputType, OutputType >, shark::SoftNearestNeighborClassifier< InputType >, shark::ThresholdVectorConverter, shark::CMACMap, shark::NearestNeighborClassifier< InputType >, shark::CARTClassifier< LabelType >, shark::CARTClassifier< RealVector >, shark::NearestNeighborRegression< InputType >, shark::GaussianNoiseModel, shark::Normalizer< DataType >, shark::RBFLayer, shark::RNNet, shark::Softmax, shark::SigmoidModel, shark::ImpulseNoiseModel, shark::ThresholdConverter, shark::LinearNorm, and shark::MissingFeaturesKernelExpansion< InputType >.
Definition at line 134 of file AbstractModel.h.
Referenced by shark::AbstractModel< InputT, unsigned int >::eval(), and shark::NegativeLogLikelihood::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::ConcatenatedModel< InputType, OutputType >, shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >, shark::Normalizer< DataType >, shark::KernelExpansion< InputType >, shark::KernelExpansion< RealVector >, shark::RBM< VisibleLayerT, HiddenLayerT, RngT >, shark::ArgMaxConverter< LinearModel< VectorType > >, shark::ArgMaxConverter< KernelExpansion< InputType > >, shark::LinearModel< InputType >, shark::LinearModel< VectorType >, shark::ConvexCombination, shark::SoftNearestNeighborClassifier< InputType >, shark::ThresholdVectorConverter, shark::CARTClassifier< LabelType >, shark::CARTClassifier< RealVector >, shark::GaussianNoiseModel, shark::SigmoidModel, shark::Softmax, shark::ImpulseNoiseModel, shark::ThresholdConverter, shark::LinearNorm, and shark::MissingFeaturesKernelExpansion< InputType >.
Definition at line 167 of file AbstractModel.h.
Referenced by shark::AbstractModel< InputT, unsigned int >::eval(), shark::NegativeLogLikelihood::evalDerivative(), shark::MeanModel< CARTClassifier< RealVector > >::name(), and shark::AbstractModel< InputT, unsigned int >::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::ConcatenatedModel< InputType, OutputType >, shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >, shark::KernelExpansion< InputType >, shark::KernelExpansion< RealVector >, shark::Normalizer< DataType >, shark::RBM< VisibleLayerT, HiddenLayerT, RngT >, shark::ArgMaxConverter< LinearModel< VectorType > >, shark::ArgMaxConverter< KernelExpansion< InputType > >, shark::LinearModel< InputType >, shark::LinearModel< VectorType >, shark::SoftNearestNeighborClassifier< InputType >, shark::OneVersusOneClassifier< InputType >, shark::ConvexCombination, shark::CARTClassifier< LabelType >, shark::CARTClassifier< RealVector >, shark::NBClassifier< InputType, OutputType >, shark::GaussianNoiseModel, shark::ThresholdVectorConverter, shark::NearestNeighborClassifier< InputType >, shark::NearestNeighborRegression< InputType >, shark::RBFLayer, shark::ImpulseNoiseModel, shark::RNNet, shark::MissingFeaturesKernelExpansion< InputType >, shark::Softmax, shark::SigmoidModel, shark::ThresholdConverter, shark::ClusteringModel< InputT, OutputT >, shark::ClusteringModel< InputT, RealVector >, shark::ClusteringModel< InputT, unsigned int >, and shark::LinearNorm.
|
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::ArgMaxConverter< Model >, shark::ArgMaxConverter< LinearModel< VectorType > >, shark::ArgMaxConverter< KernelExpansion< InputType > >, shark::SoftClusteringModel< InputT >, and shark::HardClusteringModel< InputT >.
Definition at line 183 of file AbstractModel.h.
|
inline |
Definition at line 106 of file AbstractModel.h.
|
inline |
Returns true when the first input derivative is implemented.
Definition at line 117 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 109 of file AbstractModel.h.
Referenced by shark::AbstractModel< InputT, unsigned int >::createState(), and shark::NegativeLogLikelihood::NegativeLogLikelihood().
|
inline |
Returns true when the second parameter derivative is implemented.
Definition at line 121 of file AbstractModel.h.
Referenced by shark::AbstractModel< InputT, unsigned int >::createState().
|
inline |
Returns true when the second parameter derivative is implemented.
Definition at line 113 of file AbstractModel.h.
Referenced by shark::AbstractModel< InputT, unsigned int >::createState().
|
inline |
Definition at line 124 of file AbstractModel.h.
|
inline |
Model evaluation as an operator for a whole dataset. This is a convenience function.
patterns | the input of the model |
Definition at line 195 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 208 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 218 of file AbstractModel.h.
|
inlinevirtual |
From ISerializable, reads a model from an archive.
Reimplemented from shark::ISerializable.
Reimplemented in shark::FFNet< HiddenNeuron, OutputNeuron >, shark::ConcatenatedModel< InputType, OutputType >, shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >, shark::Autoencoder< HiddenNeuron, OutputNeuron >, shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >, shark::RBM< VisibleLayerT, HiddenLayerT, RngT >, shark::KernelExpansion< InputType >, shark::KernelExpansion< RealVector >, shark::Normalizer< DataType >, shark::ArgMaxConverter< Model >, shark::ArgMaxConverter< LinearModel< VectorType > >, shark::ArgMaxConverter< KernelExpansion< InputType > >, shark::LinearModel< InputType >, shark::LinearModel< VectorType >, shark::OneVersusOneClassifier< InputType >, shark::ConvexCombination, shark::CARTClassifier< LabelType >, shark::CARTClassifier< RealVector >, shark::SoftNearestNeighborClassifier< InputType >, shark::NearestNeighborRegression< InputType >, shark::RBFLayer, shark::NearestNeighborClassifier< InputType >, shark::CMACMap, shark::SigmoidModel, shark::Softmax, shark::LinearNorm, shark::MeanModel< ModelType >, shark::MeanModel< CARTClassifier< RealVector > >, shark::ClusteringModel< InputT, OutputT >, shark::ClusteringModel< InputT, RealVector >, and shark::ClusteringModel< InputT, unsigned int >.
Definition at line 147 of file AbstractModel.h.
|
inlinevirtual |
Definition at line 106 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< InputType, OutputType >, shark::FFNet< HiddenNeuron, OutputNeuron >, shark::Autoencoder< HiddenNeuron, OutputNeuron >, and shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >.
Definition at line 302 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::LinearModel< InputType >, shark::LinearModel< VectorType >, shark::ConvexCombination, and shark::SigmoidModel.
Definition at line 264 of file AbstractModel.h.
Referenced by shark::AbstractModel< InputT, unsigned int >::weightedDerivatives().
|
inlinevirtual |
calculates the weighted sum of derivatives w.r.t the inputs
pattern | the pattern to evaluate |
coefficients | the coefficients which are used to calculate the weighted sum |
errorHessian | the second derivative of the error function for every pattern |
state | intermediate results stored by eval to sped up calculations of the derivatives |
derivative | the calculated derivative for every pattern |
hessian | the calculated hessian for every pattern |
Definition at line 281 of file AbstractModel.h.
|
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::ConcatenatedModel< InputType, OutputType >, shark::RBFLayer, shark::Softmax, shark::SigmoidModel, and shark::LinearNorm.
Definition at line 230 of file AbstractModel.h.
Referenced by shark::NegativeLogLikelihood::evalDerivative(), and 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 |
errorHessian | the second derivative of the error function 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 |
hessian | the calculated hessian as sum over all derivates of all patterns |
Definition at line 247 of file AbstractModel.h.
|
inlinevirtual |
writes a model to an archive
the default implementation just saves the parameters, not the structure!
Reimplemented from shark::ISerializable.
Reimplemented in shark::FFNet< HiddenNeuron, OutputNeuron >, shark::ConcatenatedModel< InputType, OutputType >, shark::ConvolutionalRBM< VisibleLayerT, HiddenLayerT, RngT >, shark::Autoencoder< HiddenNeuron, OutputNeuron >, shark::RBM< VisibleLayerT, HiddenLayerT, RngT >, shark::TiedAutoencoder< HiddenNeuron, OutputNeuron >, shark::KernelExpansion< InputType >, shark::KernelExpansion< RealVector >, shark::Normalizer< DataType >, shark::ArgMaxConverter< Model >, shark::ArgMaxConverter< LinearModel< VectorType > >, shark::ArgMaxConverter< KernelExpansion< InputType > >, shark::LinearModel< InputType >, shark::LinearModel< VectorType >, shark::OneVersusOneClassifier< InputType >, shark::ConvexCombination, shark::CARTClassifier< LabelType >, shark::CARTClassifier< RealVector >, shark::SoftNearestNeighborClassifier< InputType >, shark::NearestNeighborRegression< InputType >, shark::NearestNeighborClassifier< InputType >, shark::RBFLayer, shark::CMACMap, shark::SigmoidModel, shark::Softmax, shark::LinearNorm, shark::MeanModel< ModelType >, shark::MeanModel< CARTClassifier< RealVector > >, shark::ClusteringModel< InputT, OutputT >, shark::ClusteringModel< InputT, RealVector >, and shark::ClusteringModel< InputT, unsigned int >.
Definition at line 157 of file AbstractModel.h.
|
protected |
Definition at line 106 of file AbstractModel.h.
Referenced by shark::AbstractModel< InputT, unsigned int >::hasFirstInputDerivative(), shark::AbstractModel< InputT, unsigned int >::hasFirstParameterDerivative(), shark::AbstractModel< InputT, unsigned int >::hasSecondInputDerivative(), shark::AbstractModel< InputT, unsigned int >::hasSecondParameterDerivative(), shark::AbstractModel< InputT, unsigned int >::isSequential(), shark::AbstractModel< InputT, unsigned int >::read(), and shark::AbstractModel< InputT, unsigned int >::write().