shark::RBFLayer Class Reference

Implements a layer of radial basis functions in a neural network. More...

#include <shark/Models/RBFLayer.h>

+ Inheritance diagram for shark::RBFLayer:

Public Member Functions

SHARK_EXPORT_SYMBOL RBFLayer ()
 Creates an empty Radial Basis Function layer. More...
 
SHARK_EXPORT_SYMBOL RBFLayer (std::size_t numInput, std::size_t numOutput)
 Creates a layer of a Radial Basis Function Network. More...
 
std::string name () const
 From INameable: return the class name. More...
 
SHARK_EXPORT_SYMBOL RealVector parameterVector () const
 Returns the current parameter vector. The amount and order of weights depend on the training parameters. More...
 
SHARK_EXPORT_SYMBOL void setParameterVector (RealVector const &newParameters)
 Sets the new internal parameters. More...
 
SHARK_EXPORT_SYMBOL std::size_t numberOfParameters () const
 Returns the number of parameters which are currently enabled for training. More...
 
Shape inputShape () const
 Returns the number of input neurons. More...
 
Shape outputShape () const
 Returns the number of output neurons. More...
 
boost::shared_ptr< StatecreateState () const
 Creates an internal state of the model. More...
 
SHARK_EXPORT_SYMBOL void setStructure (std::size_t numInput, std::size_t numOutput)
 Configures a Radial Basis Function Network. More...
 
SHARK_EXPORT_SYMBOL void eval (BatchInputType const &patterns, BatchOutputType &outputs, State &state) const
 Standard interface for evaluating the response of the model to a batch of patterns. More...
 
SHARK_EXPORT_SYMBOL void weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, RealVector &gradient) const
 calculates the weighted sum of derivatives w.r.t the parameters. More...
 
SHARK_EXPORT_SYMBOL void setTrainingParameters (bool centers, bool width)
 Enables or disables parameters for learning. More...
 
BatchInputType const & centers () const
 Returns the center values of the neurons. More...
 
BatchInputTypecenters ()
 Sets the center values of the neurons. More...
 
RealVector const & gamma () const
 Returns the width parameter of the Gaussian functions. More...
 
SHARK_EXPORT_SYMBOL void setGamma (RealVector const &gamma)
 sets the width parameters - the gamma values - of the distributions. More...
 
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 (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 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 Attributes

RealMatrix m_centers
 The center points. The i-th element corresponds to the center of neuron number i. More...
 
RealVector m_gamma
 stores the width parameters of the Gaussian functions More...
 
RealVector m_logNormalization
 the logarithm of the normalization constant for every distribution More...
 
bool m_trainCenters
 enables learning of the center points of the neurons More...
 
bool m_trainWidth
 enables learning of the width parameters. 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

Implements a layer of radial basis functions in a neural network.

A Radial basis function layer as modeled in shark is a set of N Gaussian distributions \( p(x|i) \).

\[ p(x|i) = e^{\gamma_i*\|x-m_i\|^2} \]

and the layer transforms an input x to a vector \((p(x|1),\dots,p(x|N)\). The \(\gamma_i\) govern the width of the Gaussians, while the vectors \( m_i \) set the centers of every Gaussian distribution.

RBF networks profit much from good guesses on the centers and kernel function parameters. In case of a Gaussian kernel a call to k-Means or the EM-algorithm can be used to get a good initialisation for the network.

Definition at line 55 of file RBFLayer.h.

Constructor & Destructor Documentation

◆ RBFLayer() [1/2]

SHARK_EXPORT_SYMBOL shark::RBFLayer::RBFLayer ( )

Creates an empty Radial Basis Function layer.

◆ RBFLayer() [2/2]

SHARK_EXPORT_SYMBOL shark::RBFLayer::RBFLayer ( std::size_t  numInput,
std::size_t  numOutput 
)

Creates a layer of a Radial Basis Function Network.

This method creates a Radial Basis Function Network (RBFN) with numInput input neurons and numOutput output neurons.

Parameters
numInputNumber of input neurons, equal to dimensionality of input space.
numOutputNumber of output neurons, equal to dimensionality of output space and number of gaussian distributions

Member Function Documentation

◆ centers() [1/2]

BatchInputType const& shark::RBFLayer::centers ( ) const
inline

Returns the center values of the neurons.

Definition at line 141 of file RBFLayer.h.

References m_centers.

Referenced by createState(), and main().

◆ centers() [2/2]

BatchInputType& shark::RBFLayer::centers ( )
inline

Sets the center values of the neurons.

Definition at line 145 of file RBFLayer.h.

References m_centers.

◆ createState()

boost::shared_ptr<State> shark::RBFLayer::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 107 of file RBFLayer.h.

References centers(), eval(), setStructure(), setTrainingParameters(), SHARK_EXPORT_SYMBOL, and weightedParameterDerivative().

◆ eval()

SHARK_EXPORT_SYMBOL void shark::RBFLayer::eval ( BatchInputType const &  patterns,
BatchOutputType outputs,
State state 
) const
virtual

Standard interface for evaluating the response of the model to a batch of patterns.

Parameters
patternsthe inputs of the model
outputsthe predictions or response of the model to every pattern
stateintermediate results stored by eval which can be reused for derivative computation.

Implements shark::AbstractModel< RealVector, RealVector >.

Referenced by createState().

◆ gamma()

RealVector const& shark::RBFLayer::gamma ( ) const
inline

Returns the width parameter of the Gaussian functions.

Definition at line 150 of file RBFLayer.h.

References m_gamma, read(), setGamma(), SHARK_EXPORT_SYMBOL, and write().

Referenced by main().

◆ inputShape()

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

Returns the number of input neurons.

Implements shark::AbstractModel< RealVector, RealVector >.

Definition at line 98 of file RBFLayer.h.

References m_centers.

◆ name()

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

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 82 of file RBFLayer.h.

References numberOfParameters(), parameterVector(), setParameterVector(), and SHARK_EXPORT_SYMBOL.

◆ numberOfParameters()

SHARK_EXPORT_SYMBOL std::size_t shark::RBFLayer::numberOfParameters ( ) const
virtual

Returns the number of parameters which are currently enabled for training.

Reimplemented from shark::IParameterizable< RealVector >.

Referenced by name().

◆ outputShape()

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

Returns the number of output neurons.

Implements shark::AbstractModel< RealVector, RealVector >.

Definition at line 103 of file RBFLayer.h.

References m_centers.

◆ parameterVector()

SHARK_EXPORT_SYMBOL RealVector shark::RBFLayer::parameterVector ( ) const
virtual

Returns the current parameter vector. The amount and order of weights depend on the training parameters.

The format of the parameter vector is \( (m_1,\dots,m_k,\log(\gamma_1),\dots,\log(\gamma_k))\) if training of one or more parameters is deactivated, they are removed from the parameter vector

Reimplemented from shark::IParameterizable< RealVector >.

Referenced by name().

◆ read()

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

From ISerializable, reads a model from an archive.

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

Referenced by gamma().

◆ setGamma()

SHARK_EXPORT_SYMBOL void shark::RBFLayer::setGamma ( RealVector const &  gamma)

sets the width parameters - the gamma values - of the distributions.

Referenced by gamma().

◆ setParameterVector()

SHARK_EXPORT_SYMBOL void shark::RBFLayer::setParameterVector ( RealVector const &  newParameters)
virtual

Sets the new internal parameters.

Reimplemented from shark::IParameterizable< RealVector >.

Referenced by name().

◆ setStructure()

SHARK_EXPORT_SYMBOL void shark::RBFLayer::setStructure ( std::size_t  numInput,
std::size_t  numOutput 
)

Configures a Radial Basis Function Network.

This method initializes the structure of the Radial Basis Function Network (RBFN) with numInput input neurons, numOutput output neurons and numHidden hidden neurons.

Parameters
numInputNumber of input neurons, equal to dimensionality of input space.
numOutputNumber of output neurons (basis functions), equal to dimensionality of output space.

Referenced by createState(), and main().

◆ setTrainingParameters()

SHARK_EXPORT_SYMBOL void shark::RBFLayer::setTrainingParameters ( bool  centers,
bool  width 
)

Enables or disables parameters for learning.

Parameters
centerswhether the centers should be trained
widthwhether the distribution width should be trained

Referenced by createState().

◆ weightedParameterDerivative()

SHARK_EXPORT_SYMBOL void shark::RBFLayer::weightedParameterDerivative ( BatchInputType const &  pattern,
BatchOutputType const &  outputs,
BatchOutputType const &  coefficients,
State const &  state,
RealVector &  derivative 
) const
virtual

calculates the weighted sum of derivatives w.r.t the parameters.

Parameters
patternthe patterns to evaluate
coefficientsthe coefficients which are used to calculate the weighted sum for every pattern
stateintermediate results stored by eval to speed up calculations of the derivatives
derivativethe calculated derivative as sum over all derivates of all patterns

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

Referenced by createState().

◆ write()

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

From ISerializable, writes a model to an archive.

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

Referenced by gamma().

Member Data Documentation

◆ m_centers

RealMatrix shark::RBFLayer::m_centers
protected

The center points. The i-th element corresponds to the center of neuron number i.

Definition at line 166 of file RBFLayer.h.

Referenced by centers(), inputShape(), and outputShape().

◆ m_gamma

RealVector shark::RBFLayer::m_gamma
protected

stores the width parameters of the Gaussian functions

Definition at line 169 of file RBFLayer.h.

Referenced by gamma().

◆ m_logNormalization

RealVector shark::RBFLayer::m_logNormalization
protected

the logarithm of the normalization constant for every distribution

Definition at line 172 of file RBFLayer.h.

◆ m_trainCenters

bool shark::RBFLayer::m_trainCenters
protected

enables learning of the center points of the neurons

Definition at line 176 of file RBFLayer.h.

◆ m_trainWidth

bool shark::RBFLayer::m_trainWidth
protected

enables learning of the width parameters.

Definition at line 178 of file RBFLayer.h.


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