shark::CMACMap Class Reference

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 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< StatecreateState () 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 Featuresfeatures () 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< OutputTypeoperator() (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 &parameterDerivative, 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< FeatureFeatures
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 
- Public Types inherited from shark::IParameterizable< RealVector >
typedef RealVector ParameterVectorType
 

Detailed Description

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.

Definition at line 51 of file CMAC.h.

Constructor & Destructor Documentation

◆ CMACMap()

SHARK_EXPORT_SYMBOL shark::CMACMap::CMACMap ( )

construct the CMAC

Member Function Documentation

◆ createState()

boost::shared_ptr<State> shark::CMACMap::createState ( ) const
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.

◆ eval() [1/2]

SHARK_EXPORT_SYMBOL void shark::CMACMap::eval ( const RealMatrix &  patterns,
RealMatrix &  outputs 
) const

Referenced by createState(), and eval().

◆ eval() [2/2]

void shark::CMACMap::eval ( const RealMatrix &  patterns,
RealMatrix &  outputs,
State state 
) const
inline

Definition at line 132 of file CMAC.h.

References eval(), read(), SHARK_EXPORT_SYMBOL, weightedParameterDerivative(), and write().

◆ getArrayIndexForTiling()

SHARK_EXPORT_SYMBOL std::size_t shark::CMACMap::getArrayIndexForTiling ( std::size_t  indexOfTiling,
RealVector const &  point 
) const
protected

calculates the index in the parameter vector for the activated feature in the tiling

◆ getIndizes()

SHARK_EXPORT_SYMBOL std::vector<std::size_t> shark::CMACMap::getIndizes ( blas::matrix_row< const RealMatrix > const &  point) const
protected

returns an index in the parameter array for each activated feature

◆ inputShape()

Shape shark::CMACMap::inputShape ( ) const
inlinevirtual

Returns the expected shape of the input.

Implements shark::AbstractModel< RealVector, RealVector >.

Definition at line 107 of file CMAC.h.

References m_inputShape.

◆ name()

std::string shark::CMACMap::name ( ) const
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.

◆ numberOfParameters()

virtual std::size_t shark::CMACMap::numberOfParameters ( ) const
inlinevirtual

Return the number of parameters.

Reimplemented from shark::IParameterizable< RealVector >.

Definition at line 122 of file CMAC.h.

Referenced by setParameterVector().

◆ outputShape()

Shape shark::CMACMap::outputShape ( ) const
inlinevirtual

Returns the shape of the output.

Implements shark::AbstractModel< RealVector, RealVector >.

Definition at line 111 of file CMAC.h.

References m_outputShape.

◆ parameterVector()

virtual RealVector shark::CMACMap::parameterVector ( ) const
inlinevirtual

Return the parameter vector.

Reimplemented from shark::IParameterizable< RealVector >.

Definition at line 115 of file CMAC.h.

References m_parameters.

◆ read()

SHARK_EXPORT_SYMBOL void shark::CMACMap::read ( InArchive archive)
virtual

From ISerializable, reads a model from an archive.

Reimplemented from shark::AbstractModel< RealVector, RealVector >.

Referenced by eval().

◆ setParameterVector()

virtual void shark::CMACMap::setParameterVector ( RealVector const &  newParameters)
inlinevirtual

Set the parameter vector.

Reimplemented from shark::IParameterizable< RealVector >.

Definition at line 118 of file CMAC.h.

References numberOfParameters(), and SIZE_CHECK.

◆ setStructure() [1/2]

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]

Parameters
inputsShape of the input dimensions
outputsShape of the input dimensions
numberOfTilingsnumber of Tilings to be created
numberOfTilesamount of tiles per dimension
lowerlower bound of input values
upperupper bound of input values
randomTilesflag specifying whether distance between tiles is regular or randomized

Referenced by name().

◆ setStructure() [2/2]

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

Parameters
inputsnumber of input dimensions
outputsnumber of output dimensions
numberOfTilingsnumber of Tilings to be created
numberOfTilesamount of tiles per dimension
boundslower and upper bounts for every input dimension. every row consists of (lower,upper)
randomTilesflag specifying whether distance between tiles is regular or randomized

◆ weightedParameterDerivative()

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().

◆ write()

SHARK_EXPORT_SYMBOL void shark::CMACMap::write ( OutArchive archive) const
virtual

From ISerializable, writes a model to an archive.

Reimplemented from shark::AbstractModel< RealVector, RealVector >.

Referenced by eval().

Member Data Documentation

◆ m_dimOffset

std::vector<std::size_t> shark::CMACMap::m_dimOffset
protected

coordinate offset for every dimension in the Array

Definition at line 57 of file CMAC.h.

◆ m_inputShape

Shape shark::CMACMap::m_inputShape
protected

Definition at line 66 of file CMAC.h.

Referenced by inputShape().

◆ m_inputSize

std::size_t shark::CMACMap::m_inputSize
protected

Definition at line 67 of file CMAC.h.

◆ m_offset

RealMatrix shark::CMACMap::m_offset
protected

offset of the position of every tiling

Definition at line 54 of file CMAC.h.

◆ m_outputShape

Shape shark::CMACMap::m_outputShape
protected

Definition at line 68 of file CMAC.h.

Referenced by outputShape().

◆ m_parameters

RealVector shark::CMACMap::m_parameters
protected

The parameters of the model.

Definition at line 71 of file CMAC.h.

Referenced by parameterVector().

◆ m_parametersPerTiling

std::size_t shark::CMACMap::m_parametersPerTiling
protected

Definition at line 64 of file CMAC.h.

◆ m_tileBounds

RealMatrix shark::CMACMap::m_tileBounds
protected

lower bound and tileWidth for every Dimension

Definition at line 60 of file CMAC.h.

◆ m_tilings

std::size_t shark::CMACMap::m_tilings
protected

number of tilings

Definition at line 63 of file CMAC.h.


The documentation for this class was generated from the following file: