shark::GaussianLayer Class Reference

A layer of Gaussian neurons. More...

#include <shark/Unsupervised/RBM/Neuronlayers/GaussianLayer.h>

+ Inheritance diagram for shark::GaussianLayer:

Public Types

typedef RealSpace StateSpace
 the bias terms associated with the neurons More...
 
typedef RealVector SufficientStatistics
 The sufficient statistics for the Guassian Layer stores the mean of the neuron and the inverse temperature. More...
 
typedef Batch< SufficientStatistics >::type StatisticsBatch
 Sufficient statistics of a batch of data. More...
 
- Public Types inherited from shark::IParameterizable<>
typedef RealVector ParameterVectorType
 

Public Member Functions

const RealVector & bias () const
 Returns the bias values of the units. More...
 
RealVector & bias ()
 Returns the bias values of the units. More...
 
void resize (std::size_t newSize)
 Resizes this neuron layer. More...
 
std::size_t size () const
 Returns the number of neurons of this layer. More...
 
template<class Input , class BetaVector >
void sufficientStatistics (Input const &input, StatisticsBatch &statistics, BetaVector const &beta) const
 Takes the input of the neuron and estimates the expectation of the response of the neuron. More...
 
template<class Matrix , class Rng >
void sample (StatisticsBatch const &statistics, Matrix &state, double alpha, Rng &rng) const
 Given a the precomputed statistics (the mean of the Gaussian), the elements of the vector are sampled. This happens either with Gibbs-Sampling or Flip-the-State sampling. For alpha= 0 gibbs sampling is performed. That is the next state for neuron i is directly taken from the conditional distribution of the i-th neuron. In the case of alpha=1, flip-the-state sampling is performed, which takes the last state into account and tries to do deterministically jump into states with higher probability. THIS IS NOT IMPLEMENTED YET and alpha is ignored! More...
 
template<class Matrix >
RealVector logProbability (StatisticsBatch const &statistics, Matrix const &state) const
 Computes the log of the probability of the given states in the conditional distribution. More...
 
template<class Matrix >
Matrix const & phi (Matrix const &state) const
 Transforms the current state of the neurons for the multiplication with the weight matrix of the RBM, i.e. calculates the value of the phi-function used in the interaction term. In the case of Gaussian neurons the phi-function is just the identity. More...
 
RealMatrix const & expectedPhiValue (StatisticsBatch const &statistics) const
 Returns the expectation of the phi-function. More...
 
RealMatrix const & mean (StatisticsBatch const &statistics) const
 Returns the mean given the state of the connected layer, i.e. in this case the mean of the Gaussian. More...
 
template<class Matrix , class BetaVector >
RealVector energyTerm (Matrix const &state, BetaVector const &beta) const
 The energy term this neuron adds to the energy function for a batch of inputs. More...
 
template<class Input >
double logMarginalize (const Input &inputs, double beta) const
 Sums over all possible values of the terms of the energy function which depend on the this layer and returns the logarithmic result. More...
 
template<class Vector , class SampleBatch >
void expectedParameterDerivative (Vector &derivative, SampleBatch const &samples) const
 Calculates the expectation of the derivatives of the energy term of this neuron layer with respect to it's parameters - the bias weights. The expectation is taken with respect to the conditional probability distribution of the layer given the state of the connected layer. More...
 
template<class Vector , class SampleBatch , class Vector2 >
void expectedParameterDerivative (Vector &derivative, SampleBatch const &samples, Vector2 const &weights) const
 
template<class Vector , class SampleBatch >
void parameterDerivative (Vector &derivative, SampleBatch const &samples) const
 Calculates the derivatives of the energy term of this neuron layer with respect to it's parameters - the bias weights. More...
 
template<class Vector , class SampleBatch , class WeightVector >
void parameterDerivative (Vector &derivative, SampleBatch const &samples, WeightVector const &weights) const
 Calculates the derivatives of the energy term of this neuron layer with respect to it's parameters - the bias weights. More...
 
RealVector parameterVector () const
 Returns the vector with the parameters associated with the neurons in the layer. More...
 
void setParameterVector (RealVector const &newParameters)
 Returns the vector with the parameters associated with the neurons in the layer. More...
 
std::size_t numberOfParameters () const
 Returns the number of the parameters associated with the neurons in the layer. More...
 
void read (InArchive &archive)
 Reads the bias parameters from an archive. More...
 
void write (OutArchive &archive) const
 Writes the bias parameters to an archive. More...
 
- 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 ()
 
- Public Member Functions inherited from shark::IParameterizable<>
virtual ~IParameterizable ()
 

Detailed Description

A layer of Gaussian neurons.

For a Gaussian neuron/variable the conditional probability distribution of the state of the variable given the state of the other layer is given by a Gaussian distribution with the input of the neuron as mean and unit variance.

Definition at line 48 of file GaussianLayer.h.

Member Typedef Documentation

◆ StateSpace

the bias terms associated with the neurons

the state space of this neuron is binary

Definition at line 53 of file GaussianLayer.h.

◆ StatisticsBatch

Sufficient statistics of a batch of data.

Definition at line 58 of file GaussianLayer.h.

◆ SufficientStatistics

The sufficient statistics for the Guassian Layer stores the mean of the neuron and the inverse temperature.

Definition at line 56 of file GaussianLayer.h.

Member Function Documentation

◆ bias() [1/2]

const RealVector& shark::GaussianLayer::bias ( ) const
inline

Returns the bias values of the units.

Definition at line 61 of file GaussianLayer.h.

◆ bias() [2/2]

RealVector& shark::GaussianLayer::bias ( )
inline

Returns the bias values of the units.

Definition at line 65 of file GaussianLayer.h.

◆ energyTerm()

template<class Matrix , class BetaVector >
RealVector shark::GaussianLayer::energyTerm ( Matrix const &  state,
BetaVector const &  beta 
) const
inline

The energy term this neuron adds to the energy function for a batch of inputs.

Parameters
statethe state of the neuron layer
betathe inverse temperature of the i-th state
Returns
the energy term of the neuron layer

Definition at line 179 of file GaussianLayer.h.

References shark::batchSize(), size(), and SIZE_CHECK.

◆ expectedParameterDerivative() [1/2]

template<class Vector , class SampleBatch >
void shark::GaussianLayer::expectedParameterDerivative ( Vector &  derivative,
SampleBatch const &  samples 
) const
inline

Calculates the expectation of the derivatives of the energy term of this neuron layer with respect to it's parameters - the bias weights. The expectation is taken with respect to the conditional probability distribution of the layer given the state of the connected layer.

This function takes a batch of samples and extracts the required informations out of it.

Parameters
derivativethe derivative with respect to the parameters, the result is added on top of it to accumulate derivatives
samplesthe samples from which the informations can be extracted

Definition at line 229 of file GaussianLayer.h.

References size(), and SIZE_CHECK.

◆ expectedParameterDerivative() [2/2]

template<class Vector , class SampleBatch , class Vector2 >
void shark::GaussianLayer::expectedParameterDerivative ( Vector &  derivative,
SampleBatch const &  samples,
Vector2 const &  weights 
) const
inline

Definition at line 235 of file GaussianLayer.h.

References size(), and SIZE_CHECK.

◆ expectedPhiValue()

RealMatrix const& shark::GaussianLayer::expectedPhiValue ( StatisticsBatch const &  statistics) const
inline

Returns the expectation of the phi-function.

Parameters
statisticsthe sufficient statistics (the mean of the distribution).

Definition at line 161 of file GaussianLayer.h.

References size(), and SIZE_CHECK.

◆ logMarginalize()

template<class Input >
double shark::GaussianLayer::logMarginalize ( const Input &  inputs,
double  beta 
) const
inline

Sums over all possible values of the terms of the energy function which depend on the this layer and returns the logarithmic result.

This function is called by Energy when the unnormalized marginal probability of the connected layer is to be computed. This function calculates the part which depends on the neurons which are to be marginalized out. (In the case of the binary hidden neuron, this is the term \( \log \sum_h e^{\vec h^T W \vec v+ \vec h^T \vec c} \)). The rest is calculated by the energy function. In the general case of a hidden layer, this function calculates \( \log \int_h e^(\phi_h(\vec h)^T W \phi_v(\vec v)+f_h(\vec h) ) \) where f_h is the energy term of this.

Parameters
inputsthe inputs of the neurons they get from the other layer
betathe inverse temperature of the RBM
Returns
the marginal distribution of the connected layer

Definition at line 209 of file GaussianLayer.h.

References beta, size(), SIZE_CHECK, shark::sqr(), and shark::SQRT_2_PI.

◆ logProbability()

template<class Matrix >
RealVector shark::GaussianLayer::logProbability ( StatisticsBatch const &  statistics,
Matrix const &  state 
) const
inline

Computes the log of the probability of the given states in the conditional distribution.

Currently it is only possible to compute the case with alpha=0

Parameters
statisticsthe statistics of the conditional distribution
statethe state to check

Definition at line 132 of file GaussianLayer.h.

References size(), SIZE_CHECK, and shark::sqr().

◆ mean()

RealMatrix const& shark::GaussianLayer::mean ( StatisticsBatch const &  statistics) const
inline

Returns the mean given the state of the connected layer, i.e. in this case the mean of the Gaussian.

Parameters
statisticsthe sufficient statistics of the layer for a whole batch

Definition at line 168 of file GaussianLayer.h.

References size(), and SIZE_CHECK.

◆ numberOfParameters()

std::size_t shark::GaussianLayer::numberOfParameters ( ) const
inlinevirtual

Returns the number of the parameters associated with the neurons in the layer.

Reimplemented from shark::IParameterizable<>.

Definition at line 274 of file GaussianLayer.h.

References size().

◆ parameterDerivative() [1/2]

template<class Vector , class SampleBatch >
void shark::GaussianLayer::parameterDerivative ( Vector &  derivative,
SampleBatch const &  samples 
) const
inline

Calculates the derivatives of the energy term of this neuron layer with respect to it's parameters - the bias weights.

This function takes a batch of samples and extracts the required informations out of it.

Parameters
derivativethe derivative with respect to the parameters, the result is added on top of it to accumulate derivatives
samplesthe sample from which the informations can be extracted

Definition at line 246 of file GaussianLayer.h.

References size(), and SIZE_CHECK.

◆ parameterDerivative() [2/2]

template<class Vector , class SampleBatch , class WeightVector >
void shark::GaussianLayer::parameterDerivative ( Vector &  derivative,
SampleBatch const &  samples,
WeightVector const &  weights 
) const
inline

Calculates the derivatives of the energy term of this neuron layer with respect to it's parameters - the bias weights.

This function takes a batch of samples and calculates a weighted derivative

Parameters
derivativethe derivative with respect to the parameters, the result is added on top of it to accumulate derivatives
samplesthe sample from which the informations can be extracted
weightsthe weights for the single sample derivatives

Definition at line 258 of file GaussianLayer.h.

References size(), and SIZE_CHECK.

◆ parameterVector()

RealVector shark::GaussianLayer::parameterVector ( ) const
inlinevirtual

Returns the vector with the parameters associated with the neurons in the layer.

Reimplemented from shark::IParameterizable<>.

Definition at line 264 of file GaussianLayer.h.

◆ phi()

template<class Matrix >
Matrix const& shark::GaussianLayer::phi ( Matrix const &  state) const
inline

Transforms the current state of the neurons for the multiplication with the weight matrix of the RBM, i.e. calculates the value of the phi-function used in the interaction term. In the case of Gaussian neurons the phi-function is just the identity.

Parameters
statethe state matrix of the neuron layer
Returns
the value of the phi-function

Definition at line 153 of file GaussianLayer.h.

References size(), and SIZE_CHECK.

◆ read()

void shark::GaussianLayer::read ( InArchive archive)
inlinevirtual

Reads the bias parameters from an archive.

Reimplemented from shark::ISerializable.

Definition at line 279 of file GaussianLayer.h.

◆ resize()

void shark::GaussianLayer::resize ( std::size_t  newSize)
inline

Resizes this neuron layer.

Parameters
newSizenumber of neurons in the layer

Definition at line 72 of file GaussianLayer.h.

◆ sample()

template<class Matrix , class Rng >
void shark::GaussianLayer::sample ( StatisticsBatch const &  statistics,
Matrix &  state,
double  alpha,
Rng &  rng 
) const
inline

Given a the precomputed statistics (the mean of the Gaussian), the elements of the vector are sampled. This happens either with Gibbs-Sampling or Flip-the-State sampling. For alpha= 0 gibbs sampling is performed. That is the next state for neuron i is directly taken from the conditional distribution of the i-th neuron. In the case of alpha=1, flip-the-state sampling is performed, which takes the last state into account and tries to do deterministically jump into states with higher probability. THIS IS NOT IMPLEMENTED YET and alpha is ignored!

Parameters
statisticssufficient statistics containing the mean of the conditional Gaussian distribution of the neurons
statethe state matrix that will hold the sampled states
alphafactor changing from gibbs to flip-the state sampling. 0<=alpha<=1
rngthe random number generator used for sampling

Definition at line 110 of file GaussianLayer.h.

References shark::random::gauss(), SHARK_CRITICAL_REGION, size(), and SIZE_CHECK.

◆ setParameterVector()

void shark::GaussianLayer::setParameterVector ( RealVector const &  newParameters)
inlinevirtual

Returns the vector with the parameters associated with the neurons in the layer.

Reimplemented from shark::IParameterizable<>.

Definition at line 269 of file GaussianLayer.h.

◆ size()

std::size_t shark::GaussianLayer::size ( ) const
inline

◆ sufficientStatistics()

template<class Input , class BetaVector >
void shark::GaussianLayer::sufficientStatistics ( Input const &  input,
StatisticsBatch statistics,
BetaVector const &  beta 
) const
inline

Takes the input of the neuron and estimates the expectation of the response of the neuron.

Parameters
inputthe batch of inputs of the neuron
statisticssufficient statistics containing the mean of the resulting Gaussian distribution
betathe inverse Temperature of the RBM (typically 1) for the whole batch

Definition at line 87 of file GaussianLayer.h.

References size(), and SIZE_CHECK.

◆ write()

void shark::GaussianLayer::write ( OutArchive archive) const
inlinevirtual

Writes the bias parameters to an archive.

Reimplemented from shark::ISerializable.

Definition at line 283 of file GaussianLayer.h.


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