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. | |
| SHARK_EXPORT_SYMBOL | RBFLayer (std::size_t numInput, std::size_t numOutput) |
| Creates a layer of a Radial Basis Function Network. | |
| std::string | name () const |
| From INameable: return the class name. | |
| SHARK_EXPORT_SYMBOL RealVector | parameterVector () const |
| Returns the current parameter vector. The amount and order of weights depend on the training parameters. | |
| SHARK_EXPORT_SYMBOL void | setParameterVector (RealVector const &newParameters) |
| Sets the new internal parameters. | |
| SHARK_EXPORT_SYMBOL std::size_t | numberOfParameters () const |
| Returns the number of parameters which are currently enabled for training. | |
| Shape | inputShape () const |
| Returns the number of input neurons. | |
| Shape | outputShape () const |
| Returns the number of output neurons. | |
| boost::shared_ptr< State > | createState () const |
| Creates an internal state of the model. | |
| SHARK_EXPORT_SYMBOL void | setStructure (std::size_t numInput, std::size_t numOutput) |
| Configures a Radial Basis Function Network. | |
| 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. | |
| 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. | |
| SHARK_EXPORT_SYMBOL void | setTrainingParameters (bool centers, bool width) |
| Enables or disables parameters for learning. | |
| BatchInputType const & | centers () const |
| Returns the center values of the neurons. | |
| BatchInputType & | centers () |
| Sets the center values of the neurons. | |
| RealVector const & | gamma () const |
| Returns the width parameter of the Gaussian functions. | |
| SHARK_EXPORT_SYMBOL void | setGamma (RealVector const &gamma) |
| sets the width parameters - the gamma values - of the distributions. | |
| SHARK_EXPORT_SYMBOL void | read (InArchive &archive) |
| From ISerializable, reads a model from an archive. | |
| SHARK_EXPORT_SYMBOL void | write (OutArchive &archive) const |
| From ISerializable, writes a model to an archive. | |
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. | |
| bool | hasFirstInputDerivative () const |
| Returns true when the first input derivative is implemented. | |
| virtual void | eval (BatchInputType const &patterns, BatchOutputType &outputs) const |
| Standard interface for evaluating the response of the model to a batch of patterns. | |
| virtual void | eval (InputType const &pattern, OutputType &output) const |
| Standard interface for evaluating the response of the model to a single pattern. | |
| Data< OutputType > | operator() (Data< InputType > const &patterns) const |
| Model evaluation as an operator for a whole dataset. This is a convenience function. | |
| OutputType | operator() (InputType const &pattern) const |
| Model evaluation as an operator for a single pattern. This is a convenience function. | |
| BatchOutputType | operator() (BatchInputType const &patterns) const |
| Model evaluation as an operator for a single pattern. This is a convenience function. | |
| 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 | |
| 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 | |
Public Member Functions inherited from shark::IParameterizable< VectorType > | |
| virtual | ~IParameterizable () |
Public Member Functions inherited from shark::INameable | |
| virtual | ~INameable () |
Public Member Functions inherited from shark::ISerializable | |
| virtual | ~ISerializable () |
| Virtual d'tor. | |
| void | load (InArchive &archive, unsigned int version) |
| Versioned loading of components, calls read(...). | |
| void | save (OutArchive &archive, unsigned int version) const |
| Versioned storing of components, calls write(...). | |
| BOOST_SERIALIZATION_SPLIT_MEMBER () | |
Protected Attributes | |
| RealMatrix | m_centers |
| The center points. The i-th element corresponds to the center of neuron number i. | |
| RealVector | m_gamma |
| stores the width parameters of the Gaussian functions | |
| RealVector | m_logNormalization |
| the logarithm of the normalization constant for every distribution | |
| bool | m_trainCenters |
| enables learning of the center points of the neurons | |
| bool | m_trainWidth |
| enables learning of the width parameters. | |
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. | |
| typedef RealVector | OutputType |
| Defines the output type of the model. | |
| typedef AbstractModel< RealVector, RealVector, RealVector > | ModelBaseType |
| Defines the BaseType used by the model (this type). Useful for creating derived models. | |
| typedef Batch< InputType >::type | BatchInputType |
| defines the batch type of the input type. | |
| typedef Batch< OutputType >::type | BatchOutputType |
| defines the batch type of the output type | |
| typedef TypedFlags< Feature > | Features |
| typedef TypedFeatureNotAvailableException< Feature > | FeatureNotAvailableException |
Public Types inherited from shark::IParameterizable< VectorType > | |
| typedef VectorType | 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 57 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 |
Sets the center values of the neurons.
Definition at line 147 of file RBFLayer.h.
References m_centers.
|
inline |
Returns the center values of the neurons.
Definition at line 143 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 109 of file RBFLayer.h.
|
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 >.
|
inline |
Returns the width parameter of the Gaussian functions.
Definition at line 152 of file RBFLayer.h.
References m_gamma.
|
inlinevirtual |
Returns the number of input neurons.
Implements shark::AbstractModel< RealVector, RealVector >.
Definition at line 100 of file RBFLayer.h.
References m_centers.
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 84 of file RBFLayer.h.
|
virtual |
Returns the number of parameters which are currently enabled for training.
Reimplemented from shark::IParameterizable< VectorType >.
|
inlinevirtual |
Returns the number of output neurons.
Implements shark::AbstractModel< RealVector, RealVector >.
Definition at line 105 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< VectorType >.
|
virtual |
From ISerializable, reads a model from an archive.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
| SHARK_EXPORT_SYMBOL void shark::RBFLayer::setGamma | ( | RealVector const & | gamma | ) |
sets the width parameters - the gamma values - of the distributions.
|
virtual |
Sets the new internal parameters.
Reimplemented from shark::IParameterizable< VectorType >.
| 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. |
| 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 |
|
virtual |
calculates the weighted sum of derivatives w.r.t the parameters.
| pattern | the patterns to evaluate |
| outputs | the target outputs |
| 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 >.
|
virtual |
From ISerializable, writes a model to an archive.
Reimplemented from shark::AbstractModel< RealVector, RealVector >.
|
protected |
The center points. The i-th element corresponds to the center of neuron number i.
Definition at line 168 of file RBFLayer.h.
Referenced by centers(), centers(), inputShape(), and outputShape().
|
protected |
stores the width parameters of the Gaussian functions
Definition at line 171 of file RBFLayer.h.
Referenced by gamma().
|
protected |
the logarithm of the normalization constant for every distribution
Definition at line 174 of file RBFLayer.h.
|
protected |
enables learning of the center points of the neurons
Definition at line 178 of file RBFLayer.h.
|
protected |
enables learning of the width parameters.
Definition at line 180 of file RBFLayer.h.