Linear Prediction. More...
#include <shark/Models/LinearModel.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 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 |
Public Member Functions | |
LinearModel () | |
CDefault Constructor; use setStructure later. More... | |
LinearModel (std::size_t inputs, std::size_t outputs=1, bool offset=false) | |
Constructor creating a model with given dimnsionalities and optional offset term. More... | |
LinearModel (LinearModel const &model) | |
copy constructor More... | |
std::string | name () const |
From INameable: return the class name. More... | |
LinearModel & | operator= (LinearModel const &model) |
operator = More... | |
LinearModel (RealMatrix const &matrix, RealVector const &offset=RealVector()) | |
Construction from matrix (and vector) More... | |
bool | hasOffset () const |
check for the presence of an offset term More... | |
size_t | inputSize () const |
obtain the input dimension More... | |
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... | |
size_t | numberOfParameters () const |
return the number of parameter More... | |
void | setStructure (std::size_t inputs, std::size_t outputs=1, bool offset=false) |
overwrite structure and parameters More... | |
void | setStructure (RealMatrix const &matrix, RealVector const &offset=RealVector()) |
overwrite structure and parameters More... | |
RealMatrix const & | matrix () const |
return a copy of the matrix in dense format More... | |
RealMatrix & | matrix () |
RealVector const & | offset () const |
return the offset More... | |
RealVector & | offset () |
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 (BatchInputType const &inputs, BatchOutputType &outputs, State &state) const |
Evaluate the model: output = matrix * input + offset. 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... | |
![]() | |
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... | |
![]() | |
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 () | |
Friends | |
void | swap (LinearModel &model1, LinearModel &model2) |
swap More... | |
Additional Inherited Members | |
![]() | |
Features | m_features |
Linear Prediction.
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 53 of file LinearModel.h.
typedef base_type::BatchInputType shark::LinearModel< InputType >::BatchInputType |
Definition at line 62 of file LinearModel.h.
typedef base_type::BatchOutputType shark::LinearModel< InputType >::BatchOutputType |
Definition at line 63 of file LinearModel.h.
|
inline |
CDefault Constructor; use setStructure later.
Definition at line 66 of file LinearModel.h.
|
inline |
Constructor creating a model with given dimnsionalities and optional offset term.
Definition at line 71 of file LinearModel.h.
|
inline |
copy constructor
Definition at line 77 of file LinearModel.h.
|
inline |
Construction from matrix (and vector)
Definition at line 101 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, RealVector >.
Definition at line 170 of file LinearModel.h.
|
inlinevirtual |
Evaluate the model: output = matrix * input + offset.
Reimplemented from shark::AbstractModel< InputType, RealVector >.
Definition at line 177 of file LinearModel.h.
Referenced by shark::LinearModel< VectorType >::eval().
|
inlinevirtual |
Evaluate the model: output = matrix * input + offset.
Implements shark::AbstractModel< InputType, RealVector >.
Definition at line 186 of file LinearModel.h.
|
inline |
check for the presence of an offset term
Definition at line 108 of file LinearModel.h.
Referenced by shark::LinearModel< VectorType >::eval(), and shark::LinearModel< VectorType >::weightedParameterDerivative().
|
inline |
obtain the input dimension
Definition at line 113 of file LinearModel.h.
Referenced by shark::LinearModel< VectorType >::weightedInputDerivative(), and shark::LinearModel< VectorType >::weightedParameterDerivative().
|
inline |
return a copy of the matrix in dense format
Definition at line 154 of file LinearModel.h.
Referenced by main(), and shark::LinearModel< VectorType >::setStructure().
|
inline |
Definition at line 158 of file LinearModel.h.
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 84 of file LinearModel.h.
|
inlinevirtual |
return the number of parameter
Reimplemented from shark::IParameterizable.
Definition at line 137 of file LinearModel.h.
Referenced by shark::LinearModel< VectorType >::parameterVector(), and shark::LinearModel< VectorType >::weightedParameterDerivative().
|
inline |
return the offset
Definition at line 163 of file LinearModel.h.
Referenced by main(), and shark::LinearModel< VectorType >::setStructure().
|
inline |
Definition at line 166 of file LinearModel.h.
|
inline |
operator =
Definition at line 94 of file LinearModel.h.
|
inline |
obtain the output dimension
Definition at line 118 of file LinearModel.h.
Referenced by shark::PCA::train(), shark::LassoRegression< InputVectorType >::train(), shark::LinearModel< VectorType >::weightedInputDerivative(), and shark::LinearModel< VectorType >::weightedParameterDerivative().
|
inlinevirtual |
obtain the parameter vector
Reimplemented from shark::IParameterizable.
Definition at line 123 of file LinearModel.h.
|
inlinevirtual |
From ISerializable.
Reimplemented from shark::AbstractModel< InputType, RealVector >.
Definition at line 226 of file LinearModel.h.
|
inlinevirtual |
overwrite the parameter vector
Reimplemented from shark::IParameterizable.
Definition at line 131 of file LinearModel.h.
Referenced by main().
|
inline |
overwrite structure and parameters
Definition at line 142 of file LinearModel.h.
Referenced by shark::NormalizeComponentsWhitening::train(), shark::NormalizeComponentsZCA::train(), and shark::LassoRegression< InputVectorType >::train().
|
inline |
overwrite structure and parameters
Definition at line 148 of file LinearModel.h.
|
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< InputType, RealVector >.
Definition at line 212 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 191 of file LinearModel.h.
|
inlinevirtual |
From ISerializable.
Reimplemented from shark::AbstractModel< InputType, RealVector >.
Definition at line 231 of file LinearModel.h.
|
friend |
swap
Definition at line 88 of file LinearModel.h.
Referenced by shark::LinearModel< VectorType >::operator=(), and shark::LinearModel< VectorType >::setStructure().