GClasses
|
Represents a layer of neurons in a neural network. More...
#include <GNeuralNet.h>
Public Member Functions | |
GNeuralNetLayer () | |
virtual | ~GNeuralNetLayer () |
virtual void | activate ()=0 |
Applies the activation function to the net vector to compute the activation vector. More... | |
virtual double * | activation ()=0 |
Returns a buffer where the activation from the most-recent call to feedForward is stored. More... | |
virtual void | backPropError (GNeuralNetLayer *pUpStreamLayer, size_t inputStart=0)=0 |
Computes the activation error of the layer that feeds into this one. inputStart is used if multiple layers feed into this one. It specifies the starting index of all the inputs where this layer feeds in. More... | |
virtual void | computeError (const double *pTarget)=0 |
Computes the error term of the activation. More... | |
virtual void | copyBiasToNet ()=0 |
Copies the bias vector into the net vector. (This should be done before feedIn is called.) More... | |
virtual void | copySingleNeuronWeights (size_t source, size_t dest) |
virtual void | copyWeights (GNeuralNetLayer *pSource)=0 |
Copy the weights from pSource to this layer. (Assumes pSource is the same type of layer.) More... | |
virtual size_t | countWeights ()=0 |
Returns the number of double-precision elements necessary to serialize the weights of this layer into a vector. More... | |
virtual void | deactivateError ()=0 |
Converts the error term to refer to the net input. More... | |
virtual void | diminishWeights (double amount, bool regularizeBiases)=0 |
Moves all weights in the direction of zero by the specified amount. More... | |
virtual void | dropConnect (GRand &rand, double probOfDrop)=0 |
Randomly sets some of the weights to 0. (The dropped weights are restored when you call updateWeightsAndRestoreDroppedOnes.) More... | |
virtual void | dropOut (GRand &rand, double probOfDrop)=0 |
Randomly sets the activation of some units to 0. More... | |
virtual double * | error ()=0 |
Returns a buffer where the error terms for each unit are stored. More... | |
void | feedForward (const double *pIn) |
Feeds in the bias and pIn, then computes the activation of this layer. More... | |
virtual void | feedIn (const double *pIn, size_t inputStart, size_t inputCount)=0 |
Feeds the inputs (or a portion of the inputs) through the weights and updates the net. More... | |
virtual void | feedIn (GNeuralNetLayer *pUpStreamLayer, size_t inputStart) |
Feeds the previous layer's activation into this layer. (Implementations for specialized hardware may override this method to avoid shuttling the previous layer's activation back to host memory.) More... | |
GMatrix * | feedThrough (const GMatrix &data) |
Feeds a matrix through this layer, one row at-a-time, and returns the resulting transformed matrix. More... | |
virtual void | getWeightsSingleNeuron (size_t outputNode, double *&weights) |
Gets the weights and bias of a single neuron. More... | |
virtual size_t | inputs ()=0 |
Returns the number of values expected to be fed as input into this layer. More... | |
virtual void | maxNorm (double max)=0 |
Scales weights if necessary such that the manitude of the weights (not including the bias) feeding into each unit are <= max. More... | |
virtual size_t | outputs ()=0 |
Returns the number of values that this layer outputs. More... | |
virtual void | perturbWeights (GRand &rand, double deviation, size_t start=0, size_t count=INVALID_INDEX)=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 | renormalizeInput (size_t input, double oldMin, double oldMax, double newMin=0.0, double newMax=1.0)=0 |
Adjusts weights such that values in the new range will result in the same behavior that previously resulted from values in the old range. More... | |
virtual void | resetWeights (GRand &rand)=0 |
Initialize the weights with small random values. More... | |
virtual void | resize (size_t inputs, size_t outputs, GRand *pRand=NULL, double deviation=0.03)=0 |
Resizes this layer. If pRand is non-NULL, then it preserves existing weights when possible and initializes any others to small random values. More... | |
virtual void | scaleUnitIncomingWeights (size_t unit, double scalar)=0 |
Scale weights that feed into the specified unit. More... | |
virtual void | scaleUnitOutgoingWeights (size_t input, double scalar)=0 |
Scale weights that feed into this layer from the specified input. More... | |
virtual void | scaleWeights (double factor, bool scaleBiases)=0 |
Multiplies all the weights by the specified factor. More... | |
virtual GDomNode * | serialize (GDom *pDoc)=0 |
Marshall this layer into a DOM. More... | |
virtual void | setWeightsSingleNeuron (size_t outputNode, const double *weights) |
Gets the weights and bias of a single neuron. More... | |
virtual const char * | type ()=0 |
Returns the type of this layer. More... | |
virtual double | unitIncomingWeightsL1Norm (size_t unit)=0 |
Compute the L1 norm (sum of absolute values) of weights feeding into the specified unit. More... | |
virtual double | unitIncomingWeightsL2Norm (size_t unit)=0 |
Compute the L2 norm (sum of squares) of weights feeding into the specified unit. More... | |
virtual double | unitOutgoingWeightsL1Norm (size_t input)=0 |
Compute the L1 norm (sum of absolute values) of weights feeding into this layer from the specified input. More... | |
virtual double | unitOutgoingWeightsL2Norm (size_t input)=0 |
Compute the L2 norm (sum of squares) of weights feeding into this layer from the specified input. More... | |
virtual void | updateBias (double learningRate, double momentum)=0 |
Updates the bias of this layer by gradient descent. (Assumes the error has already been computed and deactivated.) More... | |
virtual void | updateWeights (const double *pUpStreamActivation, size_t inputStart, size_t inputCount, double learningRate, double momentum)=0 |
Updates the weights that feed into this layer (not including the bias) by gradient descent. (Assumes the error has already been computed and deactivated.) More... | |
virtual void | updateWeights (GNeuralNetLayer *pUpStreamLayer, size_t inputStart, double learningRate, double momentum) |
Refines the weights by gradient descent. More... | |
virtual void | updateWeightsAndRestoreDroppedOnes (const double *pUpStreamActivation, size_t inputStart, size_t inputCount, double learningRate, double momentum)=0 |
This is a special weight update method for use with drop-connect. It updates the weights, and restores the weights that were previously dropped by a call to dropConnect. More... | |
virtual void | updateWeightsAndRestoreDroppedOnes (GNeuralNetLayer *pUpStreamLayer, size_t inputStart, double learningRate, double momentum) |
Refines the weights by gradient descent. More... | |
virtual bool | usesGPU () |
Returns true iff this layer 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 layer. Return the number of elements consumed. More... | |
virtual size_t | weightsToVector (double *pOutVector)=0 |
Serialize the weights in this layer into a vector. Return the number of elements written. More... | |
Static Public Member Functions | |
static GNeuralNetLayer * | deserialize (GDomNode *pNode) |
Unmarshalls the specified DOM node into a layer object. More... | |
Protected Member Functions | |
GDomNode * | baseDomNode (GDom *pDoc) |
Represents a layer of neurons in a neural network.
|
inline |
|
inlinevirtual |
|
pure virtual |
Applies the activation function to the net vector to compute the activation vector.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, GClasses::GLayerSoftMax, and GClasses::GLayerClassic.
|
pure virtual |
Returns a buffer where the activation from the most-recent call to feedForward is stored.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Computes the activation error of the layer that feeds into this one. inputStart is used if multiple layers feed into this one. It specifies the starting index of all the inputs where this layer feeds in.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Computes the error term of the activation.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Copies the bias vector into the net vector. (This should be done before feedIn is called.)
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
inlinevirtual |
Reimplemented in GClasses::GLayerClassic.
|
pure virtual |
Copy the weights from pSource to this layer. (Assumes pSource is the same type of layer.)
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Returns the number of double-precision elements necessary to serialize the weights of this layer into a vector.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Converts the error term to refer to the net input.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, GClasses::GLayerSoftMax, and GClasses::GLayerClassic.
|
static |
Unmarshalls the specified DOM node into a layer object.
|
pure virtual |
Moves all weights in the direction of zero by the specified amount.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Randomly sets some of the weights to 0. (The dropped weights are restored when you call updateWeightsAndRestoreDroppedOnes.)
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Randomly sets the activation of some units to 0.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Returns a buffer where the error terms for each unit are stored.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
void GClasses::GNeuralNetLayer::feedForward | ( | const double * | pIn | ) |
Feeds in the bias and pIn, then computes the activation of this layer.
|
pure virtual |
Feeds the inputs (or a portion of the inputs) through the weights and updates the net.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
inlinevirtual |
Feeds the previous layer's activation into this layer. (Implementations for specialized hardware may override this method to avoid shuttling the previous layer's activation back to host memory.)
Feeds a matrix through this layer, one row at-a-time, and returns the resulting transformed matrix.
|
inlinevirtual |
Gets the weights and bias of a single neuron.
Reimplemented in GClasses::GLayerClassic.
|
pure virtual |
Returns the number of values expected to be fed as input into this layer.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Scales weights if necessary such that the manitude of the weights (not including the bias) feeding into each unit are <= max.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Returns the number of values that this layer outputs.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
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::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Adjusts weights such that values in the new range will result in the same behavior that previously resulted from values in the old range.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Initialize the weights with small random values.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Resizes this layer. If pRand is non-NULL, then it preserves existing weights when possible and initializes any others to small random values.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Scale weights that feed into the specified unit.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Scale weights that feed into this layer from the specified input.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Multiplies all the weights by the specified factor.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
Marshall this layer into a DOM.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
inlinevirtual |
Gets the weights and bias of a single neuron.
Reimplemented in GClasses::GLayerClassic.
|
pure virtual |
Returns the type of this layer.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, GClasses::GLayerSoftMax, and GClasses::GLayerClassic.
|
pure virtual |
Compute the L1 norm (sum of absolute values) of weights feeding into the specified unit.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Compute the L2 norm (sum of squares) of weights feeding into the specified unit.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Compute the L1 norm (sum of absolute values) of weights feeding into this layer from the specified input.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Compute the L2 norm (sum of squares) of weights feeding into this layer from the specified input.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Updates the bias of this layer by gradient descent. (Assumes the error has already been computed and deactivated.)
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Updates the weights that feed into this layer (not including the bias) by gradient descent. (Assumes the error has already been computed and deactivated.)
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
inlinevirtual |
Refines the weights by gradient descent.
|
pure virtual |
This is a special weight update method for use with drop-connect. It updates the weights, and restores the weights that were previously dropped by a call to dropConnect.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
inlinevirtual |
Refines the weights by gradient descent.
|
inlinevirtual |
Returns true iff this layer does its computations in parallel on a GPU.
|
pure virtual |
Deserialize from a vector to the weights in this layer. Return the number of elements consumed.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.
|
pure virtual |
Serialize the weights in this layer into a vector. Return the number of elements written.
Implemented in GClasses::GLayerConvolutional2D, GClasses::GLayerConvolutional1D, GClasses::GLayerRestrictedBoltzmannMachine, GClasses::GLayerMixed, and GClasses::GLayerClassic.