![]() |
MNIST-1LNN
1.0
A simple 1-layer neural network to recognize handwritten single digit numbers from the MNIST image files.
|
Machine learning functionality for a 1-layer neural network. More...
#include <stdio.h>Go to the source code of this file.
Data Structures | |
| struct | Cell |
| Core unit of the neural network (neuron and synapses) More... | |
| struct | Layer |
| The single (output) layer of this network (a layer is number cells) More... | |
| struct | Vector |
| Data structure containing defined number of integer values (the output vector contains values for 0-9) More... | |
Macros | |
| #define | NUMBER_OF_INPUT_CELLS 784 |
| use 28*28 input cells (= number of pixels per MNIST image) More... | |
| #define | NUMBER_OF_OUTPUT_CELLS 10 |
| use 10 output cells to model 10 digits (0-9) More... | |
| #define | LEARNING_RATE 0.05 |
| Incremental increase for changing connection weights. More... | |
Typedefs | |
| typedef struct Cell | Cell |
| typedef struct Layer | Layer |
| typedef struct Vector | Vector |
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... | |
Machine learning functionality for a 1-layer neural network.
Definition in file 1lnn.h.
| #define LEARNING_RATE 0.05 |
| #define NUMBER_OF_INPUT_CELLS 784 |
| #define NUMBER_OF_OUTPUT_CELLS 10 |
| void calcCellOutput | ( | Cell * | c | ) |
| double getCellError | ( | Cell * | c, |
| int | target | ||
| ) |
| int getLayerPrediction | ( | Layer * | l | ) |
| Vector getTargetOutput | ( | int | targetIndex | ) |
| void initLayer | ( | Layer * | l | ) |
Initialize layer by setting all weights to random values [0-1].
| l | A pointer to a NN layer |
Initialize layer by setting all weights to random values [0-1]
| void setCellInput | ( | Cell * | c, |
| MNIST_Image * | img | ||
| ) |
Sets a cell's input according to the pixels of a given MNIST image.
| c | A pointer to a cell |
| img | A pointer to an 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].
| void testCell | ( | Cell * | c, |
| MNIST_Image * | img, | ||
| int | target | ||
| ) |
Performs the testing of the trained network.
| c | Pointer to the cell that is to be trained |
| img | Pointer to the image that is to be processed |
| target | Desired output value |
Performs the testing of the trained network Same as training a cell, but without updating weights (learning)
| void trainCell | ( | Cell * | c, |
| MNIST_Image * | img, | ||
| int | target | ||
| ) |
| void updateCellWeights | ( | Cell * | c, |
| double | err | ||
| ) |
1.8.10