GClasses
GClasses::GBlockGRU Class Reference

Detailed Description

A block of Gated Recurrent Units.

#include <GBlock.h>

Inheritance diagram for GClasses::GBlockGRU:
GClasses::GBlockRecurrent GClasses::GBlock

Public Member Functions

 GBlockGRU (size_t outputs, size_t inputs=0)
 
 GBlockGRU (GDomNode *pNode)
 
virtual ~GBlockGRU ()
 
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 size_t depth () override
 Returns the number of instances of this block unfolded through time that will be used during training. More...
 
virtual void diminishWeights (double amount, bool regularizeBiases) override
 Moves all weights in the direction of zero by the specified amount. 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 >= min and <= max. More...
 
virtual std::string name () const override
 Returns the name of this block. More...
 
virtual GContextRecurrentInstancenewContext (GRand &rand) override
 Makes a new context object for 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. The default values apply the perturbation to all units. 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 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 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...
 
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::GBlockRecurrent
 GBlockRecurrent ()
 
 GBlockRecurrent (GDomNode *pNode)
 
virtual ~GBlockRecurrent ()
 
virtual bool isRecurrent () const override
 Returns true. 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...
 
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...
 

Static Public Member Functions

static void test ()
 
- Static Public Member Functions inherited from GClasses::GBlock
static GBlockdeserialize (GDomNode *pNode)
 Unmarshalls the specified DOM node into a block object. More...
 

Protected Attributes

GBlockLogistic m_logistic
 
GBlockScalarProduct m_product
 
GBlockLinear m_remember
 
GBlockSwitch m_switch
 
GBlockTanh m_tanh
 
GBlockLinear m_update
 
GBlockLinear m_val
 
- Protected Attributes inherited from GClasses::GBlock
size_t m_inPos
 

Friends

class GContextGRU
 

Additional Inherited Members

- Public Types inherited from GClasses::GBlock
- Protected Member Functions inherited from GClasses::GBlockRecurrent
virtual void backProp (GContext &ctx, const GVec &input, const GVec &output, const GVec &outBlame, GVec &inBlame) const override
 Deliberately protected. Throws an exception telling you to call GContextRecurrent::backProp instead. More...
 
virtual void forwardProp (GContext &ctx, const GVec &input, GVec &output) const override
 Deliberately protected. Throws an exception telling you to call GContextRecurrent::forwardProp instead. More...
 
virtual void updateGradient (GContext &ctx, const GVec &input, const GVec &outBlame, GVec &gradient) const override
 Deliberately protected. Throws an exception telling you to call GContextRecurrent::updateGradient instead. 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...
 
- Static Protected Member Functions inherited from GClasses::GBlockRecurrent
static double testEngine (GNeuralNet &nn)
 

Constructor & Destructor Documentation

GClasses::GBlockGRU::GBlockGRU ( size_t  outputs,
size_t  inputs = 0 
)
GClasses::GBlockGRU::GBlockGRU ( GDomNode pNode)
virtual GClasses::GBlockGRU::~GBlockGRU ( )
virtual

Member Function Documentation

virtual void GClasses::GBlockGRU::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 size_t GClasses::GBlockGRU::depth ( )
inlineoverridevirtual

Returns the number of instances of this block unfolded through time that will be used during training.

Implements GClasses::GBlockRecurrent.

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

Moves all weights in the direction of zero by the specified amount.

Implements GClasses::GBlock.

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

Returns the number of inputs this block consumes.

Implements GClasses::GBlock.

virtual void GClasses::GBlockGRU::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 >= min and <= max.

Implements GClasses::GBlock.

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

Returns the name of this block.

Implements GClasses::GBlock.

virtual GContextRecurrentInstance* GClasses::GBlockGRU::newContext ( GRand rand)
overridevirtual

Makes a new context object for this block.

Implements GClasses::GBlockRecurrent.

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

Returns the number of outputs this block produces.

Implements GClasses::GBlock.

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

Perturbs the weights that feed into the specifed units with Gaussian noise. The default values apply the perturbation to all units.

Implements GClasses::GBlock.

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

Initialize the weights with small random values.

Implements GClasses::GBlock.

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

Resizes this block.

Implements GClasses::GBlock.

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

Multiplies all the weights by the specified factor.

Implements GClasses::GBlock.

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

Marshall this block into a DOM.

Implements GClasses::GBlock.

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

Add the weight and bias gradient to the weights.

Implements GClasses::GBlock.

static void GClasses::GBlockGRU::test ( )
static
virtual BlockType GClasses::GBlockGRU::type ( ) const
inlineoverridevirtual

Returns the type of this block.

Implements GClasses::GBlock.

virtual size_t GClasses::GBlockGRU::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::GBlockGRU::weightCount ( ) const
overridevirtual

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

Implements GClasses::GBlock.

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

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

Implements GClasses::GBlock.

Friends And Related Function Documentation

friend class GContextGRU
friend

Member Data Documentation

GBlockLogistic GClasses::GBlockGRU::m_logistic
protected
GBlockScalarProduct GClasses::GBlockGRU::m_product
protected
GBlockLinear GClasses::GBlockGRU::m_remember
protected
GBlockSwitch GClasses::GBlockGRU::m_switch
protected
GBlockTanh GClasses::GBlockGRU::m_tanh
protected
GBlockLinear GClasses::GBlockGRU::m_update
protected
GBlockLinear GClasses::GBlockGRU::m_val
protected