GClasses
|
Represents a block of network units (artificial neurons) in a neural network.
#include <GBlock.h>
Public Types |
Public Member Functions | |
GBlock () | |
GBlock (GDomNode *pNode) | |
virtual | ~GBlock () |
virtual void | backProp (GContext &ctx, const GVec &input, const GVec &output, const GVec &outBlame, GVec &inBlame) const =0 |
Evaluates outBlame, and adds to inBlame. (Note that it "adds to" the inBlame because multiple blocks may fork from a common source.) More... | |
virtual void | copyWeights (const GBlock *pSource)=0 |
Copy the weights from pSource to this block. (Assumes pSource is the same type of block.) More... | |
virtual void | diminishWeights (double amount, bool regularizeBiases)=0 |
Moves all weights in the direction of zero by the specified amount. More... | |
virtual bool | elementWise () const |
Returns true iff this block operates only on individual elements. More... | |
virtual void | forwardProp (GContext &ctx, const GVec &input, GVec &output) const =0 |
Evaluates the input, sets the output. 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 size_t | inputs () const =0 |
Returns the number of inputs this block consumes. More... | |
virtual bool | isRecurrent () const |
Returns true iff this block is recurrent. More... | |
virtual void | maxNorm (double min, double max)=0 |
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 =0 |
Returns the name of this block in the form of a string. More... | |
virtual size_t | outputs () const =0 |
Returns the number of outputs this block produces. More... | |
virtual void | perturbWeights (GRand &rand, double deviation)=0 |
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)=0 |
Initialize the weights, usually with small random values. More... | |
virtual void | resize (size_t inputs, size_t outputs)=0 |
Resizes this block. More... | |
virtual void | scaleWeights (double factor, bool scaleBiases)=0 |
Multiplies all the weights by the specified factor. More... | |
virtual GDomNode * | serialize (GDom *pDoc) const =0 |
Marshall this block into a DOM. 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 void | step (double learningRate, const GVec &gradient)=0 |
Add the weight and bias gradient to the weights. More... | |
virtual std::string | to_str () const |
Returns a string representation of this block. More... | |
virtual BlockType | type () const =0 |
Returns the type of this block. More... | |
virtual void | updateGradient (GContext &ctx, const GVec &input, const GVec &outBlame, GVec &gradient) const =0 |
Evaluate the input and outBlame, update the gradient for updating the weights by gradient descent. More... | |
virtual bool | usesGPU () |
Returns true iff this block does its computations in parallel on a GPU. More... | |
virtual size_t | vectorToWeights (const double *pVector)=0 |
Deserialize from a vector to the weights in this block. Return the number of elements consumed. More... | |
virtual size_t | weightCount () const =0 |
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 =0 |
Serialize the weights in this block into a vector. Return the number of elements written. More... | |
Static Public Member Functions | |
static GBlock * | deserialize (GDomNode *pNode) |
Unmarshalls the specified DOM node into a block object. More... | |
Protected Member Functions | |
GDomNode * | baseDomNode (GDom *pDoc) const |
void | basicTest () |
Exercises some basic functionality that all blocks have in common. More... | |
Protected Attributes | |
size_t | m_inPos |
GClasses::GBlock::GBlock | ( | ) |
GClasses::GBlock::GBlock | ( | GDomNode * | pNode | ) |
|
inlinevirtual |
|
pure virtual |
Evaluates outBlame, and adds to inBlame. (Note that it "adds to" the inBlame because multiple blocks may fork from a common source.)
Implemented in GClasses::GBlockRecurrent, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockAllPairings, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GBlockActivation, GClasses::GMaxPooling2D, GClasses::GBlockSwitch, GClasses::GNeuralNet, GClasses::GBlockScalarProduct, and GClasses::GBlockScalarSum.
|
protected |
Exercises some basic functionality that all blocks have in common.
|
pure virtual |
Copy the weights from pSource to this block. (Assumes pSource is the same type of block.)
Implemented in GClasses::GBlockGRU, GClasses::GBlockLSTM, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GNeuralNet, and GClasses::GBlockWeightless.
Unmarshalls the specified DOM node into a block object.
|
pure virtual |
Moves all weights in the direction of zero by the specified amount.
Implemented in GClasses::GBlockGRU, GClasses::GBlockLSTM, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GNeuralNet, and GClasses::GBlockWeightless.
|
inlinevirtual |
Returns true iff this block operates only on individual elements.
Reimplemented in GClasses::GBlockSoftExp, and GClasses::GBlockActivation.
|
pure virtual |
Evaluates the input, sets the output.
Implemented in GClasses::GBlockRecurrent, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockAllPairings, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GBlockActivation, GClasses::GMaxPooling2D, GClasses::GBlockSwitch, GClasses::GNeuralNet, GClasses::GBlockScalarProduct, and GClasses::GBlockScalarSum.
|
inline |
Returns the offset in the previous layer's output where values are fed as input to this block.
|
pure virtual |
Returns the number of inputs this block consumes.
Implemented in GClasses::GBlockGRU, GClasses::GBlockLSTM, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockAllPairings, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GBlockActivation, GClasses::GMaxPooling2D, GClasses::GBlockSwitch, GClasses::GBlockScalarProduct, GClasses::GBlockScalarSum, and GClasses::GNeuralNet.
|
inlinevirtual |
Returns true iff this block is recurrent.
Reimplemented in GClasses::GBlockRecurrent.
|
pure virtual |
Scales weights if necessary such that the manitude of the weights (not including the bias) feeding into each unit are >= min and <= max.
Implemented in GClasses::GBlockGRU, GClasses::GBlockLSTM, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GNeuralNet, and GClasses::GBlockWeightless.
|
pure virtual |
Returns the name of this block in the form of a string.
Implemented in GClasses::GBlockGRU, GClasses::GBlockLSTM, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockAllPairings, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GBlockSoftRoot, GClasses::GBlockSoftPlus, GClasses::GBlockLeakyRectifier, GClasses::GBlockRectifier, GClasses::GBlockSine, GClasses::GBlockGaussian, GClasses::GBlockSigExp, GClasses::GBlockBentIdentity, GClasses::GBlockLogistic, GClasses::GBlockScaledTanh, GClasses::GBlockTanh, GClasses::GBlockIdentity, GClasses::GMaxPooling2D, GClasses::GBlockSwitch, GClasses::GBlockScalarProduct, GClasses::GBlockScalarSum, and GClasses::GNeuralNet.
|
pure virtual |
Returns the number of outputs this block produces.
Implemented in GClasses::GBlockGRU, GClasses::GBlockLSTM, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockAllPairings, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GBlockActivation, GClasses::GMaxPooling2D, GClasses::GBlockSwitch, GClasses::GBlockScalarProduct, GClasses::GBlockScalarSum, and GClasses::GNeuralNet.
|
pure virtual |
Perturbs the weights that feed into the specifed units with Gaussian noise. The default values apply the perturbation to all units.
Implemented in GClasses::GBlockGRU, GClasses::GBlockLSTM, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GNeuralNet, and GClasses::GBlockWeightless.
|
pure virtual |
Initialize the weights, usually with small random values.
Implemented in GClasses::GBlockGRU, GClasses::GBlockLSTM, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GNeuralNet, and GClasses::GBlockWeightless.
|
pure virtual |
Resizes this block.
Implemented in GClasses::GBlockGRU, GClasses::GBlockLSTM, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockAllPairings, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GBlockActivation, GClasses::GMaxPooling2D, GClasses::GBlockSwitch, GClasses::GBlockScalarProduct, GClasses::GBlockScalarSum, and GClasses::GNeuralNet.
|
pure virtual |
Multiplies all the weights by the specified factor.
Implemented in GClasses::GBlockGRU, GClasses::GBlockLSTM, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GNeuralNet, and GClasses::GBlockWeightless.
Marshall this block into a DOM.
Implemented in GClasses::GBlockGRU, GClasses::GBlockLSTM, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockAllPairings, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GBlockActivation, GClasses::GMaxPooling2D, GClasses::GBlockSwitch, GClasses::GBlockScalarProduct, GClasses::GBlockScalarSum, and GClasses::GNeuralNet.
|
inline |
Sets the starting offset in the previous layer's output where values will be fed as input to this block.
|
pure virtual |
Add the weight and bias gradient to the weights.
Implemented in GClasses::GBlockGRU, GClasses::GBlockLSTM, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GNeuralNet, and GClasses::GBlockWeightless.
|
virtual |
Returns a string representation of this block.
Reimplemented in GClasses::GNeuralNet.
|
pure virtual |
Returns the type of this block.
Implemented in GClasses::GBlockGRU, GClasses::GBlockLSTM, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockAllPairings, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GBlockSoftRoot, GClasses::GBlockSoftPlus, GClasses::GBlockLeakyRectifier, GClasses::GBlockRectifier, GClasses::GBlockSine, GClasses::GBlockGaussian, GClasses::GBlockSigExp, GClasses::GBlockBentIdentity, GClasses::GBlockLogistic, GClasses::GBlockScaledTanh, GClasses::GBlockTanh, GClasses::GBlockIdentity, GClasses::GMaxPooling2D, GClasses::GBlockSwitch, GClasses::GBlockScalarProduct, GClasses::GBlockScalarSum, and GClasses::GNeuralNet.
|
pure virtual |
Evaluate the input and outBlame, update the gradient for updating the weights by gradient descent.
Implemented in GClasses::GBlockRecurrent, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GNeuralNet, and GClasses::GBlockWeightless.
|
inlinevirtual |
Returns true iff this block does its computations in parallel on a GPU.
|
pure virtual |
Deserialize from a vector to the weights in this block. Return the number of elements consumed.
Implemented in GClasses::GBlockGRU, GClasses::GBlockLSTM, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GNeuralNet, and GClasses::GBlockWeightless.
|
pure virtual |
Returns the number of double-precision elements necessary to serialize the weights of this block into a vector.
Implemented in GClasses::GBlockGRU, GClasses::GBlockLSTM, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GNeuralNet, and GClasses::GBlockWeightless.
|
pure virtual |
Serialize the weights in this block into a vector. Return the number of elements written.
Implemented in GClasses::GBlockGRU, GClasses::GBlockLSTM, GClasses::GBlockConvolutional2D, GClasses::GBlockConvolutional1D, GClasses::GBlockRestrictedBoltzmannMachine, GClasses::GBlockFuzzy, GClasses::GBlockFeatureSelector, GClasses::GBlockSparse, GClasses::GBlockLinear, GClasses::GBlockSoftExp, GClasses::GNeuralNet, and GClasses::GBlockWeightless.
|
protected |