( The Learning Phase of the Neural Network with Backpropagation algorithm within using the P4 Parallel Programming System ( Makefile # P4 makefile for Sun P4ARCH = SUN AR = ar ruv FC = f77 CC= gcc CLINKER = gcc FLINKER = f77 RANLIB = ranlib MDEP_LIBS = -lsocket -lnsl -lthread -lm MDEP_CFLAGS = MDEP_FFLAGS = P4_OBJ = $(P4_COMM_OBJ) $(P4_SOCK_OBJ) $(P4_SHMEM_OBJ) RM = /bin/rm CFLAGS = -g -I$(INCLUDEDIR) $(MDEP_CFLAGS) $(USER_CFLAGS) FFLAGS = -g -I$(FORTLIBDIR) $(MDEP_FFLAGS) .SUFFIXES: .o .c .f .h .c.o:$(P) $(CC) $(CFLAGS) -c $*.c .f.o:$(P) $(FC) $(FFLAGS) -c $*.f dummy: default clean: $(RM) -f *~ *.o *.bak tags TAGS core P4_HOME_DIR = /usr/local/p4-1.4 INCLUDEDIR = $(P4_HOME_DIR)/include LIBDIR = $(P4_HOME_DIR)/lib LIBS = $(LIBDIR)/libp4.a $(MDEP_LIBS) default:$(P) make $(MFLAGS) neu_mas neu_sla all:$(P) make $(MFLAGS) neu_mas neu_sla neu_mas:$(P) neu_mas.o neu_sla.o $(LIBDIR)/libp4.a $(CLINKER) $(CFLAGS) -o neu_mas neu_mas.o $(LIBS) neu_sla:$(P) neu_sla.o $(LIBDIR)/libp4.a $(CLINKER) $(CFLAGS) -o neu_sla neu_sla.o $(LIBS) realclean: clean $(RM) -f p4simple p4test Makefile alogfile.p* ( Process group(procgroup) local 0 bengal 1 /leonine3/users/cyoun/cse762/project/p4/neu_sla panther 1 /leonine3/users/cyoun/cse762/project/p4/neu_sla leopard 1 /leonine3/users/cyoun/cse762/project/p4/neu_sla wildcat 1 /leonine3/users/cyoun/cse762/project/p4/neu_sla leonine 1 /leonine3/users/cyoun/cse762/project/p4/neu_sla ## lion 1 /leonine3/users/cyoun/cse762/project/p4/neu_sla tiger 1 /leonine3/users/cyoun/cse762/project/p4/neu_sla crypt 1 /leonine3/users/cyoun/cse762/project/p4/neu_sla onine 1 /leonine3/users/cyoun/cse762/project/p4/neu_sla amaran 1 /leonine3/users/cyoun/cse762/project/p4/neu_sla apult 1 /leonine3/users/cyoun/cse762/project/p4/neu_sla # amount 1 /leonine3/users/cyoun/cse762/project/p4/neu_sla ( Data file ( changing the number of the nodes) 0 8 0 1 8 16 1 2 16 24 2 3 24 32 3 4 32 40 4 5 40 48 5 6 48 56 6 7 56 64 7 8 64 72 8 9 72 80 9 10 ( Struc.h /* ========================================================================= | Structure of Layers | ========================================================================= */ struct input_layer { int Digit_images [CATEGORY][TYPE][ROW][COLUMN]; float Digit_category [CATEGORY][CATEGORY]; float Digit [ROW][COLUMN]; /* input layer */ } cell_i; struct hidden_layer { float activity [HUNIT]; float threshold [HUNIT]; float iweight [HUNIT][ITUPLE]; float error_back [HUNIT]; float delta [HUNIT]; float delta_bias [HUNIT]; float delta_iweight [HUNIT][ITUPLE]; int in_tuple [HUNIT][ITUPLE]; } cell_h; struct output_layer { float activity [CATEGORY]; float desired_activity [CATEGORY]; float threshold [CATEGORY]; float weight [CATEGORY][HUNIT]; float error [CATEGORY]; float delta [CATEGORY]; float delta_bias [CATEGORY]; float delta_weight [CATEGORY][HUNIT]; float sum_square_error; } cell_o; struct input_layer *INPUT; /* Input layer */ struct hidden_layer *HIDDEN; /* Hidden layer */ struct output_layer *OUTPUT; /* Output layer */ /* ========================================================================= | Functions and Variables | ========================================================================= */ void Read_ntuples(); void Read_Digit_image_category(); void Initialize_networks(); void Target_mapping(); void Back_Propagation_rule(); void Write_ASSE(); FILE *stream1; /* Input file for Digit- images */ FILE *stream2; /* Input file for hunit's weights */ FILE *stream3; /* Input file for hunit's thresholds */ FILE *stream4; /* Input file for ounit's weights */ FILE *stream5; /* Input file for ounit's thresholds */ /* FILE *stream6; */ /* Output file for hunit's weights */ /* FILE *stream7; */ /* Output file for hunit's thresholds */ /* FILE *stream8; */ /* Output file for ounit's weights */ /* FILE *stream9; */ /* Output file for ounit's thresholds */ FILE *stream10; /* Input file for Digit- category */ FILE *stream11; /* Input file for random N-tuples */ FILE *stream12; /* 0 */ FILE *stream13; /* 3 */ FILE *stream14; /* 6 */ FILE *stream15; /* 9 */ ( Master process /****************************************************************************** * * * File "neural_master.c" * * * * Parallel processing of neural network with hand-digit recognition for P4 * * * * Slave program in "neural_slave.c" * * Process Group File "procgroup" * * * ******************************************************************************/ #include #include #include "cortex.h" #include "p4.h" #define DATA -1 /* message type */ #define P4_ROW 10 #define P4_COLUMN 4 #define HIDDEN_UNIT 8 #define OUTPUT_UNIT 1 FILE *stream6; /* Output file for hunit's weights */ FILE *stream7; /* Output file for hunit's thresholds */ FILE *stream8; /* Output file for ounit's weights */ FILE *stream9; /* Output file for ounit's thresholds */ float Output_weight[CATEGORY][HUNIT]; float Output_threshold[CATEGORY]; float Hidden_threshold[HUNIT]; float Hidden_weight[HUNIT][ITUPLE]; int Check_variant(); int Chk_variant [TYPE] = { 100, 100, 100 }; void Storage_of_outputs(); main(argc,argv) int argc; char **argv; { int i; /* Index */ int j; /* Index */ int time = 0; /* Processing step */ int A[P4_ROW][P4_COLUMN]; int nslaves, type, size,to, from, my_id; int send_raw; int input_target; int input_type; int hstart,hindex; long start_time, end_time, elapsed_time; FILE *fpp4; float r1=0., r2=0.; int valid; float *incoming; float Hidden_activity[HUNIT]; float Output_activity[CATEGORY]; float Output_delta[CATEGORY]; start_time = clock(); p4_initenv(&argc,argv); /* P4 environment is initialized */ p4_create_procgroup(); /* Process group is created */ nslaves = p4_num_total_ids() - 1; /* The number of the slave is checked */ printf("Number of Slaves = %d\n",nslaves); my_id = p4_get_my_id(); stream6 = fopen ( "hidden.owt", "w" ); stream7 = fopen ( "hidden.oth", "w" ); stream8 = fopen ( "output.owt", "w" ); stream9 = fopen ( "output.oth", "w" ); /* get input data first */ fpp4 = fopen("data_file", "r"); if (fpp4==NULL) { printf("\n cannot find file "); exit(1); } /* get data */ /* printf("\n\n == DATA == \n"); */ for ( i = 0 ; i < P4_ROW; i++ ) { /* printf("\n"); */ for ( j = 0 ; j < P4_COLUMN; j++ ){ fscanf(fpp4,"%d",&A[i][j]); /* printf("%4d ",A[i][j]); */ } } /* printf("\n\n\n\n"); */ fclose(fpp4); /* data ready */ /* STARTING */ time = 0; type = DATA; size = P4_COLUMN * sizeof(int); for ( to = 1 ; to <= nslaves ; to++ ) { /* printf("Master is sending to processor = 1 %d\n", to); */ send_raw = to - 1; p4_sendr(DATA, to, A[send_raw], size); } do { /* distribute data */ r1 = rand() / 32767.; do { input_target = (int) floor ( (double) CATEGORY * r1 ); } while ( ( 0 > input_target ) || ( input_target >= (int) CATEGORY ) ); size = sizeof(int); for ( to = 1 ; to <= nslaves ; to++ ) { /* printf("Master is sending to processor = 1 %d\n", to); */ p4_sendr(DATA, to, &input_target, size); } /* send part of data */ for ( j = 0; j < TYPE; j++) { do { /* Which digit type ( 0 - 2 ) ? */ r2 = rand() / 32767.; input_type = (int) floor ( (double) TYPE * r2 ); if ( input_type != TYPE ) { valid = Check_variant ( j, input_type ); } else valid == FALSE; } while ( valid == FALSE ); size = sizeof(int); for ( to = 1 ; to <= nslaves ; to++ ) { /* printf("Master is sending to processor = 1 %d\n", to); */ p4_sendr(DATA, to, &input_type, size); } hstart = 0; size = HIDDEN_UNIT * sizeof(float); for( from = 1 ; from <= nslaves ; from++ ) { incoming = NULL; /* printf("Master is receiving from processor = 2 %d\n", from); */ p4_recv(&type, &from, &incoming, &size); for ( hindex = 0; hindex < HIDDEN_UNIT; hindex++) Hidden_activity[hstart++] = incoming[hindex]; p4_msg_free(incoming); } size = HUNIT * sizeof(float); for ( to = 1 ; to <= nslaves ; to++ ) { /* printf("Master is sending to processor = 3 %d\n", to); */ p4_sendr(DATA, to, Hidden_activity, size); } hstart = 0; size = OUTPUT_UNIT * sizeof(float); for( from = 1 ; from <= nslaves ; from++ ) { incoming = NULL; /* printf("Master is receiving from processor = 4 %d\n", from); */ p4_recv(&type, &from, &incoming, &size); for ( hindex = 0; hindex < OUTPUT_UNIT; hindex++) Output_activity[hstart++] = incoming[hindex]; p4_msg_free(incoming); } size = CATEGORY * sizeof(float); for ( to = 1 ; to <= nslaves ; to++ ) { /* printf("Master is sending to processor = 5 %d\n", to); */ p4_sendr(DATA, to, Output_activity, size); } hstart = 0; size = OUTPUT_UNIT * sizeof(float); for( from = 1 ; from <= nslaves ; from++ ) { incoming = NULL; /* printf("Master is receiving from processor = 6 %d\n", from); */ p4_recv(&type, &from, &incoming, &size); for ( hindex = 0; hindex < OUTPUT_UNIT; hindex++) Output_delta[hstart++] = incoming[hindex]; p4_msg_free(incoming); } hstart = 0; size = HUNIT * sizeof(float); for( from = 1 ; from <= nslaves ; from++ ) { /* printf("Master is receiving from processor = 7 %d\n", from); */ for ( i = 0; i < OUTPUT_UNIT; i++) { incoming = NULL; p4_recv(&type, &from, &incoming, &size); for ( hindex = 0; hindex < HUNIT; hindex++) Output_weight[hstart][hindex] = incoming[hindex]; ++hstart; p4_msg_free(incoming); }} size = CATEGORY * sizeof(float); for ( to = 1 ; to <= nslaves ; to++ ) { /* printf("Master is sending to processor = 8 %d\n", to); */ p4_sendr(DATA, to, Output_delta, size); } size = HUNIT * sizeof(float); for ( to = 1 ; to <= nslaves ; to++ ) { /* printf("Master is sending to processor = 9 %d\n", to); */ for ( i = 0; i < CATEGORY; i++) p4_sendr(DATA, to, Output_weight[i], size); } } for (j = 0; j < TYPE; j++) Chk_variant [j] = 100; printf("%d\n", time ); time++; } while ( time <= 0); /* Learning the SCHNN */ hstart = 0; size = HIDDEN_UNIT * sizeof(float); for( from = 1 ; from <= nslaves ; from++ ) { incoming = NULL; /* printf("Master is receiving from processor = 10 %d\n", from); */ p4_recv(&type, &from, &incoming, &size); for ( hindex = 0; hindex < HIDDEN_UNIT; hindex++) Hidden_threshold[hstart++] = incoming[hindex]; p4_msg_free(incoming); } hstart = 0; size = OUTPUT_UNIT * sizeof(float); for( from = 1 ; from <= nslaves ; from++ ) { incoming = NULL; /* printf("Master is receiving from processor = 11 %d\n", from); */ p4_recv(&type, &from, &incoming, &size); for ( hindex = 0; hindex < OUTPUT_UNIT; hindex++) Output_threshold[hstart++] = incoming[hindex]; p4_msg_free(incoming); } hstart = 0; size = ITUPLE * sizeof(float); for( from = 1 ; from <= nslaves ; from++ ) { /* printf("Master is receiving from processor = 12 %d\n", from); */ for ( i = 0; i < HIDDEN_UNIT; i++) { incoming = NULL; p4_recv(&type, &from, &incoming, &size); for ( hindex = 0; hindex < ITUPLE; hindex++) Hidden_weight[hstart][hindex] = incoming[hindex]; ++hstart; p4_msg_free(incoming); }} p4_wait_for_end(); end_time = clock(); elapsed_time = end_time - start_time; printf("\n\n\n"); printf("===================================\n"); printf(" Total Time : %d\n", elapsed_time); printf("===================================\n"); printf("\n\n Master Exiting \n"); /* Write the resulting outputs */ Storage_of_outputs(); /* Close all files and Terminate the process */ exit(0); } /* main */ /* Write the resulting outputs, i.e. Weights and Thresholds */ void Storage_of_outputs() { register int i; register int j; register int k; /* For hidden layer */ for ( i = 0; i < HUNIT; i++) { fprintf ( stream7, "%10.6f", Hidden_threshold [i] ); if ( i == HUNIT - 1 ) { fprintf ( stream7, "\n" ); } for ( k = 0; k < ITUPLE; k++) { fprintf ( stream6, "%10.6f", Hidden_weight [i][k] ); if ( k == ITUPLE - 1 ) fprintf ( stream6, "\n" ); } } /* For output layer */ for ( i = 0; i < CATEGORY; i++) { fprintf ( stream9, "%10.6f", Output_threshold [i] ); if ( i == CATEGORY - 1 ) fprintf ( stream9, "\n" ); for ( k = 0; k < HUNIT; k++) { fprintf ( stream8, "%10.6f", Output_weight [i][k] ); if ( k == HUNIT - 1 ) fprintf ( stream8, "\n" ); } } return; } /* Storage_of_outputs */ /* Check the variants of digit image */ int Check_variant ( jj1, jj ) int jj1, jj; { int i; for ( i = 0; i <= jj1; i++) { if ( Chk_variant [i] == jj ) return ( FALSE ); else; } Chk_variant [jj1] = jj; return ( TRUE ); } /* Check_variant */ ( slave processes /************************************************************************** * * * File "integral_slave.c" * * * * Calculation of integral using rectangular segments for P4 * * * * Master program in "integral_slave.c" * * Process Group File "procgroup" * * * **************************************************************************/ #include #include "p4.h" #include "cortex.h" #include "struc.h" #include #define DATA -1 #define P4_ROW 1 #define P4_COLUMN 4 #define HIDDEN_UNIT 8 #define OUTPUT_UNIT 1 /*-------------------------------------------------------------------*/ int A[P4_ROW][P4_COLUMN]; slave() { int i, j, type, to, from, size, my_id; int k; int l; int m; int n; int s,t; int tuple = 0; int hindex=0, oindex=0; float *incomingf; float wsum_hunit = 0.; float netsum_hunit = 0.; float momentum = 0.9; float learning_rate = 0.1; float wsum_ounit = 0.; float netsum_ounit = 0.; my_id = p4_get_my_id(); /* receive the data from master */ type = DATA; from = 0; /* master process */ to = 0; /* master process */ /* printf("\n slave %d: ",my_id); */ /* Learning the SCHNN */ /* Compute the output activities of hidden units */ m=0; for ( i = A[0][0]; i < A[0][1]; i++) { for ( j = 0; j < ITUPLE; j++) { tuple = HIDDEN->in_tuple [i][j]; k = tuple / COLUMN; l = tuple % COLUMN; wsum_hunit += HIDDEN->iweight [i][j] * INPUT->Digit [k][l]; } netsum_hunit = wsum_hunit + HIDDEN->threshold [i]; HIDDEN->activity[m++] = 1. / ( 1. + exp ( -1. * (double)netsum_hunit ) ); wsum_hunit = 0.0; } size = HIDDEN_UNIT * sizeof(float); p4_sendr(DATA, to, HIDDEN->activity, size); /* printf("\n slave %d: is sending the result hiddenac \n",my_id); */ /* receive the data from master */ size = HUNIT * sizeof(float); incomingf = NULL; p4_recv(&type, &from, &incomingf, &size); for ( j = 0 ; j < HUNIT; j++ ) HIDDEN->activity[j] = incomingf[j]; p4_msg_free(incomingf); /* printf("\n slave %d: is receiving the result hiddenac\n",my_id); */ /* Compute the output activities of output units */ n=0; for ( j = A[0][2]; j < A[0][3]; j++) { for ( k = 0; k < HUNIT; k++) wsum_ounit += OUTPUT->weight [j][k] * HIDDEN->activity [k]; netsum_ounit = wsum_ounit + OUTPUT->threshold [j]; OUTPUT->activity [n++] = 1. / ( 1. + exp ( -1. * (double)netsum_ounit ) ); wsum_ounit = 0.0; } size = OUTPUT_UNIT * sizeof(float); p4_sendr(DATA, to, OUTPUT->activity, size); /* printf("\n slave %d: is sending the result outputac \n",my_id); */ /* receive the data from master */ size = CATEGORY * sizeof(float); incomingf = NULL; p4_recv(&type, &from, &incomingf, &size); for ( j = 0 ; j < CATEGORY; j++ ) OUTPUT->activity[j] = incomingf[j]; p4_msg_free(incomingf); /* printf("\n slave %d: is receiving the result outputac \n",my_id); */ /* Modifying all the weights and thresholds according to EBP rule */ /* For output units */ s = 0; for ( i = A[0][2]; i < A[0][3]; i++) { OUTPUT->error [i] = OUTPUT->desired_activity [i] - OUTPUT->activity [i]; OUTPUT->sum_square_error += OUTPUT->error [i] * OUTPUT->error [i]; OUTPUT->delta [s] = OUTPUT->error [i] * OUTPUT->activity [i] * ( 1.0 - OUTPUT->activity [i]); OUTPUT->delta_bias [i] = learning_rate * OUTPUT->delta [s] + momentum * OUTPUT->delta_bias [i]; OUTPUT->threshold [i] += OUTPUT->delta_bias [i]; for ( k = 0; k < HUNIT; k++) { OUTPUT->delta_weight [i][k] = learning_rate * OUTPUT->delta [s] * HIDDEN->activity [k] + momentum * OUTPUT->delta_weight [i][k]; OUTPUT->weight [i][k] += OUTPUT->delta_weight [i][k]; } ++s; } size = OUTPUT_UNIT * sizeof(float); p4_sendr(DATA, to, OUTPUT->delta, size); /* printf("\n slave %d: is sending the result output del\n",my_id); */ size = HUNIT * sizeof(float); for (i=A[0][2]; i < A[0][3]; i++) p4_sendr(DATA, to, OUTPUT->weight[i],size); /* printf("\n slave %d: is sending the result output weight \n",my_id); */ /* receive the data from master */ size = CATEGORY * sizeof(float); incomingf = NULL; p4_recv(&type, &from, &incomingf, &size); for ( j = 0 ; j < CATEGORY; j++ ) OUTPUT->delta[j] = incomingf[j]; p4_msg_free(incomingf); /* printf("\n slave %d: is receiving the result output delta \n",my_id); */ size = HUNIT * sizeof(float); for ( i = 0; i < CATEGORY; i++) { incomingf = NULL; p4_recv(&type, &from, &incomingf, &size); for ( j = 0 ; j < HUNIT; j++ ) OUTPUT->weight[i][j] = incomingf[j]; p4_msg_free(incomingf); } /* printf("\n slave %d: is receiving the result output weight \n",my_id); */ /* For hidden units */ for ( i = A[0][0]; i < A[0][1]; i++) { HIDDEN->error_back [i] = 0.; } for ( i = A[0][0]; i < A[0][1]; i++) for ( j = 0; j < CATEGORY; j++) { HIDDEN->error_back [i] += OUTPUT->delta [j] * OUTPUT->weight [j][i]; } for ( i = A[0][0]; i < A[0][1]; i++) { HIDDEN->delta [i] = HIDDEN->activity [i] * ( 1.0 - HIDDEN->activity [i] ) * HIDDEN->error_back [i]; HIDDEN->delta_bias [i] = learning_rate * HIDDEN->delta [i] + momentum * HIDDEN->delta_bias [i]; HIDDEN->threshold [i] += HIDDEN->delta_bias [i]; for ( j = 0; j < ITUPLE; j++) { tuple = HIDDEN->in_tuple [i][j]; k = tuple / COLUMN; l = tuple % COLUMN; HIDDEN->delta_iweight [i][j] = learning_rate * HIDDEN->delta [i] * INPUT->Digit [k][l] + momentum * HIDDEN->delta_iweight [i][j]; HIDDEN->iweight [i][j] += HIDDEN->delta_iweight [i][j]; } } } main (argc, argv) int argc; char **argv; { register int i; /* Index */ register int j, j1; /* Index */ register int k; /* Index */ register int l; /* Index */ double r1 = 0., r2 = 0.; /* Random number */ int time = 0; /* Processing step */ int valid; float wsum_ounit = 0.; float netsum_ounit = 0.; float Hidden_th[40]; float Output_th[5]; int type, from, size, to; int *incoming; int i1=0,i2=0; int input_target; int input_type; p4_initenv(&argc,argv); /* P4 environment is initialized */ p4_create_procgroup(); /* Process group is created */ /* Creat and Open files */ stream1 = fopen ( "digit.rf", "r" ); stream2 = fopen ( "hidden.iwt", "r" ); stream3 = fopen ( "hidden.ith", "r" ); stream4 = fopen ( "output.iwt", "r" ); stream5 = fopen ( "output.ith", "r" ); /* stream6 = fopen ( "hidden.owt", "w" ); stream7 = fopen ( "hidden.oth", "w" ); stream8 = fopen ( "output.owt", "w" ); stream9 = fopen ( "output.oth", "w" ); */ stream10 = fopen ( "category.act", "r" ); stream11 = fopen ( "hidden.tpl","r"); stream12 = fopen ( "error.0", "w" ); stream13 = fopen ( "error.3", "w" ); stream14 = fopen ( "error.6", "w" ); if ( ( stream15 = fopen ( "error.9", "w" ) ) == NULL ) exit(1); INPUT = &cell_i; HIDDEN = &cell_h; OUTPUT = &cell_o; /* Read the random n-tuples for hidden layer */ Read_ntuples(); /* Read the Digit images and categories */ Read_Digit_image_category(); /* Initialize the SCHNN */ Initialize_networks(); /* receive the data from master */ type = DATA; from = 0; /* master process */ /* printf("\n slave %d: ",my_id); */ /* receive part of matrix A */ size = P4_COLUMN * sizeof(int); incoming = NULL; p4_recv(&type, &from, &incoming, &size); for ( i = 0 ; i < P4_ROW; i++) for ( j = 0 ; j < P4_COLUMN ; j++ ) A[i][j] = incoming[j]; p4_msg_free(incoming); /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + + Learning SCHNN + + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* STARTING */ time = 0; do { /* What category ( 0 - 9 ) ? */ size = sizeof(int); incoming = NULL; p4_recv(&type, &from, &incoming, &size); input_target = *incoming; p4_msg_free(incoming); /* Mapping Digit's target patterns into output layer */ Target_mapping(input_target); /* Random-orderly training of hand-written digits */ for ( j1 = 0; j1 < TYPE; j1++) { size = sizeof(int); incoming = NULL; p4_recv(&type, &from, &incoming, &size); input_type = *incoming; p4_msg_free(incoming); /* Input token */ for ( k = 0; k < ROW; k++) for ( l = 0; l < COLUMN; l++) { INPUT->Digit[k][l] = (float)INPUT->Digit_images[input_target][input_type][k][l]; } /* Learning the SCHNN */ slave(); } /* Write the average of sum of squared errors and Reset */ Write_ASSE(input_target); /* printf("slave time = %d\n",time); */ time++; } while ( time <= 0); /*Learning the SCHNN */ for(j = A[0][0]; j < A[0][1]; j++) Hidden_th[i1++] = HIDDEN->threshold[j]; for(j = A[0][2]; j < A[0][3]; j++) Output_th[i2++] = OUTPUT->threshold[j]; to = 0; size = HIDDEN_UNIT * sizeof(float); p4_sendr(DATA, to, Hidden_th, size); size = OUTPUT_UNIT * sizeof(float); p4_sendr(DATA, to, Output_th, size); size = ITUPLE * sizeof(float); for (i=A[0][0]; i < A[0][1]; i++) p4_sendr(DATA, to, HIDDEN->iweight[i],size); p4_wait_for_end(); /* Close all files and Terminate the process */ exit(0); } /* main */ /* ========================================================================= | Functions | ========================================================================= */ /* Read the random n-tuples for hidden layer */ void Read_ntuples() { register int i; register int j; /* Read n-tuples */ for ( i = 0; i < HUNIT; i++) { for ( j = 0; j < ITUPLE; j++) { fscanf ( stream11, "%4d", &HIDDEN->in_tuple [i][j] ); } } return; } /* Read_ntuples */ /* Read the Digit images and categories */ void Read_Digit_image_category() { register int i; register int j; register int k; register int l; /* Read Digit-images */ for ( i = 0; i < CATEGORY; i++) for ( j = 0; j < TYPE; j++) for ( k = 0; k < ROW; k++) for ( l = 0; l < COLUMN; l++) { fscanf ( stream1, "%1d", &INPUT->Digit_images [i][j][k][l] ); } /* Read category patterns */ for ( i = 0; i < CATEGORY; i++) for ( j = 0; j < CATEGORY; j++) { fscanf ( stream10, "%10f", &INPUT->Digit_category [i][j] ); } return; } /* Read_Digit_image_category */ /* Initialize the SCHNN */ void Initialize_networks() { register int i; register int j; /* For hidden layer */ for ( i = 0; i < HUNIT; i++) { fscanf ( stream3, "%10f", &HIDDEN->threshold [i] ); for ( j = 0; j < ITUPLE; j++) { fscanf ( stream2, "%10f", &HIDDEN->iweight [i][j] ); } } /* For output layer */ for ( i = 0; i < CATEGORY; i++) { fscanf ( stream5, "%10f", &OUTPUT->threshold [i] ); for ( j = 0; j < HUNIT; j++) { fscanf ( stream4, "%10f", &OUTPUT->weight [i][j] ); } } return; } /* Initialize_networks */ /* Mapping Digit's target pattern into output layer */ void Target_mapping(i1) register int i1; { register int i; /* Index */ for ( i = 0; i < CATEGORY; i++ ) { OUTPUT->desired_activity [i] = INPUT->Digit_category [i1][i]; } return; } /* Target_mapping */ /* Write the average of sum of squared errors and Reset */ void Write_ASSE(i1) int i1; { OUTPUT->sum_square_error /= (float) TYPE; switch ( i1 ) { case 0: fprintf(stream12,"%10.6f\n",OUTPUT->sum_square_error); OUTPUT->sum_square_error = 0.; break; case 1: OUTPUT->sum_square_error = 0.; break; case 2: OUTPUT->sum_square_error = 0.; break; case 3: fprintf(stream13,"%10.6f\n",OUTPUT->sum_square_error); OUTPUT->sum_square_error = 0.; break; case 4: OUTPUT->sum_square_error = 0.; break; case 5: OUTPUT->sum_square_error = 0.; break; case 6: fprintf(stream14,"%10.6f\n",OUTPUT->sum_square_error); OUTPUT->sum_square_error = 0.; break; case 7: OUTPUT->sum_square_error = 0.; break; case 8: OUTPUT->sum_square_error = 0.; break; case 9: fprintf(stream15,"%10.6f\n",OUTPUT->sum_square_error); OUTPUT->sum_square_error = 0.; break; default: printf ("ERROR"); exit(1); } return; } /* Write_ASSE */ /* END */ /* end of slave */ 0