GClasses
GClasses::GBlockConvolutional2D Class Reference

#include <GBlock.h>

Inheritance diagram for GClasses::GBlockConvolutional2D:
GClasses::GBlock

Classes

struct  Image
 Image abstraction to facilitate convolution. More...
 

Public Member Functions

 GBlockConvolutional2D (size_t width, size_t height, size_t channels, size_t kWidth, size_t kHeight, size_t kCount=0)
 General-purpose constructor. More...
 
 GBlockConvolutional2D (size_t kWidth, size_t kHeight, size_t kCount=0)
 Constructor that will automatically use the upstream convolutional block when added to a neural network. More...
 
 GBlockConvolutional2D (GDomNode *pNode)
 
void addKernel ()
 
void addKernels (size_t n)
 
virtual void backProp (GContext &ctx, const GVec &input, const GVec &output, const GVec &outBlame, GVec &inBlame) const override
 Evaluates outBlame, and adds to inBlame. (Note that it "adds to" the inBlame because multiple blocks may fork from a common source.) More...
 
const GVecbias () const
 
GVecbias ()
 
virtual void copyWeights (const GBlock *pSource) override
 Copy the weights from pSource to this block. (Assumes pSource is the same type of block.) More...
 
virtual void diminishWeights (double amount, bool regularizeBiases) override
 Moves all weights in the direction of zero by the specified amount. More...
 
virtual void forwardProp (GContext &ctx, const GVec &input, GVec &output) const override
 Evaluate the input, set the output. More...
 
size_t inputChannels () const
 
size_t inputHeight () const
 
virtual size_t inputs () const override
 Returns the number of inputs this block consumes. More...
 
size_t inputWidth () const
 
size_t kernelChannels () const
 
size_t kernelCount () const
 
size_t kernelHeight () const
 
const GMatrixkernels () const
 
GMatrixkernels ()
 
size_t kernelWidth () const
 
virtual void maxNorm (double min, double max) override
 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 override
 Returns the name of this block. More...
 
size_t outputChannels () const
 
size_t outputHeight () const
 
virtual size_t outputs () const override
 Returns the number of outputs this block produces. More...
 
size_t outputWidth () const
 
virtual void perturbWeights (GRand &rand, double deviation) override
 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) override
 Initialize the weights, usually with small random values. More...
 
virtual void resize (size_t inputs, size_t outputs) override
 Resizes this block. More...
 
virtual void scaleWeights (double factor, bool scaleBiases) override
 Multiplies all the weights by the specified factor. More...
 
virtual GDomNodeserialize (GDom *pDoc) const override
 Marshall this block into a DOM. More...
 
void setInputInterlaced (bool interlaced)
 
void setInterlaced (bool interlaced)
 
void setKernelsInterlaced (bool interlaced)
 
void setOutputInterlaced (bool interlaced)
 
void setPadding (size_t px, size_t py=none)
 
void setStride (size_t sx, size_t sy=none)
 
virtual void step (double learningRate, const GVec &gradient) override
 Add the weight and bias gradient to the weights. More...
 
virtual BlockType type () const override
 Returns the type of this block. More...
 
virtual void updateGradient (GContext &ctx, const GVec &input, const GVec &outBlame, GVec &gradient) const override
 Updates the gradient for updating the weights by gradient descent. (Assumes the error has already been computed and deactivated.) More...
 
virtual size_t vectorToWeights (const double *pVector) override
 Deserialize from a vector to the weights in this block. Return the number of elements consumed. More...
 
virtual size_t weightCount () const override
 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 override
 Serialize the weights in this block into a vector. Return the number of elements written. More...
 
- Public Member Functions inherited from GClasses::GBlock
 GBlock ()
 
 GBlock (GDomNode *pNode)
 
virtual ~GBlock ()
 
virtual bool elementWise () const
 Returns true iff this block operates only on individual elements. 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 bool isRecurrent () const
 Returns true iff this block is recurrent. 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 std::string to_str () const
 Returns a string representation of this block. More...
 
virtual bool usesGPU ()
 Returns true iff this block does its computations in parallel on a GPU. More...
 

Static Public Attributes

static size_t none
 

Protected Attributes

Image m_actImage
 
GVec m_bias
 Data. More...
 
GVec m_biasDelta
 
size_t m_channels
 
Image m_deltaImage
 
Image m_errImage
 
size_t m_height
 
Image m_inputImage
 
Image m_kernelImage
 Data as images. More...
 
GMatrix m_kernels
 
size_t m_kHeight
 
size_t m_kWidth
 Kernel dimensions (kernel channels = input channels) More...
 
size_t m_outputHeight
 
size_t m_outputWidth
 Output dimensions (derived; output channels = kernel count) More...
 
Image m_upStreamErrorImage
 
size_t m_width
 Input dimensions. More...
 
- Protected Attributes inherited from GClasses::GBlock
size_t m_inPos
 

Additional Inherited Members

- Public Types inherited from GClasses::GBlock
- Static Public Member Functions inherited from GClasses::GBlock
static GBlockdeserialize (GDomNode *pNode)
 Unmarshalls the specified DOM node into a block object. More...
 
- Protected Member Functions inherited from GClasses::GBlock
GDomNodebaseDomNode (GDom *pDoc) const
 
void basicTest ()
 Exercises some basic functionality that all blocks have in common. More...
 

Constructor & Destructor Documentation

GClasses::GBlockConvolutional2D::GBlockConvolutional2D ( size_t  width,
size_t  height,
size_t  channels,
size_t  kWidth,
size_t  kHeight,
size_t  kCount = 0 
)

General-purpose constructor.

GClasses::GBlockConvolutional2D::GBlockConvolutional2D ( size_t  kWidth,
size_t  kHeight,
size_t  kCount = 0 
)

Constructor that will automatically use the upstream convolutional block when added to a neural network.

GClasses::GBlockConvolutional2D::GBlockConvolutional2D ( GDomNode pNode)

Member Function Documentation

void GClasses::GBlockConvolutional2D::addKernel ( )
void GClasses::GBlockConvolutional2D::addKernels ( size_t  n)
virtual void GClasses::GBlockConvolutional2D::backProp ( GContext ctx,
const GVec input,
const GVec output,
const GVec outBlame,
GVec inBlame 
) const
overridevirtual

Evaluates outBlame, and adds to inBlame. (Note that it "adds to" the inBlame because multiple blocks may fork from a common source.)

Implements GClasses::GBlock.

const GVec& GClasses::GBlockConvolutional2D::bias ( ) const
inline
GVec& GClasses::GBlockConvolutional2D::bias ( )
inline
virtual void GClasses::GBlockConvolutional2D::copyWeights ( const GBlock pSource)
overridevirtual

Copy the weights from pSource to this block. (Assumes pSource is the same type of block.)

Implements GClasses::GBlock.

virtual void GClasses::GBlockConvolutional2D::diminishWeights ( double  amount,
bool  regularizeBiases 
)
overridevirtual

Moves all weights in the direction of zero by the specified amount.

Implements GClasses::GBlock.

virtual void GClasses::GBlockConvolutional2D::forwardProp ( GContext ctx,
const GVec input,
GVec output 
) const
overridevirtual

Evaluate the input, set the output.

Implements GClasses::GBlock.

size_t GClasses::GBlockConvolutional2D::inputChannels ( ) const
inline
size_t GClasses::GBlockConvolutional2D::inputHeight ( ) const
inline
virtual size_t GClasses::GBlockConvolutional2D::inputs ( ) const
inlineoverridevirtual

Returns the number of inputs this block consumes.

Implements GClasses::GBlock.

size_t GClasses::GBlockConvolutional2D::inputWidth ( ) const
inline
size_t GClasses::GBlockConvolutional2D::kernelChannels ( ) const
inline
size_t GClasses::GBlockConvolutional2D::kernelCount ( ) const
inline
size_t GClasses::GBlockConvolutional2D::kernelHeight ( ) const
inline
const GMatrix& GClasses::GBlockConvolutional2D::kernels ( ) const
inline
GMatrix& GClasses::GBlockConvolutional2D::kernels ( )
inline
size_t GClasses::GBlockConvolutional2D::kernelWidth ( ) const
inline
virtual void GClasses::GBlockConvolutional2D::maxNorm ( double  min,
double  max 
)
overridevirtual

Scales weights if necessary such that the manitude of the weights (not including the bias) feeding into each unit are >= min and <= max.

Implements GClasses::GBlock.

virtual std::string GClasses::GBlockConvolutional2D::name ( ) const
inlineoverridevirtual

Returns the name of this block.

Implements GClasses::GBlock.

size_t GClasses::GBlockConvolutional2D::outputChannels ( ) const
inline
size_t GClasses::GBlockConvolutional2D::outputHeight ( ) const
inline
virtual size_t GClasses::GBlockConvolutional2D::outputs ( ) const
inlineoverridevirtual

Returns the number of outputs this block produces.

Implements GClasses::GBlock.

size_t GClasses::GBlockConvolutional2D::outputWidth ( ) const
inline
virtual void GClasses::GBlockConvolutional2D::perturbWeights ( GRand rand,
double  deviation 
)
overridevirtual

Perturbs the weights that feed into the specifed units with Gaussian noise. The default values apply the perturbation to all units.

Implements GClasses::GBlock.

virtual void GClasses::GBlockConvolutional2D::resetWeights ( GRand rand)
overridevirtual

Initialize the weights, usually with small random values.

Implements GClasses::GBlock.

virtual void GClasses::GBlockConvolutional2D::resize ( size_t  inputs,
size_t  outputs 
)
overridevirtual

Resizes this block.

Implements GClasses::GBlock.

virtual void GClasses::GBlockConvolutional2D::scaleWeights ( double  factor,
bool  scaleBiases 
)
overridevirtual

Multiplies all the weights by the specified factor.

Implements GClasses::GBlock.

virtual GDomNode* GClasses::GBlockConvolutional2D::serialize ( GDom pDoc) const
overridevirtual

Marshall this block into a DOM.

Implements GClasses::GBlock.

void GClasses::GBlockConvolutional2D::setInputInterlaced ( bool  interlaced)
void GClasses::GBlockConvolutional2D::setInterlaced ( bool  interlaced)
void GClasses::GBlockConvolutional2D::setKernelsInterlaced ( bool  interlaced)
void GClasses::GBlockConvolutional2D::setOutputInterlaced ( bool  interlaced)
void GClasses::GBlockConvolutional2D::setPadding ( size_t  px,
size_t  py = none 
)
void GClasses::GBlockConvolutional2D::setStride ( size_t  sx,
size_t  sy = none 
)
virtual void GClasses::GBlockConvolutional2D::step ( double  learningRate,
const GVec gradient 
)
overridevirtual

Add the weight and bias gradient to the weights.

Implements GClasses::GBlock.

virtual BlockType GClasses::GBlockConvolutional2D::type ( ) const
inlineoverridevirtual

Returns the type of this block.

Implements GClasses::GBlock.

virtual void GClasses::GBlockConvolutional2D::updateGradient ( GContext ctx,
const GVec input,
const GVec outBlame,
GVec gradient 
) const
overridevirtual

Updates the gradient for updating the weights by gradient descent. (Assumes the error has already been computed and deactivated.)

Implements GClasses::GBlock.

virtual size_t GClasses::GBlockConvolutional2D::vectorToWeights ( const double *  pVector)
overridevirtual

Deserialize from a vector to the weights in this block. Return the number of elements consumed.

Implements GClasses::GBlock.

virtual size_t GClasses::GBlockConvolutional2D::weightCount ( ) const
overridevirtual

Returns the number of double-precision elements necessary to serialize the weights of this block into a vector.

Implements GClasses::GBlock.

virtual size_t GClasses::GBlockConvolutional2D::weightsToVector ( double *  pOutVector) const
overridevirtual

Serialize the weights in this block into a vector. Return the number of elements written.

Implements GClasses::GBlock.

Member Data Documentation

Image GClasses::GBlockConvolutional2D::m_actImage
protected
GVec GClasses::GBlockConvolutional2D::m_bias
protected

Data.

GVec GClasses::GBlockConvolutional2D::m_biasDelta
protected
size_t GClasses::GBlockConvolutional2D::m_channels
protected
Image GClasses::GBlockConvolutional2D::m_deltaImage
protected
Image GClasses::GBlockConvolutional2D::m_errImage
protected
size_t GClasses::GBlockConvolutional2D::m_height
protected
Image GClasses::GBlockConvolutional2D::m_inputImage
protected
Image GClasses::GBlockConvolutional2D::m_kernelImage
protected

Data as images.

GMatrix GClasses::GBlockConvolutional2D::m_kernels
protected
size_t GClasses::GBlockConvolutional2D::m_kHeight
protected
size_t GClasses::GBlockConvolutional2D::m_kWidth
protected

Kernel dimensions (kernel channels = input channels)

size_t GClasses::GBlockConvolutional2D::m_outputHeight
protected
size_t GClasses::GBlockConvolutional2D::m_outputWidth
protected

Output dimensions (derived; output channels = kernel count)

Image GClasses::GBlockConvolutional2D::m_upStreamErrorImage
protected
size_t GClasses::GBlockConvolutional2D::m_width
protected

Input dimensions.

size_t GClasses::GBlockConvolutional2D::none
static