Neural Network Programming Framework
Neural networks consist of layers. The input layer, the output layer and a number of hidden layers between them. Each layer consists of a number of neurons. Each neuron is connected to all neurons of the next and the previous layer. The connections between the neurons contain weights. The files network.c and network.h provide a framework that covers the standard tasks of neural network programming. This includes creation of networks, modifying of all of its parameters, and applying input vectors. The framework supports variable layer sizes but only one hidden layer. The network as well as test and training patterns are stored internally.
Command line parameter parsing
argc.h and argc.c provide basic parameter parsing. The default parameters are parsed by std_opts(). They are either taken from the command line or the .defaults file that resides in the current working directory. The command line parameters take priority over the parameters stored in the .defaults file. Parsed arguments are stored in the variables that were supplied to std_opts().
int std_opts(int argc, char **argv, int *hids, int *epochs, int *lr, int *mm, int *modulo, int *prt_opts,
double *x0, int *l_pats, int *t_pats) Parameters:
• hids – number of neurons in hidden layer
• epochs – number of generations to compute
• lr – learn rate
• mm – momentum
• modulo – print every n-th line
• prt_opts – debugging options
• x0 – start value for connections
• l_pats – number of learning patterns
• t_pats – number of test patterns
Example for command line parameters:
./main hids=2 epochs=100 lr=0.1 mm=0.0 modulo=5 Example for a .defaults file:
x0=10 epochs=400 lr=0.1 hids=2
Neural Network operators
#include “network.h”
int make_nn( int in, int hid, int out, int pat ) Creates a neural network.
in: number of input neurons
hid: number of neurons in the hidden layer out: number of output neurons
pat: number of patterns (train and test) int destroy_nn()
deletes a previously generated neural network.
int init_units( double min_w, double max_w )
Initializes all weights between neurons in a network with random values within min_w and max_w. Also sets the delta of each neuron to 0.
double get_link( int type, int tl, int tu, int fl, int fu )
Returns the weight, the delta, or the previous delta of a link between to neurons.
type: WEIGHT, DELTA, or PDELTA
tl: layer of the destination neuron (IN, HID, or OUT) tu: number of the destination neuron
fl: layer of the source neuron (IN, HID, or OUT) fu: number of the source neuron
int set_link( int type, int tl, int tu, int fl, int fu, double val )
Sets the weight, the delta, or the previous delta of a connection between two neurons.
type: WEIGHT, DELTA, or PDELTA
tl: layer of the destination neuron (IN, HID, or OUT) tu: number of the destination neuron
fl: layer of the source neuron (IN, HID, or OUT) fu: number of the source neuron
val: value
double get_unit( int type, int l, int u )
Retrieves the activation or the error of a neuron.
type: ACT or ERR
l: layer of the neuron (IN, HID, or OUT) u: number of the neuron
int set_unit( int type, int l, int u, double val ) Sets the activation or error of a neuron.
type: ACT or ERR
l: layer of the neuron (IN, HID, or OUT) u: number of the neuron
val: activation or error to be set double get_pattern( int p, int l, int u )
Retrieves the input or output pattern of an input or output neuron.
p: pattern number
l: layer (either IN or OUT) u: number of neuron
int set_pattern( int p, int l, int u, double val ) sets a value in an input or output pattern.
p: pattern number
l: layer (either IN or OUT) u: number of neuron
val: input or output value of the neuron
int set_cpattern( int p, double *iv_p, double *ov_p ) Stores a complete pattern.
p: pattern number
iv_p: array of input values (must have the same size as the input layer) ov_p: array of output values (must have the same size as the output layer)