GClasses
GClasses::GNeuralNetLayer Class Referenceabstract

Represents a layer of neurons in a neural network. More...

#include <GNeuralNet.h>

Inheritance diagram for GClasses::GNeuralNetLayer:
GClasses::GLayerClassic GClasses::GLayerConvolutional1D GClasses::GLayerConvolutional2D GClasses::GLayerMixed GClasses::GLayerRestrictedBoltzmannMachine GClasses::GLayerSoftMax

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...
 
GMatrixfeedThrough (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 GDomNodeserialize (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 GNeuralNetLayerdeserialize (GDomNode *pNode)
 Unmarshalls the specified DOM node into a layer object. More...
 

Protected Member Functions

GDomNodebaseDomNode (GDom *pDoc)
 

Detailed Description

Represents a layer of neurons in a neural network.

Constructor & Destructor Documentation

GClasses::GNeuralNetLayer::GNeuralNetLayer ( )
inline
virtual GClasses::GNeuralNetLayer::~GNeuralNetLayer ( )
inlinevirtual

Member Function Documentation

virtual void GClasses::GNeuralNetLayer::activate ( )
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.

virtual double* GClasses::GNeuralNetLayer::activation ( )
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.

virtual void GClasses::GNeuralNetLayer::backPropError ( GNeuralNetLayer pUpStreamLayer,
size_t  inputStart = 0 
)
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.

GDomNode* GClasses::GNeuralNetLayer::baseDomNode ( GDom pDoc)
protected
virtual void GClasses::GNeuralNetLayer::computeError ( const double *  pTarget)
pure virtual
virtual void GClasses::GNeuralNetLayer::copyBiasToNet ( )
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.

virtual void GClasses::GNeuralNetLayer::copySingleNeuronWeights ( size_t  source,
size_t  dest 
)
inlinevirtual

Reimplemented in GClasses::GLayerClassic.

virtual void GClasses::GNeuralNetLayer::copyWeights ( GNeuralNetLayer pSource)
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.

virtual size_t GClasses::GNeuralNetLayer::countWeights ( )
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.

virtual void GClasses::GNeuralNetLayer::deactivateError ( )
pure virtual
static GNeuralNetLayer* GClasses::GNeuralNetLayer::deserialize ( GDomNode pNode)
static

Unmarshalls the specified DOM node into a layer object.

virtual void GClasses::GNeuralNetLayer::diminishWeights ( double  amount,
bool  regularizeBiases 
)
pure virtual
virtual void GClasses::GNeuralNetLayer::dropConnect ( GRand rand,
double  probOfDrop 
)
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.

virtual void GClasses::GNeuralNetLayer::dropOut ( GRand rand,
double  probOfDrop 
)
pure virtual
virtual double* GClasses::GNeuralNetLayer::error ( )
pure virtual
void GClasses::GNeuralNetLayer::feedForward ( const double *  pIn)

Feeds in the bias and pIn, then computes the activation of this layer.

virtual void GClasses::GNeuralNetLayer::feedIn ( const double *  pIn,
size_t  inputStart,
size_t  inputCount 
)
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.

virtual void GClasses::GNeuralNetLayer::feedIn ( GNeuralNetLayer pUpStreamLayer,
size_t  inputStart 
)
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.)

GMatrix* GClasses::GNeuralNetLayer::feedThrough ( const GMatrix data)

Feeds a matrix through this layer, one row at-a-time, and returns the resulting transformed matrix.

virtual void GClasses::GNeuralNetLayer::getWeightsSingleNeuron ( size_t  outputNode,
double *&  weights 
)
inlinevirtual

Gets the weights and bias of a single neuron.

Reimplemented in GClasses::GLayerClassic.

virtual size_t GClasses::GNeuralNetLayer::inputs ( )
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.

virtual void GClasses::GNeuralNetLayer::maxNorm ( double  max)
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.

virtual size_t GClasses::GNeuralNetLayer::outputs ( )
pure virtual
virtual void GClasses::GNeuralNetLayer::perturbWeights ( GRand rand,
double  deviation,
size_t  start = 0,
size_t  count = INVALID_INDEX 
)
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.

virtual void GClasses::GNeuralNetLayer::renormalizeInput ( size_t  input,
double  oldMin,
double  oldMax,
double  newMin = 0.0,
double  newMax = 1.0 
)
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.

virtual void GClasses::GNeuralNetLayer::resetWeights ( GRand rand)
pure virtual
virtual void GClasses::GNeuralNetLayer::resize ( size_t  inputs,
size_t  outputs,
GRand pRand = NULL,
double  deviation = 0.03 
)
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.

virtual void GClasses::GNeuralNetLayer::scaleUnitIncomingWeights ( size_t  unit,
double  scalar 
)
pure virtual
virtual void GClasses::GNeuralNetLayer::scaleUnitOutgoingWeights ( size_t  input,
double  scalar 
)
pure virtual
virtual void GClasses::GNeuralNetLayer::scaleWeights ( double  factor,
bool  scaleBiases 
)
pure virtual
virtual GDomNode* GClasses::GNeuralNetLayer::serialize ( GDom pDoc)
pure virtual
virtual void GClasses::GNeuralNetLayer::setWeightsSingleNeuron ( size_t  outputNode,
const double *  weights 
)
inlinevirtual

Gets the weights and bias of a single neuron.

Reimplemented in GClasses::GLayerClassic.

virtual const char* GClasses::GNeuralNetLayer::type ( )
pure virtual
virtual double GClasses::GNeuralNetLayer::unitIncomingWeightsL1Norm ( size_t  unit)
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.

virtual double GClasses::GNeuralNetLayer::unitIncomingWeightsL2Norm ( size_t  unit)
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.

virtual double GClasses::GNeuralNetLayer::unitOutgoingWeightsL1Norm ( size_t  input)
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.

virtual double GClasses::GNeuralNetLayer::unitOutgoingWeightsL2Norm ( size_t  input)
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.

virtual void GClasses::GNeuralNetLayer::updateBias ( double  learningRate,
double  momentum 
)
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.

virtual void GClasses::GNeuralNetLayer::updateWeights ( const double *  pUpStreamActivation,
size_t  inputStart,
size_t  inputCount,
double  learningRate,
double  momentum 
)
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.

virtual void GClasses::GNeuralNetLayer::updateWeights ( GNeuralNetLayer pUpStreamLayer,
size_t  inputStart,
double  learningRate,
double  momentum 
)
inlinevirtual

Refines the weights by gradient descent.

virtual void GClasses::GNeuralNetLayer::updateWeightsAndRestoreDroppedOnes ( const double *  pUpStreamActivation,
size_t  inputStart,
size_t  inputCount,
double  learningRate,
double  momentum 
)
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.

virtual void GClasses::GNeuralNetLayer::updateWeightsAndRestoreDroppedOnes ( GNeuralNetLayer pUpStreamLayer,
size_t  inputStart,
double  learningRate,
double  momentum 
)
inlinevirtual

Refines the weights by gradient descent.

virtual bool GClasses::GNeuralNetLayer::usesGPU ( )
inlinevirtual

Returns true iff this layer does its computations in parallel on a GPU.

virtual size_t GClasses::GNeuralNetLayer::vectorToWeights ( const double *  pVector)
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.

virtual size_t GClasses::GNeuralNetLayer::weightsToVector ( double *  pOutVector)
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.