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 (std::size_t inputs, std::size_t 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 (std::size_t inputs, std::size_t outputs, std::size_t numberOfTilings, std::size_t numberOfTiles, RealMatrix const &bounds, bool randomTiles=false)
 initializes the structure of the cmac More...
 
virtual std::size_t inputSize () const
 
virtual std::size_t outputSize () const
 
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, 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 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 (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 &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, 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 &parameterDerivative, 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::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 (ConstRealMatrixRow 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
 
std::size_t m_inputSize
 
std::size_t m_outputSize
 
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 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
 

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 128 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 134 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 ( ConstRealMatrixRow const &  point) const
protected

returns an index in the parameter array for each activated feature

§ inputSize()

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

Definition at line 105 of file CMAC.h.

References m_inputSize.

§ name()

std::string shark::CMACMap::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 81 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.

Definition at line 123 of file CMAC.h.

Referenced by setParameterVector().

§ outputSize()

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

Definition at line 109 of file CMAC.h.

References m_outputSize.

§ parameterVector()

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

Return the parameter vector.

Reimplemented from shark::IParameterizable.

Definition at line 114 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.

Definition at line 118 of file CMAC.h.

References numberOfParameters(), and SIZE_CHECK.

§ setStructure() [1/2]

SHARK_EXPORT_SYMBOL void shark::CMACMap::setStructure ( std::size_t  inputs,
std::size_t  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
inputsnumber of input dimensions
outputsnumber of output 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 ( std::size_t  inputs,
std::size_t  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,
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_inputSize

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

Definition at line 66 of file CMAC.h.

Referenced by inputSize().

§ m_offset

RealMatrix shark::CMACMap::m_offset
protected

offset of the position of every tiling

Definition at line 54 of file CMAC.h.

§ m_outputSize

std::size_t shark::CMACMap::m_outputSize
protected

Definition at line 67 of file CMAC.h.

Referenced by outputSize().

§ m_parameters

RealVector shark::CMACMap::m_parameters
protected

The parameters of the model.

Definition at line 70 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: