GClasses
GClasses::GLayer Class Reference

Detailed Description

GNeuralNet contains GLayers stacked upon each other. GLayer contains GBlocks concatenated beside each other. (GNeuralNet is a type of GBlock.) Each GBlock is an array of differentiable network units (artificial neurons). The user must add at least one GBlock to each GLayer.

#include <GNeuralNet.h>

Public Member Functions

 GLayer ()
 
 GLayer (GDomNode *pNode)
 
virtual ~GLayer ()
 
void add (GBlock *pBlock, size_t inPos=0)
 Adds a block of network units (artificial neurons) to this layer. inPos specifies the index of the first output from the previous layer that will feed into this block of units. More...
 
void backProp (GContextLayer &ctx, const GVec &input, const GVec &output, const GVec &outBlame, GVec &inBlame) const
 Backpropagates the blame through the layer that was used to construct this object. More...
 
GBlockblock (size_t i)
 Returns a reference to the specified block. More...
 
const GBlockblock (size_t i) const
 
size_t blockCount () const
 Returns the number of blocks in this layer. More...
 
void copyWeights (const GLayer *pOther)
 Copies the weights from pOther. (Assumes pOther has the same structure.) More...
 
void diminishWeights (double amount, bool diminishBiases)
 Moves all weights by a constant amount toward 0. More...
 
void forwardProp (GContextLayer &ctx, const GVec &input, GVec &output) const
 Feeds input forward through the layer that was used to construct this object. More...
 
void forwardProp_training (GContextLayer &ctx, const GVec &input, GVec &output) const
 Identical to forwardProp, except recurrent blocks additionally propagate through time during training. More...
 
size_t inputs () const
 Returns the number of inputs that this layer consumes. More...
 
void maxNorm (double min, double max)
 Clips the magnitude of the weight vector in each network unit to fall within the specified range. More...
 
GContextLayernewContext (GRand &rand) const
 Allocates a new GContextLayer object, which can be used to train or predict with this layer. (Behavior is undefined if you add any blocks after you call newContext.) More...
 
size_t outputs () const
 Returns the number of outputs that this layer produces. More...
 
void perturbWeights (GRand &rand, double deviation)
 Perturbs all the weights in this layer by adding Gaussian noise with the specified deviation. More...
 
void recount ()
 Recounts the number of inputs, outputs, and weights in this layer. More...
 
void resetWeights (GRand &rand)
 Resets the weights in all of the blocks in this layer. More...
 
void scaleWeights (double factor, bool scaleBiases)
 Scales all the weights in this layer. More...
 
GDomNodeserialize (GDom *pDoc) const
 Marshal this object into a dom node. More...
 
void step (double learningRate, const GVec &gradient)
 Take a step to descend the gradient by updating the weights. More...
 
void updateGradient (GContextLayer &ctx, const GVec &input, const GVec &outBlame, GVec &gradient) const
 Updates the gradient for the layer that was used to construct this object. More...
 
size_t vectorToWeights (const double *pVector)
 Unmarshals all the weights in this layer from a vector. More...
 
size_t weightCount () const
 Returns the total number of weights in this layer. More...
 
size_t weightsToVector (double *pOutVector) const
 Marshals all the weights in this layer into a vector. More...
 

Protected Attributes

std::vector< GBlock * > m_blocks
 
size_t m_inputs
 
size_t m_outputs
 
size_t m_weightCount
 

Constructor & Destructor Documentation

GClasses::GLayer::GLayer ( )
GClasses::GLayer::GLayer ( GDomNode pNode)
virtual GClasses::GLayer::~GLayer ( )
virtual

Member Function Documentation

void GClasses::GLayer::add ( GBlock pBlock,
size_t  inPos = 0 
)

Adds a block of network units (artificial neurons) to this layer. inPos specifies the index of the first output from the previous layer that will feed into this block of units.

void GClasses::GLayer::backProp ( GContextLayer ctx,
const GVec input,
const GVec output,
const GVec outBlame,
GVec inBlame 
) const

Backpropagates the blame through the layer that was used to construct this object.

GBlock& GClasses::GLayer::block ( size_t  i)
inline

Returns a reference to the specified block.

const GBlock& GClasses::GLayer::block ( size_t  i) const
inline
size_t GClasses::GLayer::blockCount ( ) const
inline

Returns the number of blocks in this layer.

void GClasses::GLayer::copyWeights ( const GLayer pOther)

Copies the weights from pOther. (Assumes pOther has the same structure.)

void GClasses::GLayer::diminishWeights ( double  amount,
bool  diminishBiases 
)

Moves all weights by a constant amount toward 0.

void GClasses::GLayer::forwardProp ( GContextLayer ctx,
const GVec input,
GVec output 
) const

Feeds input forward through the layer that was used to construct this object.

void GClasses::GLayer::forwardProp_training ( GContextLayer ctx,
const GVec input,
GVec output 
) const

Identical to forwardProp, except recurrent blocks additionally propagate through time during training.

size_t GClasses::GLayer::inputs ( ) const

Returns the number of inputs that this layer consumes.

void GClasses::GLayer::maxNorm ( double  min,
double  max 
)

Clips the magnitude of the weight vector in each network unit to fall within the specified range.

GContextLayer* GClasses::GLayer::newContext ( GRand rand) const

Allocates a new GContextLayer object, which can be used to train or predict with this layer. (Behavior is undefined if you add any blocks after you call newContext.)

size_t GClasses::GLayer::outputs ( ) const

Returns the number of outputs that this layer produces.

void GClasses::GLayer::perturbWeights ( GRand rand,
double  deviation 
)

Perturbs all the weights in this layer by adding Gaussian noise with the specified deviation.

void GClasses::GLayer::recount ( )

Recounts the number of inputs, outputs, and weights in this layer.

void GClasses::GLayer::resetWeights ( GRand rand)

Resets the weights in all of the blocks in this layer.

void GClasses::GLayer::scaleWeights ( double  factor,
bool  scaleBiases 
)

Scales all the weights in this layer.

GDomNode* GClasses::GLayer::serialize ( GDom pDoc) const

Marshal this object into a dom node.

void GClasses::GLayer::step ( double  learningRate,
const GVec gradient 
)

Take a step to descend the gradient by updating the weights.

void GClasses::GLayer::updateGradient ( GContextLayer ctx,
const GVec input,
const GVec outBlame,
GVec gradient 
) const

Updates the gradient for the layer that was used to construct this object.

size_t GClasses::GLayer::vectorToWeights ( const double *  pVector)

Unmarshals all the weights in this layer from a vector.

size_t GClasses::GLayer::weightCount ( ) const

Returns the total number of weights in this layer.

size_t GClasses::GLayer::weightsToVector ( double *  pOutVector) const

Marshals all the weights in this layer into a vector.

Member Data Documentation

std::vector<GBlock*> GClasses::GLayer::m_blocks
protected
size_t GClasses::GLayer::m_inputs
protected
size_t GClasses::GLayer::m_outputs
protected
size_t GClasses::GLayer::m_weightCount
protected