MNIST-3LNN  1.0
A simple 3-layer neural network to recognize handwritten single digit numbers from the MNIST image files.
Functions
3lnn.c File Reference

Neural network functionality for a 3-layer (INPUT, HIDDEN, OUTPUT) feed-forward, back-prop NN. More...

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "util/mnist-utils.h"
#include "3lnn.h"

Go to the source code of this file.

Functions

NodegetNode (Layer *l, int nodeId)
 
LayergetLayer (Network *nn, LayerType ltype)
 Returns one of the layers of the network. More...
 
double getActFctDerivative (Network *nn, LayerType ltype, double outVal)
 Returns the result of applying the given outputValue to the derivate of the activation function. More...
 
void updateNodeWeights (Network *nn, LayerType ltype, int id, double error)
 Updates a node's weights based on given error. More...
 
void backPropagateHiddenLayer (Network *nn, int targetClassification)
 Back propagates network error to hidden layer. More...
 
void backPropagateOutputLayer (Network *nn, int targetClassification)
 Back propagates network error in output layer. More...
 
void backPropagateNetwork (Network *nn, int targetClassification)
 Back propagates network error from output layer to hidden layer. More...
 
void activateNode (Network *nn, LayerType ltype, int id)
 Performs an activiation function (as defined in the NN's defaults) to a specified node. More...
 
void calcNodeOutput (Network *nn, LayerType ltype, int id)
 Calculates the output value of a specified node by multiplying all its weights with the previous layer's outputs. More...
 
void calcLayer (Network *nn, LayerType ltype)
 Calculates the output values of a given NN layer. More...
 
void feedForwardNetwork (Network *nn)
 Feeds input layer values forward to hidden to output layer (calculation and activation fct) More...
 
void feedInput (Network *nn, Vector *v)
 Feeds some Vector data into the INPUT layer of the NN. More...
 
LayercreateInputLayer (int inpCount)
 
LayercreateLayer (int nodeCount, int weightCount)
 
void initNetwork (Network *nn, int inpCount, int hidCount, int outCount)
 Initializes the NN by creating and copying INTPUT, HIDDEN, OUTPUT data structures into the NN's memory space. More...
 
void setNetworkDefaults (Network *nn)
 Sets the default network parameters (which can be overwritten/changed) More...
 
void initWeights (Network *nn, LayerType ltype)
 Initializes a layer's weights with random values. More...
 
NetworkcreateNetwork (int inpCount, int hidCount, int outCount)
 Creates a dynamically-sized, 3-layer (INTPUT, HIDDEN, OUTPUT) neural network. More...
 
int getNetworkClassification (Network *nn)
 Returns the network's classification using the ID of teh node with the hightest output. More...
 

Detailed Description

Neural network functionality for a 3-layer (INPUT, HIDDEN, OUTPUT) feed-forward, back-prop NN.

Author
Matt Lind
Date
August 2015

Definition in file 3lnn.c.

Function Documentation

void activateNode ( Network nn,
LayerType  ltype,
int  id 
)

Performs an activiation function (as defined in the NN's defaults) to a specified node.

Parameters
nnA pointer to the NN
ltypeType of layer (INPUT, HIDDEN, OUTPUT)
idSequential id of the node that is to be calculated

Definition at line 224 of file 3lnn.c.

void backPropagateHiddenLayer ( Network nn,
int  targetClassification 
)

Back propagates network error to hidden layer.

Parameters
nnA pointer to the NN
targetClassificationCorrect classification (=label) of the input stream

Definition at line 140 of file 3lnn.c.

void backPropagateNetwork ( Network nn,
int  targetClassification 
)

Back propagates network error from output layer to hidden layer.

Parameters
nnA pointer to the NN
targetClassificationCorrect classification (=label) of the input stream

Definition at line 206 of file 3lnn.c.

void backPropagateOutputLayer ( Network nn,
int  targetClassification 
)

Back propagates network error in output layer.

Parameters
nnA pointer to the NN
targetClassificationCorrect classification (=label) of the input stream

Definition at line 178 of file 3lnn.c.

void calcLayer ( Network nn,
LayerType  ltype 
)

Calculates the output values of a given NN layer.

Parameters
nnA pointer to the NN
ltypeType of layer (INPUT, HIDDEN, OUTPUT)

Definition at line 288 of file 3lnn.c.

void calcNodeOutput ( Network nn,
LayerType  ltype,
int  id 
)

Calculates the output value of a specified node by multiplying all its weights with the previous layer's outputs.

Parameters
nnA pointer to the NN
ltypeType of layer (INPUT, HIDDEN, OUTPUT)
idSequential id of the node that is to be calculated

Definition at line 249 of file 3lnn.c.

Layer* createInputLayer ( int  inpCount)

Creates an input layer and sets all weights to random values [0-1]

Parameters
inpCountNumber of nodes in the input layer

Definition at line 344 of file 3lnn.c.

Layer* createLayer ( int  nodeCount,
int  weightCount 
)

Creates a layer and sets all weights to random values [0-1]

Parameters
nodeCountNumber of nodes
weightCountNumber of weights per node

Definition at line 378 of file 3lnn.c.

Network* createNetwork ( int  inpCount,
int  hidCount,
int  outCount 
)

Creates a dynamically-sized, 3-layer (INTPUT, HIDDEN, OUTPUT) neural network.

Parameters
inpCountNumber of nodes in the INPUT layer
hidCountNumber of nodes in the HIDDEN layer
outCountNumber of nodes in the OUTPUT layer

Definition at line 505 of file 3lnn.c.

void feedForwardNetwork ( Network nn)

Feeds input layer values forward to hidden to output layer (calculation and activation fct)

Parameters
nnA pointer to the NN

Definition at line 306 of file 3lnn.c.

void feedInput ( Network nn,
Vector v 
)

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

Parameters
nnA pointer to the NN
vA pointer to a vector

Definition at line 320 of file 3lnn.c.

double getActFctDerivative ( Network nn,
LayerType  ltype,
double  outVal 
)

Returns the result of applying the given outputValue to the derivate of the activation function.

Parameters
nnA pointer to the NN
ltypeType of layer (INPUT, HIDDEN, OUTPUT)
outValOutput value that is to be back propagated

Definition at line 78 of file 3lnn.c.

Layer* getLayer ( Network nn,
LayerType  ltype 
)

Returns one of the layers of the network.

Parameters
nnA pointer to the NN
ltypeType of layer to be returned (INPUT, HIDDEN, OUTPUT)

Definition at line 41 of file 3lnn.c.

int getNetworkClassification ( Network nn)

Returns the network's classification using the ID of teh node with the hightest output.

Parameters
nnA pointer to the NN

Definition at line 553 of file 3lnn.c.

Node* getNode ( Layer l,
int  nodeId 
)

Retrieves a node via ID from a layer

Definition at line 22 of file 3lnn.c.

void initNetwork ( Network nn,
int  inpCount,
int  hidCount,
int  outCount 
)

Initializes the NN by creating and copying INTPUT, HIDDEN, OUTPUT data structures into the NN's memory space.

Parameters
nnA pointer to the NN
inpCountNumber of nodes in the INPUT layer
hidCountNumber of nodes in the HIDDEN layer
outCountNumber of nodes in the OUTPUT layer

Definition at line 413 of file 3lnn.c.

void initWeights ( Network nn,
LayerType  ltype 
)

Initializes a layer's weights with random values.

Parameters
nnA pointer to the NN
ltypeDefining what layer to initialize

Definition at line 467 of file 3lnn.c.

void setNetworkDefaults ( Network nn)

Sets the default network parameters (which can be overwritten/changed)

Parameters
nnA pointer to the NN

Definition at line 447 of file 3lnn.c.

void updateNodeWeights ( Network nn,
LayerType  ltype,
int  id,
double  error 
)

Updates a node's weights based on given error.

Parameters
nnA pointer to the NN
ltypeType of layer (INPUT, HIDDEN, OUTPUT)
idSequential id of the node that is to be calculated
errorThe error (difference between desired output and actual output

Definition at line 103 of file 3lnn.c.