GClasses
GClasses::GBlockRestrictedBoltzmannMachine Class Reference

#include <GBlock.h>

Inheritance diagram for GClasses::GBlockRestrictedBoltzmannMachine:
GClasses::GBlock

Public Member Functions

 GBlockRestrictedBoltzmannMachine (size_t outputs, size_t inputs=0)
 General-purpose constructor. More...
 
 GBlockRestrictedBoltzmannMachine (GDomNode *pNode)
 Deserializing constructor. More...
 
virtual void backProp (GContext &ctx, const GVec &input, const GVec &output, const GVec &outBlame, GVec &inBlame) const override
 Evaluates outBlame, and adds to inBlame. (Note that it "adds to" the inBlame because multiple blocks may fork from a common source.) More...
 
GVecbias ()
 Returns the bias for the hidden end of this block. More...
 
const GVecbias () const
 Returns the bias for the hidden end of this block. More...
 
GVecbiasReverse ()
 Returns the bias for the visible end of this block. More...
 
const GVecbiasReverse () const
 
virtual void copyWeights (const GBlock *pSource) override
 Copy the weights from pSource to this block. (Assumes pSource is the same type of block.) More...
 
virtual void diminishWeights (double amount, bool regularizeBiases) override
 Diminishes all the weights (that is, moves them in the direction toward 0) by the specified amount. More...
 
void drawSample (GContext &ctx, size_t iters, GVec &output, GVec &input)
 Draws a sample observation from "iters" iterations of Gibbs sampling. The resulting sample is placed in activationReverse(), and the corresponding encoding will be in activation(). More...
 
void feedBackward (const GVec &output, GVec &input) const
 Feed a vector backwards through this block. More...
 
virtual void forwardProp (GContext &ctx, const GVec &input, GVec &output) const override
 Evaluate the input, set the output. More...
 
virtual size_t inputs () const override
 Returns the number of inputs this block consumes. More...
 
virtual void maxNorm (double min, double max) override
 Scales weights if necessary such that the manitude of the weights (not including the bias) feeding into each unit are <= max. More...
 
virtual std::string name () const override
 Returns the name of this block. More...
 
virtual size_t outputs () const override
 Returns the number of outputs this block produces. More...
 
virtual void perturbWeights (GRand &rand, double deviation) override
 Perturbs the weights that feed into the specifed units with Gaussian noise. Also perturbs the bias. start specifies the first unit whose incoming weights are perturbed. count specifies the maximum number of units whose incoming weights are perturbed. The default values for these parameters apply the perturbation to all units. More...
 
void resampleHidden (GRand &rand, GVec &output)
 Performs binomial resampling of the activation values on the output end of this block. More...
 
void resampleVisible (GRand &rand, GVec &input)
 Performs binomial resampling of the activation values on the input end of this block. More...
 
virtual void resetWeights (GRand &rand) override
 Initialize the weights with small random values. More...
 
virtual void resize (size_t inputs, size_t outputs) override
 Resizes this block. More...
 
virtual void scaleWeights (double factor, bool scaleBiases) override
 Multiplies all the weights in this block by the specified factor. More...
 
virtual GDomNodeserialize (GDom *pDoc) const override
 Marshall this block into a DOM. More...
 
virtual void step (double learningRate, const GVec &gradient) override
 Add the weight and bias gradient to the weights. More...
 
virtual BlockType type () const override
 Returns the type of this block. More...
 
virtual void updateGradient (GContext &ctx, const GVec &input, const GVec &outBlame, GVec &gradient) const override
 Updates the gradient for updating the weights by gradient descent. (Assumes the error has already been computed and deactivated.) More...
 
virtual size_t vectorToWeights (const double *pVector) override
 Deserialize from a vector to the weights in this block. Return the number of elements consumed. More...
 
virtual size_t weightCount () const override
 Returns the number of double-precision elements necessary to serialize the weights of this block into a vector. More...
 
GMatrixweights ()
 Returns a reference to the weights matrix of this block. More...
 
virtual size_t weightsToVector (double *pOutVector) const override
 Serialize the weights in this block into a vector. Return the number of elements written. More...
 
- Public Member Functions inherited from GClasses::GBlock
 GBlock ()
 
 GBlock (GDomNode *pNode)
 
virtual ~GBlock ()
 
virtual bool elementWise () const
 Returns true iff this block operates only on individual elements. More...
 
size_t inPos () const
 Returns the offset in the previous layer's output where values are fed as input to this block. More...
 
virtual bool isRecurrent () const
 Returns true iff this block is recurrent. More...
 
void setInPos (size_t n)
 Sets the starting offset in the previous layer's output where values will be fed as input to this block. More...
 
virtual std::string to_str () const
 Returns a string representation of this block. More...
 
virtual bool usesGPU ()
 Returns true iff this block does its computations in parallel on a GPU. More...
 

Protected Attributes

GVec m_bias
 
GMatrix m_biasReverse
 
GMatrix m_weights
 
- Protected Attributes inherited from GClasses::GBlock
size_t m_inPos
 

Additional Inherited Members

- Public Types inherited from GClasses::GBlock
- Static Public Member Functions inherited from GClasses::GBlock
static GBlockdeserialize (GDomNode *pNode)
 Unmarshalls the specified DOM node into a block object. More...
 
- Protected Member Functions inherited from GClasses::GBlock
GDomNodebaseDomNode (GDom *pDoc) const
 
void basicTest ()
 Exercises some basic functionality that all blocks have in common. More...
 

Constructor & Destructor Documentation

GClasses::GBlockRestrictedBoltzmannMachine::GBlockRestrictedBoltzmannMachine ( size_t  outputs,
size_t  inputs = 0 
)

General-purpose constructor.

GClasses::GBlockRestrictedBoltzmannMachine::GBlockRestrictedBoltzmannMachine ( GDomNode pNode)

Deserializing constructor.

Member Function Documentation

virtual void GClasses::GBlockRestrictedBoltzmannMachine::backProp ( GContext ctx,
const GVec input,
const GVec output,
const GVec outBlame,
GVec inBlame 
) const
overridevirtual

Evaluates outBlame, and adds to inBlame. (Note that it "adds to" the inBlame because multiple blocks may fork from a common source.)

Implements GClasses::GBlock.

GVec& GClasses::GBlockRestrictedBoltzmannMachine::bias ( )
inline

Returns the bias for the hidden end of this block.

const GVec& GClasses::GBlockRestrictedBoltzmannMachine::bias ( ) const
inline

Returns the bias for the hidden end of this block.

GVec& GClasses::GBlockRestrictedBoltzmannMachine::biasReverse ( )
inline

Returns the bias for the visible end of this block.

const GVec& GClasses::GBlockRestrictedBoltzmannMachine::biasReverse ( ) const
inline
virtual void GClasses::GBlockRestrictedBoltzmannMachine::copyWeights ( const GBlock pSource)
overridevirtual

Copy the weights from pSource to this block. (Assumes pSource is the same type of block.)

Implements GClasses::GBlock.

virtual void GClasses::GBlockRestrictedBoltzmannMachine::diminishWeights ( double  amount,
bool  regularizeBiases 
)
overridevirtual

Diminishes all the weights (that is, moves them in the direction toward 0) by the specified amount.

Implements GClasses::GBlock.

void GClasses::GBlockRestrictedBoltzmannMachine::drawSample ( GContext ctx,
size_t  iters,
GVec output,
GVec input 
)

Draws a sample observation from "iters" iterations of Gibbs sampling. The resulting sample is placed in activationReverse(), and the corresponding encoding will be in activation().

void GClasses::GBlockRestrictedBoltzmannMachine::feedBackward ( const GVec output,
GVec input 
) const

Feed a vector backwards through this block.

virtual void GClasses::GBlockRestrictedBoltzmannMachine::forwardProp ( GContext ctx,
const GVec input,
GVec output 
) const
overridevirtual

Evaluate the input, set the output.

Implements GClasses::GBlock.

virtual size_t GClasses::GBlockRestrictedBoltzmannMachine::inputs ( ) const
inlineoverridevirtual

Returns the number of inputs this block consumes.

Implements GClasses::GBlock.

virtual void GClasses::GBlockRestrictedBoltzmannMachine::maxNorm ( double  min,
double  max 
)
overridevirtual

Scales weights if necessary such that the manitude of the weights (not including the bias) feeding into each unit are <= max.

Implements GClasses::GBlock.

virtual std::string GClasses::GBlockRestrictedBoltzmannMachine::name ( ) const
inlineoverridevirtual

Returns the name of this block.

Implements GClasses::GBlock.

virtual size_t GClasses::GBlockRestrictedBoltzmannMachine::outputs ( ) const
inlineoverridevirtual

Returns the number of outputs this block produces.

Implements GClasses::GBlock.

virtual void GClasses::GBlockRestrictedBoltzmannMachine::perturbWeights ( GRand rand,
double  deviation 
)
overridevirtual

Perturbs the weights that feed into the specifed units with Gaussian noise. Also perturbs the bias. start specifies the first unit whose incoming weights are perturbed. count specifies the maximum number of units whose incoming weights are perturbed. The default values for these parameters apply the perturbation to all units.

Implements GClasses::GBlock.

void GClasses::GBlockRestrictedBoltzmannMachine::resampleHidden ( GRand rand,
GVec output 
)

Performs binomial resampling of the activation values on the output end of this block.

void GClasses::GBlockRestrictedBoltzmannMachine::resampleVisible ( GRand rand,
GVec input 
)

Performs binomial resampling of the activation values on the input end of this block.

virtual void GClasses::GBlockRestrictedBoltzmannMachine::resetWeights ( GRand rand)
overridevirtual

Initialize the weights with small random values.

Implements GClasses::GBlock.

virtual void GClasses::GBlockRestrictedBoltzmannMachine::resize ( size_t  inputs,
size_t  outputs 
)
overridevirtual

Resizes this block.

Implements GClasses::GBlock.

virtual void GClasses::GBlockRestrictedBoltzmannMachine::scaleWeights ( double  factor,
bool  scaleBiases 
)
overridevirtual

Multiplies all the weights in this block by the specified factor.

Implements GClasses::GBlock.

virtual GDomNode* GClasses::GBlockRestrictedBoltzmannMachine::serialize ( GDom pDoc) const
overridevirtual

Marshall this block into a DOM.

Implements GClasses::GBlock.

virtual void GClasses::GBlockRestrictedBoltzmannMachine::step ( double  learningRate,
const GVec gradient 
)
overridevirtual

Add the weight and bias gradient to the weights.

Implements GClasses::GBlock.

virtual BlockType GClasses::GBlockRestrictedBoltzmannMachine::type ( ) const
inlineoverridevirtual

Returns the type of this block.

Implements GClasses::GBlock.

virtual void GClasses::GBlockRestrictedBoltzmannMachine::updateGradient ( GContext ctx,
const GVec input,
const GVec outBlame,
GVec gradient 
) const
overridevirtual

Updates the gradient for updating the weights by gradient descent. (Assumes the error has already been computed and deactivated.)

Implements GClasses::GBlock.

virtual size_t GClasses::GBlockRestrictedBoltzmannMachine::vectorToWeights ( const double *  pVector)
overridevirtual

Deserialize from a vector to the weights in this block. Return the number of elements consumed.

Implements GClasses::GBlock.

virtual size_t GClasses::GBlockRestrictedBoltzmannMachine::weightCount ( ) const
overridevirtual

Returns the number of double-precision elements necessary to serialize the weights of this block into a vector.

Implements GClasses::GBlock.

GMatrix& GClasses::GBlockRestrictedBoltzmannMachine::weights ( )
inline

Returns a reference to the weights matrix of this block.

virtual size_t GClasses::GBlockRestrictedBoltzmannMachine::weightsToVector ( double *  pOutVector) const
overridevirtual

Serialize the weights in this block into a vector. Return the number of elements written.

Implements GClasses::GBlock.

Member Data Documentation

GVec GClasses::GBlockRestrictedBoltzmannMachine::m_bias
protected
GMatrix GClasses::GBlockRestrictedBoltzmannMachine::m_biasReverse
protected
GMatrix GClasses::GBlockRestrictedBoltzmannMachine::m_weights
protected