/* GENERATES A WEIGHTS FILE AND A SAMPLE INPUT FILE FOR TESTING THE MULTI-LAYER PERCEPTRON PROGRAM Author: Robert John Morton YE572246C Decmber 1997 tab = 3 spaces */ #include #define NL 4 //number of layers in the network #define NI 5 //number of input channels to the network #define NR 4 //number of patterns in the input file short // Layer 0 to Layer 1 interconnection weights W10[] = {5691, 2183, 5210, 9031, 2671}, W11[] = {3080, 49, 72, 651, 80}, W12[] = { 99, 26, 8, 77, 7201}, W13[] = {4750, 66, 3, 52, 629}, // Layer 1 to Layer 2 interconnection weights W20[] = { 123, 71, 4, 32}, W21[] = { 367, 921, 626, 747}, W22[] = { 21, 47, 9621, 570}, // Layer 2 to Layer 3 interconnection weights W30[] = { 22, 629, 87}, W31[] = { 921, 57, 12}, // pointer arrays for each layers weights arrays *W1[] = {W10, W11, W12, W13}, *W2[] = {W20, W21, W22}, *W3[] = {W30, W31}, // pointer array for each layer's weights pointer arrays **W[] = {NULL, W1, W2, W3}, // number of neurons in each layer of the network N[] = {5, 4, 3, 2}, L[] = { 2351, 124, 76, 996, 6453, 32755, 3278, 8743, 3971, 4, 9981, 8994, 12359, 25440, 7244, 4410, 29944, 888, 35, 777 }; main() { int nl, i, I; //network layer number short x; FILE *fh = fopen("ROBOT.WTS", "wb"); //open the weights file FILE *ih = fopen("ROBOT.IN", "wb"); //open the inputs file putw(*N, fh); //store the number of network input channels for(nl = 1; nl < NL; nl++) { //for each network layer int nn, NN = *(N + nl); //neuron number short **ppw = *(W + nl); //point to appropriate *Wn[] putw(NN, fh); //store n§ of neurons in layer for(nn = 0; nn < NN; nn++) { //for each neuron in layer int ni, Ni = *(N - 1 + nl); //number of inputs to neuron short *pw = *(ppw + nn); //points to appropriate Wnn[] for(ni = 0; ni < Ni; ni++) //for each input to neuron putw(*(pw + ni), fh); //store the weight } } for(i = 0, I = NI * NR; i < I; i++) //for each input value in the input data putw(*(L + i), ih); //store the test value }