GClasses
|
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... | |
GBlock & | block (size_t i) |
Returns a reference to the specified block. More... | |
const GBlock & | block (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... | |
GContextLayer * | 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.) 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... | |
GDomNode * | serialize (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 |
GClasses::GLayer::GLayer | ( | ) |
GClasses::GLayer::GLayer | ( | GDomNode * | pNode | ) |
|
virtual |
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.
|
inline |
Returns a reference to the specified block.
|
inline |
|
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.
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.
|
protected |
|
protected |
|
protected |
|
protected |