Deep Neural Network for MNIST Handwriting Recognition  1.0
Deep Neural Network for MNIST Handwriting Recognition
Data Structures | Macros | Typedefs | Enumerations | Functions
/Users/mlind/Coding/Github/mnist-dnn/dnn.h File Reference

Core network library for a deep neural network. More...

#include "util/mnist-utils.h"
#include "util/mnist-stats.h"

Go to the source code of this file.

Data Structures

struct  Volume
 Data structure defining a 3-dimensional vector used to define the size of a node map. More...
 
struct  LayerDefinition
 Data structure allowing users to define the characteristics of a network. More...
 
struct  Connection
 Data structure attached to a node and pointing to another node as well as to a weight. More...
 
struct  Node
 Variably-sized data structure modeling a neuron with a variable number of connections/weights. More...
 
struct  Column
 Variably-sized data structure modeling a vector of nodes. More...
 
struct  Layer
 Variably-sized data structure holding a definable number of columns that form a layer. More...
 
struct  Network
 Variably-sized data structure that serves as the over container for a whole network. More...
 

Macros

#define MAX_CONVOLUTIONAL_FILTER   10
 

Typedefs

typedef struct LayerDefinition LayerDefinition
 
typedef struct Vector3D Vector3D
 
typedef struct Value2D Value2D
 
typedef struct Volume Volume
 
typedef struct Network Network
 
typedef struct Layer Layer
 
typedef struct Column Column
 
typedef struct Node Node
 
typedef struct Connection Connection
 
typedef double Weight
 
typedef unsigned long ByteSize
 
typedef enum LayerType LayerType
 
typedef enum ActFctType ActFctType
 

Enumerations

enum  LayerType {
  EMPTY, INPUT, CONVOLUTIONAL, FULLY_CONNECTED,
  OUTPUT
}
 
enum  ActFctType { SIGMOID, TANH, RELU, NONE }
 

Functions

int getLayerNodeCount (LayerDefinition *layerDef)
 Returns the number of nodes in a layer. More...
 
int getNodeBackwardConnectionCount (LayerDefinition *layerDef)
 Returns the number of backward connections of a NODE (not of a layer) More...
 
int getLayerWeightCount (LayerDefinition *layerDef)
 Returns the number of weights for a layer (based on a given layer definition) More...
 
ByteSize getLayerWeightBlockSize (LayerDefinition *layerDef)
 Returns the memory (byte) size of the weights block for a specific layer. More...
 
ByteSize getLayerSize (LayerDefinition *layerDef)
 Returns the memory (byte) size of a specific layer based on a given layer definition. More...
 
int calcStride (int tgtWidth, int filter, int srcWidth)
 Calculates the stride (number of nodes/columns that are skipped) in a convolutional kernel. More...
 
void feedInput (Network *nn, Vector *v)
 Feeds some Vector data into the INPUT layer of the network. More...
 
void feedForwardNetwork (Network *nn)
 Feeds forward (=calculating a node's output value and applying an activation function) layer by layer. More...
 
void backPropagateNetwork (Network *nn, int targetClassification)
 Backpropagates the output nodes' errors from output layer backwards to first layer. More...
 
int getNetworkClassification (Network *nn)
 Returns the network's classification of the input image by choosing the node with the hightest output. More...
 
NetworkcreateNetwork (int layerCount, LayerDefinition *layerDefs)
 Creates the neural network based on a given array of layer definitions. More...
 
LayerDefinitionsetLayerDefinitions (int layerCount,...)
 Returns a pointer to an array of a variable number of layer definitions. More...
 

Detailed Description

Core network library for a deep neural network.

Author
Matt Lind
Date
February 2016

Macro Definition Documentation

#define MAX_CONVOLUTIONAL_FILTER   10

Typedef Documentation

typedef enum ActFctType ActFctType
typedef unsigned long ByteSize
typedef struct Column Column
typedef struct Connection Connection
typedef struct Layer Layer
typedef enum LayerType LayerType
typedef struct Network Network
typedef struct Node Node
typedef struct Value2D Value2D
typedef struct Vector3D Vector3D
typedef struct Volume Volume
typedef double Weight

Enumeration Type Documentation

enum ActFctType
Enumerator
SIGMOID 
TANH 
RELU 
NONE 
enum LayerType
Enumerator
EMPTY 
INPUT 
CONVOLUTIONAL 
FULLY_CONNECTED 
OUTPUT 

Function Documentation

void backPropagateNetwork ( Network nn,
int  targetClassification 
)

Backpropagates the output nodes' errors from output layer backwards to first layer.

The network's backpropagation proceeds in 2 steps:

  1. CALCULATE OUTPUT NODES' ERRORS a. Calculate the errorsums in all output cells based on the targetClassification
  2. BACKPROPAGATE EACH LAYER a. Update the nodes weights based on actual output and accumulated errorsum b. Calculate the errorsums in all TARGET cells based on errorsum in this layer (calculated in 3)
Parameters
nnA pointer to the neural network
targetClassificationThe correct/desired classification (=label) of this recognition/image
int calcStride ( int  tgtWidth,
int  filter,
int  srcWidth 
)

Calculates the stride (number of nodes/columns that are skipped) in a convolutional kernel.

Parameters
tgtWidthNumber of columns on the x-axis (horizontally) in the TARGET (=previous) layer
filterNumber of columns/nodes on the x-axis in a filter window (
Attention
ASSSUMES WIDTH=HEIGHT!!)
Parameters
srcWidthNumber of columns on the x-axis (horizontally) in the SOURCE (=this) layer
Network* createNetwork ( int  layerCount,
LayerDefinition layerDefs 
)

Creates the neural network based on a given array of layer definitions.

Creates a reserved memory block for this network based on the given layer definitions, and then initializes this memory with the respective layer/node/connection/weights structure.

Parameters
layerCountThe number of layer definitions inside the layer-definition-array (2nd param)
layerDefsA pointer to an array of layer definitions
void feedForwardNetwork ( Network nn)

Feeds forward (=calculating a node's output value and applying an activation function) layer by layer.

Feeds forward from 2nd=#1 layer (i.e. skips input layer) to output layer

Parameters
nnA pointer to the NN
void feedInput ( Network nn,
Vector v 
)

Feeds some Vector data into the INPUT layer of the network.

Parameters
nnA pointer to the neural network
vA pointer to the vector holding the input values
int getLayerNodeCount ( LayerDefinition layerDef)

Returns the number of nodes in a layer.

Parameters
layerDefPointer to a layer definition
ByteSize getLayerSize ( LayerDefinition layerDef)

Returns the memory (byte) size of a specific layer based on a given layer definition.

Each layer's memory size may be different due to a different number of nodes and connections For FEED FORWARD (e.g. OUTPUT) layers, full connectivity is assumed (i.e. each node links to ALL nodes in the previous layer)

Parameters
layerDefA pointer to a layer definition
ByteSize getLayerWeightBlockSize ( LayerDefinition layerDef)

Returns the memory (byte) size of the weights block for a specific layer.

Each layer's number of weights may be different due to a different number of connections For FEED FORWARD (HIDDEN and OUTPUT) layers, full connectivity is assumed, CONV layers e.g. share weights.

Parameters
layerDefA pointer to a layer definition
int getLayerWeightCount ( LayerDefinition layerDef)

Returns the number of weights for a layer (based on a given layer definition)

Parameters
layerDefA pointer to the layer definition
int getNetworkClassification ( Network nn)

Returns the network's classification of the input image by choosing the node with the hightest output.

Parameters
nnA pointer to the neural network
int getNodeBackwardConnectionCount ( LayerDefinition layerDef)

Returns the number of backward connections of a NODE (not of a layer)

For FEED FORWARD (HIDDEN and OUTPUT) layers, full connectivity is assumed (each node links to ALL nodes in the previous layer)

Parameters
layerDefPointer to a layer definition
LayerDefinition* setLayerDefinitions ( int  layerCount,
  ... 
)

Returns a pointer to an array of a variable number of layer definitions.

Parameters
layerCountNumber of layers of the network
...Variabe number of layer definition objects