The CMACMap class represents a linear combination of piecewise constant functions. More...
#include <shark/Models/CMAC.h>
Public Member Functions | |
SHARK_EXPORT_SYMBOL | CMACMap () |
construct the CMAC More... | |
std::string | name () const |
From INameable: return the class name. More... | |
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] More... | |
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 More... | |
Shape | inputShape () const |
Returns the expected shape of the input. More... | |
Shape | outputShape () const |
Returns the shape of the output. More... | |
virtual RealVector | parameterVector () const |
Return the parameter vector. More... | |
virtual void | setParameterVector (RealVector const &newParameters) |
Set the parameter vector. More... | |
virtual std::size_t | numberOfParameters () const |
Return the number of parameters. More... | |
boost::shared_ptr< State > | createState () const |
Creates an internal state of the model. More... | |
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. More... | |
SHARK_EXPORT_SYMBOL void | write (OutArchive &archive) const |
From ISerializable, writes a model to an archive. 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 | hasFirstInputDerivative () const |
Returns true when the first input derivative is implemented. More... | |
virtual void | eval (BatchInputType const &patterns, BatchOutputType &outputs) const |
Standard interface for evaluating the response of the model to a batch of patterns. More... | |
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. More... | |
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 &outputs, 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 &outputs, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const |
calculates the weighted sum of derivatives w.r.t the inputs More... | |
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 More... | |
Public Member Functions inherited from shark::IParameterizable< RealVector > | |
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 () | |
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 More... | |
SHARK_EXPORT_SYMBOL std::vector< std::size_t > | getIndizes (blas::matrix_row< const RealMatrix > const &point) const |
returns an index in the parameter array for each activated feature More... | |
Protected Attributes | |
RealMatrix | m_offset |
offset of the position of every tiling More... | |
std::vector< std::size_t > | m_dimOffset |
coordinate offset for every dimension in the Array More... | |
RealMatrix | m_tileBounds |
lower bound and tileWidth for every Dimension More... | |
std::size_t | m_tilings |
number of tilings More... | |
std::size_t | m_parametersPerTiling |
Shape | m_inputShape |
std::size_t | m_inputSize |
Shape | m_outputShape |
RealVector | m_parameters |
The parameters of the model. More... | |
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. More... | |
typedef RealVector | OutputType |
Defines the output type of the model. More... | |
typedef AbstractModel< RealVector, RealVector, RealVector > | ModelBaseType |
Defines the BaseType used by the model (this type). Useful for creating derived models. 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 Types inherited from shark::IParameterizable< RealVector > | |
typedef RealVector | 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 >.
Definition at line 126 of file CMAC.h.
References eval(), and SHARK_EXPORT_SYMBOL.
SHARK_EXPORT_SYMBOL void shark::CMACMap::eval | ( | const RealMatrix & | patterns, |
RealMatrix & | outputs | ||
) | const |
Referenced by createState(), and eval().
|
inline |
Definition at line 132 of file CMAC.h.
References eval(), read(), SHARK_EXPORT_SYMBOL, weightedParameterDerivative(), and write().
|
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 107 of file CMAC.h.
References m_inputShape.
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 82 of file CMAC.h.
References setStructure(), and SHARK_EXPORT_SYMBOL.
|
inlinevirtual |
Return the number of parameters.
Reimplemented from shark::IParameterizable< RealVector >.
Definition at line 122 of file CMAC.h.
Referenced by setParameterVector().
|
inlinevirtual |
Returns the shape of the output.
Implements shark::AbstractModel< RealVector, RealVector >.
Definition at line 111 of file CMAC.h.
References m_outputShape.
|
inlinevirtual |
Return the parameter vector.
Reimplemented from shark::IParameterizable< RealVector >.
Definition at line 115 of file CMAC.h.
References m_parameters.
|
virtual |
From ISerializable, reads a model from an archive.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Referenced by eval().
|
inlinevirtual |
Set the parameter vector.
Reimplemented from shark::IParameterizable< RealVector >.
Definition at line 118 of file CMAC.h.
References 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 |
Referenced by name().
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 |
Referenced by eval().
|
virtual |
From ISerializable, writes a model to an archive.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Referenced by eval().
|
protected |
|
protected |
Definition at line 66 of file CMAC.h.
Referenced by inputShape().
|
protected |
|
protected |
Definition at line 68 of file CMAC.h.
Referenced by outputShape().
|
protected |
|
protected |
|
protected |