MNIST-3LNN  1.0
A simple 3-layer neural network to recognize handwritten single digit numbers from the MNIST image files.
3lnn.h
Go to the documentation of this file.
1 /**
2  * @file 3lnn.h
3  * @brief Neural network functionality for a 3-layer (INPUT, HIDDEN, OUTPUT) feed-forward, back-prop NN
4  * @author Matt Lind
5  * @date August 2015
6  */
7 
8 
9 
10 
11 
12 typedef struct Network Network;
13 typedef struct Layer Layer;
14 typedef struct Node Node;
15 typedef struct Vector Vector;
16 
19 
20 
21 
22 
23 /**
24  * @brief Dynamic data structure containing defined number of values
25  */
26 
27 struct Vector{
28  int size;
29  double vals[];
30 };
31 
32 
33 
34 
35 /**
36  * @brief Dynamic data structure modeling a neuron with a variable number of connections/weights
37  */
38 
39 struct Node{
40  double bias;
41  double output;
42  int wcount;
43  double weights[];
44 };
45 
46 
47 
48 
49 /**
50  * @brief Dynamic data structure holding a definable number of nodes that form a layer
51  */
52 
53 struct Layer{
54  int ncount;
56 };
57 
58 
59 /**
60  * @brief Dynamic data structure holding the whole network
61  */
62 
63 struct Network{
70  double learningRate; ///< Factor by which connection weight changes are applied
74 };
75 
76 
77 
78 
79 /**
80  * @brief Creates a dynamically-sized, 3-layer (INTPUT, HIDDEN, OUTPUT) neural network
81  * @param inpCount Number of nodes in the INPUT layer
82  * @param hidCount Number of nodes in the HIDDEN layer
83  * @param outCount Number of nodes in the OUTPUT layer
84  */
85 
86 Network *createNetwork(int inpCount, int hidCount, int outCount);
87 
88 
89 
90 
91 /**
92  * @brief Feeds some Vector data into the INPUT layer of the NN
93  * @param nn A pointer to the NN
94  * @param v A pointer to a vector
95  */
96 
97 void feedInput(Network *nn, Vector *v);
98 
99 
100 
101 
102 /**
103  * @brief Feeds input layer values forward to hidden to output layer (calculation and activation fct)
104  * @param nn A pointer to the NN
105  */
106 
107 void feedForwardNetwork(Network *nn);
108 
109 
110 
111 
112 /**
113  * @brief Back propagates network error from output layer to hidden layer
114  * @param nn A pointer to the NN
115  * @param targetClassification Correct classification (=label) of the input stream
116  */
117 
118 void backPropagateNetwork(Network *nn, int targetClassification);
119 
120 
121 
122 
123 /**
124  * @brief Returns the network's classification using the ID of teh node with the hightest output
125  * @param nn A pointer to the NN
126  */
127 
129 
130 
131 
132 
Dynamic data structure containing defined number of values.
Definition: 3lnn.h:27
int inpLayerSize
Definition: 3lnn.h:65
Node nodes[]
Definition: 3lnn.h:55
int hidLayerSize
Definition: 3lnn.h:67
Definition: 3lnn.h:17
int getNetworkClassification(Network *nn)
Returns the network's classification using the ID of teh node with the hightest output.
Definition: 3lnn.c:553
int hidNodeSize
Definition: 3lnn.h:66
ActFctType outLayerActType
Definition: 3lnn.h:72
int outLayerSize
Definition: 3lnn.h:69
Layer layers[]
Definition: 3lnn.h:73
int wcount
Definition: 3lnn.h:42
int outNodeSize
Definition: 3lnn.h:68
Definition: 3lnn.h:18
double output
Definition: 3lnn.h:41
int inpNodeSize
Definition: 3lnn.h:64
double vals[]
Definition: 3lnn.h:29
void backPropagateNetwork(Network *nn, int targetClassification)
Back propagates network error from output layer to hidden layer.
Definition: 3lnn.c:206
double learningRate
Factor by which connection weight changes are applied.
Definition: 3lnn.h:70
Dynamic data structure holding a definable number of nodes that form a layer.
Definition: 3lnn.h:53
LayerType
Definition: 3lnn.h:17
int ncount
Definition: 3lnn.h:54
int size
Definition: 3lnn.h:28
Definition: 3lnn.h:18
void feedInput(Network *nn, Vector *v)
Feeds some Vector data into the INPUT layer of the NN.
Definition: 3lnn.c:320
ActFctType hidLayerActType
Definition: 3lnn.h:71
Network * createNetwork(int inpCount, int hidCount, int outCount)
Creates a dynamically-sized, 3-layer (INTPUT, HIDDEN, OUTPUT) neural network.
Definition: 3lnn.c:505
Definition: 3lnn.h:17
void feedForwardNetwork(Network *nn)
Feeds input layer values forward to hidden to output layer (calculation and activation fct) ...
Definition: 3lnn.c:306
ActFctType
Definition: 3lnn.h:18
double bias
Definition: 3lnn.h:40
Definition: 3lnn.h:17
Dynamic data structure modeling a neuron with a variable number of connections/weights.
Definition: 3lnn.h:39
double weights[]
Definition: 3lnn.h:43
Dynamic data structure holding the whole network.
Definition: 3lnn.h:63