ConcatenatedModel concatenates two models such that the output of the first model is input to the second. More...
#include <shark/Models/ConcatenatedModel.h>
Public Member Functions | |
std::string | name () const |
From INameable: return the class name. More... | |
Shape | inputShape () const |
Returns the expected shape of the input. More... | |
Shape | outputShape () const |
Returns the shape of the output. More... | |
void | add (AbstractModel< VectorType, VectorType > *layer, bool optimize) |
void | enableModelOptimization (std::size_t index, bool opt) |
sets whether the parameters of the index-th model should be optimized More... | |
ParameterVectorType | parameterVector () const |
Return the parameter vector. More... | |
void | setParameterVector (ParameterVectorType const &newParameters) |
Set the parameter vector. More... | |
std::size_t | numberOfParameters () const |
Return the number of parameters. More... | |
boost::shared_ptr< State > | createState () const |
Creates an internal state of the model. More... | |
BatchOutputType const & | hiddenResponses (State const &state, std::size_t index) const |
State const & | hiddenState (State const &state, std::size_t index) const |
void | eval (BatchInputType const &patterns, BatchOutputType &outputs) const |
Standard interface for evaluating the response of the model to a batch of patterns. More... | |
void | eval (BatchInputType const &patterns, BatchOutputType &outputs, State &state) const |
Standard interface for evaluating the response of the model to a batch of patterns. More... | |
void | weightedParameterDerivative (BatchInputType const &patterns, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, RealVector &gradient) const |
calculates the weighted sum of derivatives w.r.t the parameters. More... | |
void | weightedInputDerivative (BatchInputType const &patterns, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, BatchOutputType &derivatives) const |
virtual void | weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, RealVector &gradient, BatchInputType &inputDerivative) const |
calculates weighted input and parameter derivative at the same time More... | |
void | read (InArchive &archive) |
From ISerializable. More... | |
void | write (OutArchive &archive) const |
From ISerializable. More... | |
Public Member Functions inherited from shark::AbstractModel< VectorType, VectorType, VectorType > | |
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 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 | 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... | |
Public Member Functions inherited from shark::IParameterizable< VectorType > | |
virtual | ~IParameterizable () |
Public Member Functions inherited from shark::INameable | |
virtual | ~INameable () |
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 () | |
Additional Inherited Members | |
Protected Attributes inherited from shark::AbstractModel< VectorType, VectorType, VectorType > | |
Features | m_features |
ConcatenatedModel concatenates two models such that the output of the first model is input to the second.
Sometimes a series of models is needed to generate the desired output. For example when input data needs to be normalized before it can be put into the trained model. In this case, the ConcatenatedModel can be used to represent this series as one model. The easiest way to do is is using the operator >> of AbstractModel: ConcatenatedModel<InputType,OutputType> model = model1>>model2; InputType must be the type of input model1 receives and model2 the output of model2. The output of model1 and input of model2 must match. Another way of construction is calling the constructor of ConcatenatedModel using the constructor: ConcatenatedModel<InputType,OutputType> model (&modell,&model2); warning: model1 and model2 must outlive model. When they are destroyed first, behavior is undefined.
Definition at line 56 of file ConcatenatedModel.h.
typedef base_type::BatchInputType shark::ConcatenatedModel< VectorType >::BatchInputType |
Definition at line 60 of file ConcatenatedModel.h.
typedef base_type::BatchOutputType shark::ConcatenatedModel< VectorType >::BatchOutputType |
Definition at line 61 of file ConcatenatedModel.h.
typedef base_type::ParameterVectorType shark::ConcatenatedModel< VectorType >::ParameterVectorType |
Definition at line 62 of file ConcatenatedModel.h.
|
inline |
Definition at line 79 of file ConcatenatedModel.h.
References shark::ConcatenatedModel< VectorType >::enableModelOptimization().
Referenced by shark::operator>>().
|
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 from shark::AbstractModel< VectorType, VectorType, VectorType >.
Definition at line 145 of file ConcatenatedModel.h.
|
inline |
sets whether the parameters of the index-th model should be optimized
If the model has non-differentiable submodels disabling those will make the whole model differentiable. Note that the models are ordered as model0 >> model1>> model2>>...
Definition at line 89 of file ConcatenatedModel.h.
References shark::AbstractModel< VectorType, VectorType, VectorType >::HAS_FIRST_INPUT_DERIVATIVE, shark::AbstractModel< VectorType, VectorType, VectorType >::HAS_FIRST_PARAMETER_DERIVATIVE, shark::AbstractModel< VectorType, VectorType, VectorType >::m_features, shark::TypedFlags< Flag >::reset(), and SIZE_CHECK.
Referenced by shark::ConcatenatedModel< VectorType >::add(), and trainAutoencoderModel().
|
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 from shark::AbstractModel< VectorType, VectorType, VectorType >.
Definition at line 165 of file ConcatenatedModel.h.
References shark::swap().
|
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 |
state | intermediate results stored by eval which can be reused for derivative computation. |
Implements shark::AbstractModel< VectorType, VectorType, VectorType >.
Definition at line 173 of file ConcatenatedModel.h.
References shark::State::toState().
|
inline |
Definition at line 154 of file ConcatenatedModel.h.
References shark::State::toState().
|
inline |
Definition at line 159 of file ConcatenatedModel.h.
References shark::AbstractModel< VectorType, VectorType, VectorType >::eval(), and shark::State::toState().
|
inlinevirtual |
Returns the expected shape of the input.
Implements shark::AbstractModel< VectorType, VectorType, VectorType >.
Definition at line 70 of file ConcatenatedModel.h.
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 65 of file ConcatenatedModel.h.
Referenced by trainAutoencoderModel().
|
inlinevirtual |
Return the number of parameters.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 136 of file ConcatenatedModel.h.
Referenced by shark::ConcatenatedModel< VectorType >::parameterVector(), shark::ConcatenatedModel< VectorType >::weightedDerivatives(), and shark::ConcatenatedModel< VectorType >::weightedParameterDerivative().
|
inlinevirtual |
Returns the shape of the output.
Implements shark::AbstractModel< VectorType, VectorType, VectorType >.
Definition at line 74 of file ConcatenatedModel.h.
|
inlinevirtual |
Return the parameter vector.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 114 of file ConcatenatedModel.h.
References shark::ConcatenatedModel< VectorType >::numberOfParameters().
|
inlinevirtual |
From ISerializable.
Reimplemented from shark::AbstractModel< VectorType, VectorType, VectorType >.
Definition at line 277 of file ConcatenatedModel.h.
|
inlinevirtual |
Set the parameter vector.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 126 of file ConcatenatedModel.h.
Referenced by trainAutoencoderModel().
|
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 from shark::AbstractModel< VectorType, VectorType, VectorType >.
Definition at line 244 of file ConcatenatedModel.h.
References shark::ConcatenatedModel< VectorType >::numberOfParameters(), shark::swap(), and shark::State::toState().
|
inline |
Definition at line 222 of file ConcatenatedModel.h.
References shark::swap(), and shark::State::toState().
|
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 from shark::AbstractModel< VectorType, VectorType, VectorType >.
Definition at line 185 of file ConcatenatedModel.h.
References shark::ConcatenatedModel< VectorType >::numberOfParameters(), shark::swap(), and shark::State::toState().
|
inlinevirtual |
From ISerializable.
Reimplemented from shark::AbstractModel< VectorType, VectorType, VectorType >.
Definition at line 285 of file ConcatenatedModel.h.