Linear Prediction. More...
#include <shark/Models/LinearModel.h>
Inheritance diagram for shark::LinearModel< InputType, OutputType >:
Collaboration diagram for shark::LinearModel< InputType, OutputType >:Public Types | |
| typedef base_type::BatchInputType | BatchInputType |
| typedef base_type::BatchOutputType | BatchOutputType |
Public Types inherited from shark::AbstractModel< InputType, OutputType > | |
| 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 | |
| LinearModel () | |
| Constructor of an invalid model; use setStructure later. More... | |
| LinearModel (const self_type &model) | |
| copy constructor More... | |
| std::string | name () const |
| From INameable: return the class name. More... | |
| const self_type | operator= (const self_type &model) |
| operator = More... | |
| LinearModel (unsigned int inputs, unsigned int outputs=1, bool offset=false, bool sparse=false) | |
| Constructor. More... | |
| LinearModel (RealMatrix const &matrix) | |
| Construction from matrix. More... | |
| LinearModel (RealMatrix const &matrix, OutputType offset) | |
| Construction from matrix and vector. More... | |
| LinearModel (CompressedRealMatrix const &matrix) | |
| Construction from matrix. More... | |
| LinearModel (CompressedRealMatrix const &matrix, RealVector offset) | |
| 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 (RealMatrix const &matrix) |
| overwrite structure and parameters More... | |
| void | setStructure (unsigned int inputs, unsigned int outputs=1, bool offset=false, bool sparse=false) |
| overwrite structure and parameters More... | |
| void | setStructure (RealMatrix const &matrix, const RealVector &offset) |
| overwrite structure and parameters More... | |
| void | setStructure (CompressedRealMatrix const &matrix) |
| overwrite structure and parameters More... | |
| void | setStructure (CompressedRealMatrix const &matrix, const RealVector &offset) |
| overwrite structure and parameters More... | |
| RealMatrix | matrix () const |
| return a copy of the matrix in dense format More... | |
| OutputType const & | offset () const |
| return the offset More... | |
| RealVector | matrixRow (size_t index) const |
| return a copy of a row of the matrix in dense format More... | |
| RealVector | matrixColumn (size_t index) const |
| return a copy of a column of the matrix in dense format More... | |
| boost::shared_ptr< State > | createState () const |
| Creates an internal state of the model. More... | |
| void | eval (BatchInputType const &input, BatchOutputType &output) const |
| Evaluate the model: output = matrix * input + offset. More... | |
| void | eval (BatchInputType const &input, BatchOutputType &output, State &state) const |
| Evaluate the model: output = matrix * input + offset. More... | |
| void | weightedParameterDerivative (BatchInputType const &pattern, 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 | weightedParameterDerivative (BatchInputType const &patterns, 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... | |
| void | read (InArchive &archive) |
| From ISerializable. More... | |
| void | write (OutArchive &archive) const |
| From ISerializable. More... | |
Public Member Functions inherited from shark::AbstractModel< InputType, OutputType > | |
| 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 | 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 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::IConfigurable | |
| virtual | ~IConfigurable () |
| Virtual d'tor. More... | |
| virtual void | configure (const PropertyTree &node) |
| Configures the component given a property tree. 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 () | |
Friends | |
| void | swap (const LinearModel &model1, const LinearModel &model2) |
| swap More... | |
Additional Inherited Members | |
Protected Attributes inherited from shark::AbstractModel< InputType, OutputType > | |
| Features | m_features |
Linear Prediction.
Definition at line 57 of file LinearModel.h.
| typedef base_type::BatchInputType shark::LinearModel< InputType, OutputType >::BatchInputType |
Definition at line 66 of file LinearModel.h.
| typedef base_type::BatchOutputType shark::LinearModel< InputType, OutputType >::BatchOutputType |
Definition at line 67 of file LinearModel.h.
|
inline |
Constructor of an invalid model; use setStructure later.
Definition at line 70 of file LinearModel.h.
References shark::AbstractModel< InputType, OutputType >::HAS_FIRST_PARAMETER_DERIVATIVE, shark::AbstractModel< InputType, OutputType >::HAS_SECOND_PARAMETER_DERIVATIVE, and shark::AbstractModel< InputType, OutputType >::m_features.
|
inline |
copy constructor
Definition at line 75 of file LinearModel.h.
References shark::AbstractModel< InputType, OutputType >::HAS_FIRST_PARAMETER_DERIVATIVE, shark::AbstractModel< InputType, OutputType >::HAS_SECOND_PARAMETER_DERIVATIVE, and shark::AbstractModel< InputType, OutputType >::m_features.
|
inline |
Constructor.
Definition at line 96 of file LinearModel.h.
References shark::AbstractModel< InputType, OutputType >::HAS_FIRST_PARAMETER_DERIVATIVE, shark::AbstractModel< InputType, OutputType >::HAS_SECOND_PARAMETER_DERIVATIVE, shark::AbstractModel< InputType, OutputType >::m_features, and shark::LinearModel< InputType, OutputType >::offset().
|
inline |
Construction from matrix.
Definition at line 107 of file LinearModel.h.
References shark::AbstractModel< InputType, OutputType >::HAS_FIRST_PARAMETER_DERIVATIVE, shark::AbstractModel< InputType, OutputType >::HAS_SECOND_PARAMETER_DERIVATIVE, and shark::AbstractModel< InputType, OutputType >::m_features.
|
inline |
Construction from matrix and vector.
Definition at line 114 of file LinearModel.h.
References shark::AbstractModel< InputType, OutputType >::HAS_FIRST_PARAMETER_DERIVATIVE, shark::AbstractModel< InputType, OutputType >::HAS_SECOND_PARAMETER_DERIVATIVE, and shark::AbstractModel< InputType, OutputType >::m_features.
|
inline |
Construction from matrix.
Definition at line 121 of file LinearModel.h.
References shark::AbstractModel< InputType, OutputType >::HAS_FIRST_PARAMETER_DERIVATIVE, shark::AbstractModel< InputType, OutputType >::HAS_SECOND_PARAMETER_DERIVATIVE, and shark::AbstractModel< InputType, OutputType >::m_features.
|
inline |
Construction from matrix and vector.
Definition at line 128 of file LinearModel.h.
References shark::AbstractModel< InputType, OutputType >::HAS_FIRST_PARAMETER_DERIVATIVE, shark::AbstractModel< InputType, OutputType >::HAS_SECOND_PARAMETER_DERIVATIVE, and 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 228 of file LinearModel.h.
References SHARK_CHECK.
|
inlinevirtual |
Evaluate the model: output = matrix * input + offset.
Reimplemented from shark::AbstractModel< InputType, OutputType >.
Definition at line 236 of file LinearModel.h.
References SHARK_CHECK.
|
inlinevirtual |
Evaluate the model: output = matrix * input + offset.
Implements shark::AbstractModel< InputType, OutputType >.
Definition at line 241 of file LinearModel.h.
References SHARK_CHECK.
|
inline |
check for the presence of an offset term
Definition at line 135 of file LinearModel.h.
References SHARK_CHECK.
Referenced by shark::LinearMcSvmOVATrainer::train(), shark::LinearMcSvmMMRTrainer::train(), shark::LinearMcSvmADMTrainer::train(), shark::LinearMcSvmLLWTrainer::train(), shark::LinearMcSvmATMTrainer::train(), shark::LinearMcSvmCSTrainer::train(), shark::LinearMcSvmWWTrainer::train(), shark::LinearCSvmTrainer::train(), and shark::LinearMcSvmATSTrainer::train().
|
inline |
obtain the input dimension
Definition at line 141 of file LinearModel.h.
References SHARK_CHECK.
Referenced by shark::LinearMcSvmOVATrainer::train(), shark::LinearMcSvmMMRTrainer::train(), shark::LinearMcSvmADMTrainer::train(), shark::LinearMcSvmLLWTrainer::train(), shark::LinearMcSvmATMTrainer::train(), shark::LinearMcSvmCSTrainer::train(), shark::LinearMcSvmWWTrainer::train(), shark::LinearCSvmTrainer::train(), and shark::LinearMcSvmATSTrainer::train().
|
inline |
return a copy of the matrix in dense format
Definition at line 201 of file LinearModel.h.
References SHARK_CHECK.
Referenced by main().
|
inline |
return a copy of a column of the matrix in dense format
Definition at line 221 of file LinearModel.h.
References SHARK_CHECK.
|
inline |
return a copy of a row of the matrix in dense format
Definition at line 213 of file LinearModel.h.
References SHARK_CHECK.
Referenced by main().
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 81 of file LinearModel.h.
|
inlinevirtual |
return the number of parameter
Reimplemented from shark::IParameterizable.
Definition at line 166 of file LinearModel.h.
References SHARK_CHECK.
|
inline |
return the offset
Definition at line 207 of file LinearModel.h.
References SHARK_CHECK.
Referenced by shark::LinearModel< InputType, OutputType >::LinearModel(), main(), and shark::LinearModel< InputType, OutputType >::setStructure().
|
inline |
operator =
Definition at line 90 of file LinearModel.h.
References shark::LinearModel< InputType, OutputType >::swap.
|
inline |
obtain the output dimension
Definition at line 147 of file LinearModel.h.
References SHARK_CHECK.
Referenced by shark::PCA::train(), shark::LassoRegression< InputVectorType >::train(), shark::LinearMcSvmOVATrainer::train(), shark::LinearMcSvmMMRTrainer::train(), shark::LinearMcSvmADMTrainer::train(), shark::LinearMcSvmLLWTrainer::train(), shark::LinearMcSvmATMTrainer::train(), shark::LinearMcSvmCSTrainer::train(), shark::LinearMcSvmWWTrainer::train(), shark::LinearCSvmTrainer::train(), and shark::LinearMcSvmATSTrainer::train().
|
inlinevirtual |
obtain the parameter vector
Reimplemented from shark::IParameterizable.
Definition at line 153 of file LinearModel.h.
References SHARK_CHECK.
|
inlinevirtual |
From ISerializable.
Reimplemented from shark::AbstractModel< InputType, OutputType >.
Definition at line 264 of file LinearModel.h.
|
inlinevirtual |
overwrite the parameter vector
Reimplemented from shark::IParameterizable.
Definition at line 159 of file LinearModel.h.
References SHARK_CHECK.
Referenced by main().
|
inline |
overwrite structure and parameters
Definition at line 172 of file LinearModel.h.
Referenced by shark::PCA::decoder(), shark::PCA::encoder(), shark::NormalizeComponentsWhitening< VectorType >::train(), shark::LinearRegression::train(), shark::FisherLDA::train(), shark::LassoRegression< InputVectorType >::train(), shark::LinearMcSvmOVATrainer::train(), shark::LinearMcSvmMMRTrainer::train(), shark::LinearMcSvmADMTrainer::train(), shark::LinearMcSvmLLWTrainer::train(), shark::LinearMcSvmATMTrainer::train(), shark::LinearMcSvmCSTrainer::train(), shark::LinearMcSvmWWTrainer::train(), shark::LinearCSvmTrainer::train(), and shark::LinearMcSvmATSTrainer::train().
|
inline |
overwrite structure and parameters
Definition at line 177 of file LinearModel.h.
References shark::LinearModel< InputType, OutputType >::offset().
|
inline |
overwrite structure and parameters
Definition at line 185 of file LinearModel.h.
|
inline |
overwrite structure and parameters
Definition at line 190 of file LinearModel.h.
|
inline |
overwrite structure and parameters
Definition at line 195 of file LinearModel.h.
References SHARK_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 247 of file LinearModel.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 |
| errorHessian | the second derivative of the error function for every pattern |
| state | intermediate results stored by eval to sped up calculations of the derivatives |
| derivative | the calculated derivative as sum over all derivates of all patterns |
| hessian | the calculated hessian as sum over all derivates of all patterns |
Reimplemented from shark::AbstractModel< InputType, OutputType >.
Definition at line 252 of file LinearModel.h.
|
inlinevirtual |
From ISerializable.
Reimplemented from shark::AbstractModel< InputType, OutputType >.
Definition at line 272 of file LinearModel.h.
|
friend |
swap
Definition at line 85 of file LinearModel.h.
Referenced by shark::LinearModel< InputType, OutputType >::operator=().