/* A backpropagation simulator. * This is oversimplified version of 2 boolean inputs to 1 boolean output * by asakawa@twcu.ac.jp */ #include #include #include #include /* time.h is required for random number generator */ #include "rand.h" #include "neuron_util.h" #define FROM 0 #define TO 10000 #define ERROR_LIMIT 0.2 /* STRUCTURE of NETWORK */ /* NOTE: you must specify the number of neurons in each layer plus 1 */ /* 0-th neuron will be handled threshold value */ #define N_of_input_layer ( 2 + 1 ) #define N_of_hidden_layer ( 3 + 1 ) #define N_of_output_layer ( 1 + 1 ) neuron input[N_of_input_layer], hidden[N_of_hidden_layer]; neuron output[N_of_output_layer], old_output[N_of_output_layer]; /* Number of patterns to be learned */ #define NPATS 4 /* Each training pattern is stored as {input1,input2, and teacher_signal} */ /* Here's XOR problem, which can not solve perceptron rule */ double example[NPATS][N_of_input_layer -1] = {{0,0}, {0,1}, {1,0}, {1,1}}; double teacher[NPATS][N_of_output_layer-1] = { {0},{1},{1},{0}}; /* The next is AND problem */ /* double teacher[NPATS][N_of_output_layer-1] = { {0},{0},{0},{1}}; */ /* This is OR problem */ /* double teacher[NPATS][N_of_output_layer-1] = { {0},{1},{1},{1}}; */ /* Set values of each input neron */ void set_input(neuron *input, int pat) { int i; input[0].output = 1.0; /* threshold */ for (i=1; i