Implements a layer of radial basis functions in a neural network. More...
#include <shark/Models/RBFLayer.h>
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< State > | createState () 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... | |
BatchInputType & | centers () |
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 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 (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 | 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 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< Feature > | Features |
typedef TypedFeatureNotAvailableException< Feature > | FeatureNotAvailableException |
Public Types inherited from shark::IParameterizable< RealVector > | |
typedef RealVector | ParameterVectorType |
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.
SHARK_EXPORT_SYMBOL shark::RBFLayer::RBFLayer | ( | ) |
Creates an empty Radial Basis Function layer.
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.
numInput | Number of input neurons, equal to dimensionality of input space. |
numOutput | Number of output neurons, equal to dimensionality of output space and number of gaussian distributions |
|
inline |
Returns the center values of the neurons.
Definition at line 141 of file RBFLayer.h.
References m_centers.
Referenced by createState(), and main().
|
inline |
Sets the center values of the neurons.
Definition at line 145 of file RBFLayer.h.
References m_centers.
|
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().
|
virtual |
Standard interface for evaluating the response of the model to a batch of patterns.
patterns | the inputs of the model |
outputs | the predictions or response of the model to every pattern |
state | intermediate results stored by eval which can be reused for derivative computation. |
Implements shark::AbstractModel< RealVector, RealVector >.
Referenced by createState().
|
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().
|
inlinevirtual |
Returns the number of input neurons.
Implements shark::AbstractModel< RealVector, RealVector >.
Definition at line 98 of file RBFLayer.h.
References m_centers.
|
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.
|
virtual |
Returns the number of parameters which are currently enabled for training.
Reimplemented from shark::IParameterizable< RealVector >.
Referenced by name().
|
inlinevirtual |
Returns the number of output neurons.
Implements shark::AbstractModel< RealVector, RealVector >.
Definition at line 103 of file RBFLayer.h.
References m_centers.
|
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().
|
virtual |
From ISerializable, reads a model from an archive.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Referenced by gamma().
SHARK_EXPORT_SYMBOL void shark::RBFLayer::setGamma | ( | RealVector const & | gamma | ) |
sets the width parameters - the gamma values - of the distributions.
Referenced by gamma().
|
virtual |
Sets the new internal parameters.
Reimplemented from shark::IParameterizable< RealVector >.
Referenced by name().
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.
numInput | Number of input neurons, equal to dimensionality of input space. |
numOutput | Number of output neurons (basis functions), equal to dimensionality of output space. |
Referenced by createState(), and main().
SHARK_EXPORT_SYMBOL void shark::RBFLayer::setTrainingParameters | ( | bool | centers, |
bool | width | ||
) |
Enables or disables parameters for learning.
centers | whether the centers should be trained |
width | whether the distribution width should be trained |
Referenced by createState().
|
virtual |
calculates the weighted sum of derivatives w.r.t the parameters.
pattern | the patterns to evaluate |
coefficients | the coefficients which are used to calculate the weighted sum for every pattern |
state | intermediate results stored by eval to speed up calculations of the derivatives |
derivative | the calculated derivative as sum over all derivates of all patterns |
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Referenced by createState().
|
virtual |
From ISerializable, writes a model to an archive.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
Referenced by gamma().
|
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().
|
protected |
stores the width parameters of the Gaussian functions
Definition at line 169 of file RBFLayer.h.
Referenced by gamma().
|
protected |
the logarithm of the normalization constant for every distribution
Definition at line 172 of file RBFLayer.h.
|
protected |
enables learning of the center points of the neurons
Definition at line 176 of file RBFLayer.h.
|
protected |
enables learning of the width parameters.
Definition at line 178 of file RBFLayer.h.