ConcatenatedModel concatenates two models such that the output of the first model is input to the second. More...
#include <shark/Models/ConcatenatedModel.h>
Public Types | |
typedef base_type::BatchInputType | BatchInputType |
typedef base_type::BatchOutputType | BatchOutputType |
![]() | |
enum | Feature |
typedef InputType | InputType |
Defines the input type of the model. More... | |
typedef OutputType | 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 | |
template<class T > | |
ConcatenatedModel (AbstractModel< InputType, T > *firstModel, AbstractModel< T, OutputType > *secondModel) | |
creates a concatenated model using two base model. this is equivalent to concModel = *firstModel >> *secondModel; More... | |
ConcatenatedModel (const detail::ConcatenatedModelWrapperBase< InputType, OutputType > &wrapper) | |
copy constructor to allow ConcatenatedModel concModel = model1 >> model2 >> model3; More... | |
ConcatenatedModel< InputType, OutputType > & | operator= (detail::ConcatenatedModelWrapperBase< InputType, OutputType > &wrapper) |
operator = to allow concModel = model1 >> model2 >> model3; for a previously declared concatenadel model More... | |
bool | optimizeFirstModelParameters () const |
Returns whether the parameters of the first model are going to be optimized. More... | |
bool & | optimizeFirstModelParameters () |
Returns a variable indicting whether the parameters of the first model are going to be optimized. More... | |
bool | optimizeSecondModelParameters () const |
Returns whether the parameters of the second model are going to be optimized. More... | |
bool & | optimizeSecondModelParameters () |
Returns a variable indicting whether the parameters of the second model are going to be optimized. More... | |
ConcatenatedModel (const ConcatenatedModel< InputType, OutputType > &src) | |
std::string | name () const |
From INameable: return the class name. More... | |
const ConcatenatedModel< InputType, OutputType > & | operator= (const ConcatenatedModel< InputType, OutputType > &src) |
RealVector | parameterVector () const |
Return the parameter vector. More... | |
void | setParameterVector (RealVector const &newParameters) |
Set the parameter vector. More... | |
size_t | numberOfParameters () const |
Return the number of parameters. More... | |
boost::shared_ptr< State > | createState () const |
Creates an internal state of the model. More... | |
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 &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 &coefficients, State const &state, BatchOutputType &derivatives) const |
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... | |
void | read (InArchive &archive) |
From ISerializable. More... | |
void | write (OutArchive &archive) const |
From ISerializable. More... | |
![]() | |
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 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, 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 | ~IParameterizable () |
![]() | |
virtual | ~INameable () |
![]() | |
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 | |
![]() | |
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 362 of file ConcatenatedModel.h.
typedef base_type::BatchInputType shark::ConcatenatedModel< InputType, OutputType >::BatchInputType |
Definition at line 368 of file ConcatenatedModel.h.
typedef base_type::BatchOutputType shark::ConcatenatedModel< InputType, OutputType >::BatchOutputType |
Definition at line 369 of file ConcatenatedModel.h.
|
inline |
creates a concatenated model using two base model. this is equivalent to concModel = *firstModel >> *secondModel;
Definition at line 374 of file ConcatenatedModel.h.
|
inline |
copy constructor to allow ConcatenatedModel concModel = model1 >> model2 >> model3;
Definition at line 385 of file ConcatenatedModel.h.
|
inline |
Definition at line 437 of file ConcatenatedModel.h.
References shark::AbstractModel< InputType, OutputType >::m_features.
|
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< InputType, OutputType >.
Definition at line 465 of file ConcatenatedModel.h.
|
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< InputType, OutputType >.
Definition at line 470 of file ConcatenatedModel.h.
|
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< InputType, OutputType >.
Definition at line 473 of file ConcatenatedModel.h.
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 443 of file ConcatenatedModel.h.
Referenced by trainAutoencoderModel().
|
inlinevirtual |
Return the number of parameters.
Reimplemented from shark::IParameterizable.
Definition at line 461 of file ConcatenatedModel.h.
|
inline |
operator = to allow concModel = model1 >> model2 >> model3; for a previously declared concatenadel model
Definition at line 396 of file ConcatenatedModel.h.
|
inline |
Definition at line 446 of file ConcatenatedModel.h.
References shark::AbstractModel< InputType, OutputType >::m_features, and shark::swap().
|
inline |
Returns whether the parameters of the first model are going to be optimized.
Remember that concatModel = first >> second, so it is the lower layer.
Definition at line 412 of file ConcatenatedModel.h.
|
inline |
Returns a variable indicting whether the parameters of the first model are going to be optimized.
Remember that concatModel = first >> second, so it is the lower layer.
Definition at line 419 of file ConcatenatedModel.h.
|
inline |
Returns whether the parameters of the second model are going to be optimized.
Remember that concatModel = first >> second, so it is the upper layer.
Definition at line 426 of file ConcatenatedModel.h.
|
inline |
Returns a variable indicting whether the parameters of the second model are going to be optimized.
Remember that concatModel = first >> second, so it is the upper layer.
Definition at line 433 of file ConcatenatedModel.h.
|
inlinevirtual |
Return the parameter vector.
Reimplemented from shark::IParameterizable.
Definition at line 453 of file ConcatenatedModel.h.
|
inlinevirtual |
From ISerializable.
Reimplemented from shark::AbstractModel< InputType, OutputType >.
Definition at line 500 of file ConcatenatedModel.h.
|
inlinevirtual |
Set the parameter vector.
Reimplemented from shark::IParameterizable.
Definition at line 457 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< InputType, OutputType >.
Definition at line 489 of file ConcatenatedModel.h.
|
inline |
Definition at line 483 of file ConcatenatedModel.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 from shark::AbstractModel< InputType, OutputType >.
Definition at line 477 of file ConcatenatedModel.h.
|
inlinevirtual |
From ISerializable.
Reimplemented from shark::AbstractModel< InputType, OutputType >.
Definition at line 505 of file ConcatenatedModel.h.