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

Machine learning functionality for a 1-layer neural network. More...

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "mnist-utils.h"
#include "1lnn.h"

Go to the source code of this file.

Functions

Vector getTargetOutput (int targetIndex)
 Returns an output vector with targetIndex set to 1, all others to 0. More...
 
void initLayer (Layer *l)
 Initialize layer by setting all weights to random values [0-1]. More...
 
int getLayerPrediction (Layer *l)
 Returns the index of the cell with the hightest output. More...
 
void setCellInput (Cell *c, MNIST_Image *img)
 Sets a cell's input according to the pixels of a given MNIST image. More...
 
void calcCellOutput (Cell *c)
 Calculates a cell's output by suming all input-weight-products. More...
 
double getCellError (Cell *c, int target)
 Returns the difference between a target value and the cell's ouput. More...
 
void updateCellWeights (Cell *c, double err)
 Updates a cell's weights based on given error and LEARNING_RATE. More...
 
void trainCell (Cell *c, MNIST_Image *img, int target)
 Performs the training algorithm. More...
 
void testCell (Cell *c, MNIST_Image *img, int target)
 Performs the testing of the trained network. More...
 

Detailed Description

Machine learning functionality for a 1-layer neural network.

Author
Matt Lind
Date
July 2015

Definition in file 1lnn.c.

Function Documentation

void calcCellOutput ( Cell c)

Calculates a cell's output by suming all input-weight-products.

Calculates a cell's output by suming all input-weight-products and normalizes to [0-1].

Definition at line 104 of file 1lnn.c.

double getCellError ( Cell c,
int  target 
)

Returns the difference between a target value and the cell's ouput.

Returns the difference between a target value and the cell's ouput

Definition at line 122 of file 1lnn.c.

int getLayerPrediction ( Layer l)

Returns the index of the cell with the hightest output.

The output prediction is derived by simply sorting all output values and using the index (=0-9 number) of the highest value as the prediction.

Definition at line 62 of file 1lnn.c.

Vector getTargetOutput ( int  targetIndex)

Returns an output vector with targetIndex set to 1, all others to 0.

Returns an output vector with targetIndex set to 1, all others to 0

Definition at line 22 of file 1lnn.c.

void initLayer ( Layer l)

Initialize layer by setting all weights to random values [0-1].

Initialize layer by setting all weights to random values [0-1]

Attention
It actually makes no difference whether the weights are initialized to a constant (e.g. 0.5) or to a random number. The result (85% success rate) will not change significantly.

Definition at line 40 of file 1lnn.c.

void setCellInput ( Cell c,
MNIST_Image img 
)

Sets a cell's input according to the pixels of a given MNIST image.

Creates an input vector of length NUMBER_OF_INPUT_CELLS of a given MNIST image, setting input vector cells to [0,1] based on the pixels of the image. Scalar pixel intensity [=grey-scale] is ignored, only 0 or 1 [=black-white].

Definition at line 89 of file 1lnn.c.

void testCell ( Cell c,
MNIST_Image img,
int  target 
)

Performs the testing of the trained network.

Performs the testing of the trained network Same as training a cell, but without updating weights (learning)

Definition at line 169 of file 1lnn.c.

void trainCell ( Cell c,
MNIST_Image img,
int  target 
)

Performs the training algorithm.

Performs the training algorithm: feeding input, calculate output, calculate error, update weights)

Definition at line 151 of file 1lnn.c.

void updateCellWeights ( Cell c,
double  err 
)

Updates a cell's weights based on given error and LEARNING_RATE.

Updates a cell's weights based on given error and LEARNING_RATE

Definition at line 136 of file 1lnn.c.