Models a convex combination of inputs. More...
#include <shark/Models/ConvexCombination.h>
Public Member Functions | |
ConvexCombination () | |
CDefault Constructor; use setStructure later. More... | |
ConvexCombination (std::size_t inputs, std::size_t outputs=1) | |
Constructor creating a model with given dimnsionalities and optional offset term. More... | |
ConvexCombination (RealMatrix const &matrix) | |
Construction from matrix. More... | |
std::string | name () const |
From INameable: return the class name. More... | |
ConvexCombination & | operator= (ConvexCombination const &model) |
operator = More... | |
std::size_t | inputSize () const |
obtain the input dimension More... | |
std::size_t | outputSize () const |
obtain the output dimension More... | |
RealVector | parameterVector () const |
obtain the parameter vector More... | |
void | setParameterVector (RealVector const &newParameters) |
overwrite the parameter vector More... | |
std::size_t | numberOfParameters () const |
return the number of parameter More... | |
void | setStructure (std::size_t inputs, std::size_t outputs=1) |
overwrite structure and parameters More... | |
RealMatrix const & | weights () const |
RealMatrix & | weights () |
boost::shared_ptr< State > | createState () const |
Creates an internal state of the model. More... | |
void | eval (BatchInputType const &inputs, BatchOutputType &outputs) const |
Evaluate the model: output = w * input. More... | |
void | eval (BatchInputType const &inputs, BatchOutputType &outputs, State &state) const |
Evaluate the model: output = w *input. More... | |
void | weightedParameterDerivative (BatchInputType const &patterns, RealMatrix const &coefficients, State const &state, RealVector &gradient) const |
Calculates the first derivative w.r.t the parameters and summing them up over all patterns of the last computed batch. More... | |
void | weightedInputDerivative (BatchInputType const &patterns, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const |
Calculates the first derivative w.r.t the inputs and summs them up over all patterns of the last computed batch. More... | |
void | read (InArchive &archive) |
From ISerializable. More... | |
void | write (OutArchive &archive) const |
From ISerializable. More... | |
Public Member Functions inherited from shark::AbstractModel< RealVector, RealVector > | |
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, 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, 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... | |
Public Member Functions inherited from shark::IParameterizable | |
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 () | |
Friends | |
void | swap (ConvexCombination &model1, ConvexCombination &model2) |
swap More... | |
Additional Inherited Members | |
Public Types inherited from shark::AbstractModel< RealVector, RealVector > | |
enum | Feature |
typedef RealVector | InputType |
Defines the input type of the model. More... | |
typedef RealVector | 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 |
Protected Attributes inherited from shark::AbstractModel< RealVector, RealVector > | |
Features | m_features |
Models a convex combination of inputs.
For a given input vector x, the convex combination returns \( f_i(x) = sum_j w_{ij} x_j \), where \( w_i > 0 \) and \( sum_j w_{ij} = 1\), that is the outputs of the model are a convex combination of the inputs.
To ensure that the constraints are fulfilled, the model uses a different set of weights q_i and \( w_{ij} = exp(q_{ij})/sum_j exp(q_{ik}) \). As usual, this encoding is only used for the derivatives and the parameter vectors, not when the weights are explicitely set. In the latter case, the user must provide a set of suitable \( w_{ij} \).
Definition at line 51 of file ConvexCombination.h.
|
inline |
CDefault Constructor; use setStructure later.
Definition at line 58 of file ConvexCombination.h.
References shark::AbstractModel< RealVector, RealVector >::HAS_FIRST_INPUT_DERIVATIVE, shark::AbstractModel< RealVector, RealVector >::HAS_FIRST_PARAMETER_DERIVATIVE, and shark::AbstractModel< RealVector, RealVector >::m_features.
|
inline |
Constructor creating a model with given dimnsionalities and optional offset term.
Definition at line 64 of file ConvexCombination.h.
References shark::AbstractModel< RealVector, RealVector >::HAS_FIRST_INPUT_DERIVATIVE, shark::AbstractModel< RealVector, RealVector >::HAS_FIRST_PARAMETER_DERIVATIVE, and shark::AbstractModel< RealVector, RealVector >::m_features.
|
inline |
Construction from matrix.
Definition at line 71 of file ConvexCombination.h.
References shark::AbstractModel< RealVector, RealVector >::HAS_FIRST_INPUT_DERIVATIVE, shark::AbstractModel< RealVector, RealVector >::HAS_FIRST_PARAMETER_DERIVATIVE, and shark::AbstractModel< RealVector, RealVector >::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< RealVector, RealVector >.
Definition at line 135 of file ConvexCombination.h.
|
inlinevirtual |
Evaluate the model: output = w * input.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Definition at line 140 of file ConvexCombination.h.
References remora::noalias(), remora::prod(), and remora::trans().
Referenced by eval().
|
inlinevirtual |
Evaluate the model: output = w *input.
Implements shark::AbstractModel< RealVector, RealVector >.
Definition at line 145 of file ConvexCombination.h.
References eval().
|
inline |
obtain the input dimension
Definition at line 93 of file ConvexCombination.h.
Referenced by weightedInputDerivative(), and weightedParameterDerivative().
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 77 of file ConvexCombination.h.
|
inlinevirtual |
return the number of parameter
Reimplemented from shark::IParameterizable.
Definition at line 117 of file ConvexCombination.h.
Referenced by weightedParameterDerivative().
|
inline |
|
inline |
obtain the output dimension
Definition at line 98 of file ConvexCombination.h.
Referenced by setParameterVector(), weightedInputDerivative(), and weightedParameterDerivative().
|
inlinevirtual |
obtain the parameter vector
Reimplemented from shark::IParameterizable.
Definition at line 103 of file ConvexCombination.h.
References remora::to_vector().
|
inlinevirtual |
From ISerializable.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Definition at line 188 of file ConvexCombination.h.
|
inlinevirtual |
overwrite the parameter vector
Reimplemented from shark::IParameterizable.
Definition at line 108 of file ConvexCombination.h.
References remora::noalias(), outputSize(), remora::row(), remora::sum(), and remora::to_matrix().
|
inline |
overwrite structure and parameters
Definition at line 122 of file ConvexCombination.h.
References swap.
Referenced by main().
|
inlinevirtual |
Calculates the first derivative w.r.t the inputs and summs them up over all patterns of the last computed batch.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Definition at line 174 of file ConvexCombination.h.
References inputSize(), remora::noalias(), outputSize(), remora::prod(), and SIZE_CHECK.
|
inline |
Calculates the first derivative w.r.t the parameters and summing them up over all patterns of the last computed batch.
Definition at line 150 of file ConvexCombination.h.
References remora::inner_prod(), inputSize(), remora::noalias(), numberOfParameters(), outputSize(), remora::prod(), remora::row(), SIZE_CHECK, remora::to_matrix(), and remora::trans().
|
inline |
Definition at line 127 of file ConvexCombination.h.
|
inline |
Definition at line 131 of file ConvexCombination.h.
|
inlinevirtual |
From ISerializable.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Definition at line 192 of file ConvexCombination.h.
|
friend |
swap
Definition at line 81 of file ConvexCombination.h.
Referenced by operator=(), and setStructure().