The CMACMap class represents a linear combination of piecewise constant functions. More...
#include <shark/Models/CMAC.h>
Inheritance diagram for shark::CMACMap:Public Member Functions | |
| SHARK_EXPORT_SYMBOL | CMACMap () |
| construct the CMAC | |
| std::string | name () const |
| From INameable: return the class name. | |
| SHARK_EXPORT_SYMBOL void | setStructure (Shape const &inputs, Shape const &outputs, std::size_t numberOfTilings, std::size_t numberOfTiles, double lower=0., double upper=1., bool randomTiles=false) |
| initializes the structure of the cmac. it uses the same lower and upper bound for every input dimension. default is [0,1] | |
| SHARK_EXPORT_SYMBOL void | setStructure (Shape const &inputs, Shape const &outputs, std::size_t numberOfTilings, std::size_t numberOfTiles, RealMatrix const &bounds, bool randomTiles=false) |
| initializes the structure of the cmac | |
| Shape | inputShape () const |
| Returns the expected shape of the input. | |
| Shape | outputShape () const |
| Returns the shape of the output. | |
| virtual RealVector | parameterVector () const |
| Return the parameter vector. | |
| virtual void | setParameterVector (RealVector const &newParameters) |
| Set the parameter vector. | |
| virtual std::size_t | numberOfParameters () const |
| Return the number of parameters. | |
| boost::shared_ptr< State > | createState () const |
| Creates an internal state of the model. | |
| SHARK_EXPORT_SYMBOL void | eval (const RealMatrix &patterns, RealMatrix &outputs) const |
| void | eval (const RealMatrix &patterns, RealMatrix &outputs, State &state) const |
| SHARK_EXPORT_SYMBOL void | weightedParameterDerivative (RealMatrix const &pattern, BatchOutputType const &outputs, RealMatrix const &coefficients, State const &state, RealVector &gradient) const |
| SHARK_EXPORT_SYMBOL void | read (InArchive &archive) |
| From ISerializable, reads a model from an archive. | |
| SHARK_EXPORT_SYMBOL void | write (OutArchive &archive) const |
| From ISerializable, writes a model to an archive. | |
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. | |
| bool | hasFirstInputDerivative () const |
| Returns true when the first input derivative is implemented. | |
| virtual void | eval (BatchInputType const &patterns, BatchOutputType &outputs) const |
| Standard interface for evaluating the response of the model to a batch of patterns. | |
| virtual void | eval (BatchInputType const &patterns, BatchOutputType &outputs, State &state) const=0 |
| Standard interface for evaluating the response of the model to a batch of patterns. | |
| virtual void | eval (InputType const &pattern, OutputType &output) const |
| Standard interface for evaluating the response of the model to a single pattern. | |
| Data< OutputType > | operator() (Data< InputType > const &patterns) const |
| Model evaluation as an operator for a whole dataset. This is a convenience function. | |
| OutputType | operator() (InputType const &pattern) const |
| Model evaluation as an operator for a single pattern. This is a convenience function. | |
| BatchOutputType | operator() (BatchInputType const &patterns) const |
| Model evaluation as an operator for a single pattern. This is a convenience function. | |
| virtual void | weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, RealVector &derivative) const |
| calculates the weighted sum of derivatives w.r.t the parameters. | |
| virtual void | weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const |
| calculates the weighted sum of derivatives w.r.t the inputs | |
| virtual void | weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, RealVector ¶meterDerivative, BatchInputType &inputDerivative) const |
| calculates weighted input and parameter derivative at the same time | |
Public Member Functions inherited from shark::IParameterizable< VectorType > | |
| virtual | ~IParameterizable () |
Public Member Functions inherited from shark::INameable | |
| virtual | ~INameable () |
Public Member Functions inherited from shark::ISerializable | |
| virtual | ~ISerializable () |
| Virtual d'tor. | |
| void | load (InArchive &archive, unsigned int version) |
| Versioned loading of components, calls read(...). | |
| void | save (OutArchive &archive, unsigned int version) const |
| Versioned storing of components, calls write(...). | |
| BOOST_SERIALIZATION_SPLIT_MEMBER () | |
Protected Member Functions | |
| SHARK_EXPORT_SYMBOL std::size_t | getArrayIndexForTiling (std::size_t indexOfTiling, RealVector const &point) const |
| calculates the index in the parameter vector for the activated feature in the tiling | |
| SHARK_EXPORT_SYMBOL std::vector< std::size_t > | getIndizes (blas::dense_vector_adaptor< double const > const &point) const |
| returns an index in the parameter array for each activated feature | |
Protected Attributes | |
| RealMatrix | m_offset |
| offset of the position of every tiling | |
| std::vector< std::size_t > | m_dimOffset |
| coordinate offset for every dimension in the Array | |
| RealMatrix | m_tileBounds |
| lower bound and tileWidth for every Dimension | |
| std::size_t | m_tilings |
| number of tilings | |
| std::size_t | m_parametersPerTiling |
| Shape | m_inputShape |
| std::size_t | m_inputSize |
| Shape | m_outputShape |
| RealVector | m_parameters |
| The parameters of the model. | |
Protected Attributes inherited from shark::AbstractModel< RealVector, RealVector > | |
| Features | m_features |
Additional Inherited Members | |
Public Types inherited from shark::AbstractModel< RealVector, RealVector > | |
| enum | Feature |
| typedef RealVector | InputType |
| Defines the input type of the model. | |
| typedef RealVector | OutputType |
| Defines the output type of the model. | |
| typedef AbstractModel< RealVector, RealVector, RealVector > | ModelBaseType |
| Defines the BaseType used by the model (this type). Useful for creating derived models. | |
| typedef Batch< InputType >::type | BatchInputType |
| defines the batch type of the input type. | |
| typedef Batch< OutputType >::type | BatchOutputType |
| defines the batch type of the output type | |
| typedef TypedFlags< Feature > | Features |
| typedef TypedFeatureNotAvailableException< Feature > | FeatureNotAvailableException |
Public Types inherited from shark::IParameterizable< VectorType > | |
| typedef VectorType | ParameterVectorType |
The CMACMap class represents a linear combination of piecewise constant functions.
when a point is fed into the CMAC, it is first mapped into a vector of binary features. For this purpose the inputspace is divided into several tilings. Every tiling produces a bitstring where an element is 1 if the point lies inside the tile, 0 otherwise. The concatenation of all tilings forms the feature vector which is then fed into a linear function. Usually the CMAC is only good for low dimensional input data since the size of the featurevector grows exponentially with the number of dimensions.
| SHARK_EXPORT_SYMBOL shark::CMACMap::CMACMap | ( | ) |
construct the CMAC
|
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 >.
| SHARK_EXPORT_SYMBOL void shark::CMACMap::eval | ( | const RealMatrix & | patterns, |
| RealMatrix & | outputs | ||
| ) | const |
Referenced by eval().
|
inline |
|
protected |
calculates the index in the parameter vector for the activated feature in the tiling
|
protected |
returns an index in the parameter array for each activated feature
|
inlinevirtual |
Returns the expected shape of the input.
Implements shark::AbstractModel< RealVector, RealVector >.
Definition at line 108 of file CMAC.h.
References m_inputShape.
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
|
inlinevirtual |
Return the number of parameters.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 123 of file CMAC.h.
References m_parameters.
Referenced by setParameterVector().
|
inlinevirtual |
Returns the shape of the output.
Implements shark::AbstractModel< RealVector, RealVector >.
Definition at line 112 of file CMAC.h.
References m_outputShape.
|
inlinevirtual |
Return the parameter vector.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 116 of file CMAC.h.
References m_parameters.
|
virtual |
From ISerializable, reads a model from an archive.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
|
inlinevirtual |
Set the parameter vector.
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 119 of file CMAC.h.
References m_parameters, numberOfParameters(), and SIZE_CHECK.
| SHARK_EXPORT_SYMBOL void shark::CMACMap::setStructure | ( | Shape const & | inputs, |
| Shape const & | outputs, | ||
| std::size_t | numberOfTilings, | ||
| std::size_t | numberOfTiles, | ||
| double | lower = 0., |
||
| double | upper = 1., |
||
| bool | randomTiles = false |
||
| ) |
initializes the structure of the cmac. it uses the same lower and upper bound for every input dimension. default is [0,1]
| inputs | Shape of the input dimensions |
| outputs | Shape of the input dimensions |
| numberOfTilings | number of Tilings to be created |
| numberOfTiles | amount of tiles per dimension |
| lower | lower bound of input values |
| upper | upper bound of input values |
| randomTiles | flag specifying whether distance between tiles is regular or randomized |
| SHARK_EXPORT_SYMBOL void shark::CMACMap::setStructure | ( | Shape const & | inputs, |
| Shape const & | outputs, | ||
| std::size_t | numberOfTilings, | ||
| std::size_t | numberOfTiles, | ||
| RealMatrix const & | bounds, | ||
| bool | randomTiles = false |
||
| ) |
initializes the structure of the cmac
| inputs | number of input dimensions |
| outputs | number of output dimensions |
| numberOfTilings | number of Tilings to be created |
| numberOfTiles | amount of tiles per dimension |
| bounds | lower and upper bounts for every input dimension. every row consists of (lower,upper) |
| randomTiles | flag specifying whether distance between tiles is regular or randomized |
| SHARK_EXPORT_SYMBOL void shark::CMACMap::weightedParameterDerivative | ( | RealMatrix const & | pattern, |
| BatchOutputType const & | outputs, | ||
| RealMatrix const & | coefficients, | ||
| State const & | state, | ||
| RealVector & | gradient | ||
| ) | const |
|
virtual |
From ISerializable, writes a model to an archive.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
|
protected |
|
protected |
Definition at line 67 of file CMAC.h.
Referenced by inputShape().
|
protected |
|
protected |
Definition at line 69 of file CMAC.h.
Referenced by outputShape().
|
protected |
The parameters of the model.
Definition at line 72 of file CMAC.h.
Referenced by numberOfParameters(), parameterVector(), and setParameterVector().
|
protected |
|
protected |