Linear Prediction with optional activation function. More...
#include <shark/Models/LinearModel.h>
Public Types | |
typedef base_type::BatchInputType | BatchInputType |
typedef base_type::BatchOutputType | BatchOutputType |
typedef base_type::ParameterVectorType | ParameterVectorType |
Public Member Functions | |
LinearModel () | |
CDefault Constructor; use setStructure later. More... | |
LinearModel (Shape const &inputs, Shape const &outputs=1, bool offset=false) | |
Constructor creating a model with given dimensionalities and optional offset term. More... | |
std::string | name () const |
From INameable: return the class name. More... | |
LinearModel (MatrixType const &matrix, VectorType const &offset=VectorType()) | |
Construction from matrix (and vector) More... | |
bool | hasOffset () const |
check for the presence of an offset term More... | |
Shape | inputShape () const |
Returns the expected shape of the input. More... | |
Shape | outputShape () const |
Returns the shape of the output. More... | |
ParameterVectorType | parameterVector () const |
obtain the parameter vector More... | |
void | setParameterVector (ParameterVectorType const &newParameters) |
overwrite the parameter vector More... | |
size_t | numberOfParameters () const |
return the number of parameter More... | |
void | setStructure (Shape const &inputs, Shape const &outputs=1, bool offset=false) |
overwrite structure and parameters More... | |
void | setStructure (MatrixType const &matrix, VectorType const &offset=VectorType()) |
overwrite structure and parameters More... | |
MatrixType const & | matrix () const |
return a copy of the matrix in dense format More... | |
MatrixType & | matrix () |
VectorType const & | offset () const |
return the offset More... | |
VectorType & | offset () |
ActivationFunction const & | activationFunction () const |
Returns the activation function. More... | |
ActivationFunction & | activationFunction () |
Returns the activation function. More... | |
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 = matrix * input + offset. More... | |
void | eval (InputType const &input, VectorType &output) const |
void | eval (BatchInputType const &inputs, BatchOutputType &outputs, State &state) const |
Evaluate the model: output = matrix * input + offset. More... | |
void | weightedParameterDerivative (BatchInputType const &patterns, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, ParameterVectorType &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 &outputs, BatchOutputType const &coefficients, State const &state, MatrixType &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 | weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, ParameterVectorType ¶meterDerivative, MatrixType &inputDerivative) const |
void | read (InArchive &archive) |
From ISerializable. More... | |
void | write (OutArchive &archive) const |
From ISerializable. More... | |
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 () | |
Linear Prediction with optional activation function.
The class allows for dense and sparse input vector types. However it assumes that the weight matrix and the ouputs are dense. There are some cases where this is not good behavior. Check for example Normalizer for a class which is designed for sparse inputs and outputs.
Definition at line 57 of file LinearModel.h.
typedef base_type::BatchInputType shark::LinearModel< InputType, ActivationFunction >::BatchInputType |
Definition at line 73 of file LinearModel.h.
typedef base_type::BatchOutputType shark::LinearModel< InputType, ActivationFunction >::BatchOutputType |
Definition at line 74 of file LinearModel.h.
typedef base_type::ParameterVectorType shark::LinearModel< InputType, ActivationFunction >::ParameterVectorType |
Definition at line 75 of file LinearModel.h.
|
inline |
CDefault Constructor; use setStructure later.
Definition at line 78 of file LinearModel.h.
|
inline |
Constructor creating a model with given dimensionalities and optional offset term.
Definition at line 85 of file LinearModel.h.
|
inline |
Construction from matrix (and vector)
Definition at line 101 of file LinearModel.h.
|
inline |
Returns the activation function.
Definition at line 174 of file LinearModel.h.
|
inline |
Returns the activation function.
Definition at line 179 of file LinearModel.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 from shark::AbstractModel< InputType, blas::vector< InputType::value_type, InputType::device_type >, blas::vector< InputType::value_type, InputType::device_type > >.
Definition at line 183 of file LinearModel.h.
|
inlinevirtual |
Evaluate the model: output = matrix * input + offset.
Reimplemented from shark::AbstractModel< InputType, blas::vector< InputType::value_type, InputType::device_type >, blas::vector< InputType::value_type, InputType::device_type > >.
Definition at line 190 of file LinearModel.h.
|
inline |
Definition at line 200 of file LinearModel.h.
|
inlinevirtual |
Evaluate the model: output = matrix * input + offset.
Definition at line 210 of file LinearModel.h.
|
inline |
check for the presence of an offset term
Definition at line 113 of file LinearModel.h.
|
inlinevirtual |
Returns the expected shape of the input.
Definition at line 118 of file LinearModel.h.
Referenced by shark::LinearSAGTrainer< InputType, LabelType >::numberOfParameters(), shark::LinearModel< VectorType >::setParameterVector(), shark::LinearModel< VectorType >::weightedDerivatives(), and shark::LinearModel< VectorType >::weightedParameterDerivative().
|
inline |
return a copy of the matrix in dense format
Definition at line 157 of file LinearModel.h.
Referenced by main().
|
inline |
Definition at line 161 of file LinearModel.h.
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 97 of file LinearModel.h.
|
inlinevirtual |
return the number of parameter
Reimplemented from shark::IParameterizable< blas::vector< InputType::value_type, InputType::device_type > >.
Definition at line 140 of file LinearModel.h.
Referenced by shark::LinearModel< VectorType >::weightedParameterDerivative().
|
inline |
return the offset
Definition at line 166 of file LinearModel.h.
Referenced by main(), and shark::LinearModel< VectorType >::setStructure().
|
inline |
Definition at line 169 of file LinearModel.h.
|
inlinevirtual |
Returns the shape of the output.
Definition at line 122 of file LinearModel.h.
Referenced by shark::LinearSAGTrainer< InputType, LabelType >::numberOfParameters(), shark::LinearModel< VectorType >::setParameterVector(), shark::PCA::train(), shark::LinearModel< VectorType >::weightedDerivatives(), and shark::LinearModel< VectorType >::weightedParameterDerivative().
|
inlinevirtual |
obtain the parameter vector
Reimplemented from shark::IParameterizable< blas::vector< InputType::value_type, InputType::device_type > >.
Definition at line 127 of file LinearModel.h.
|
inlinevirtual |
From ISerializable.
Reimplemented from shark::AbstractModel< InputType, blas::vector< InputType::value_type, InputType::device_type >, blas::vector< InputType::value_type, InputType::device_type > >.
Definition at line 304 of file LinearModel.h.
|
inline |
|
inline |
overwrite structure and parameters
Definition at line 145 of file LinearModel.h.
Referenced by shark::LinearSAGTrainer< InputType, LabelType >::numberOfParameters(), and shark::NormalizeComponentsZCA::train().
|
inline |
overwrite structure and parameters
Definition at line 151 of file LinearModel.h.
|
inline |
Definition at line 267 of file LinearModel.h.
|
inline |
Calculates the first derivative w.r.t the inputs and summs them up over all patterns of the last computed batch.
Definition at line 249 of file LinearModel.h.
|
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 221 of file LinearModel.h.
|
inlinevirtual |
From ISerializable.
Reimplemented from shark::AbstractModel< InputType, blas::vector< InputType::value_type, InputType::device_type >, blas::vector< InputType::value_type, InputType::device_type > >.
Definition at line 311 of file LinearModel.h.