/* adaline.c Dwayne Phillips February 1992 The functions in this file implement the adaptive linear element - Adaline - and the alpha-LMS learning law. Contents: calculate_net calculate_output display_inputs display_weights get_straight_input_from_user get_straight_input_vectors get_target_from_user initialize_weights process_new_case train_the_adaline train_weights */ #include /* long get_straight_input_vectors(inputs, x, N) This function gets an input vector from the user via interaction using the screen and the keyboard. */ long get_straight_input_vectors(inputs, x, N) FILE *inputs; long x[], N; { char string[80]; int i, s; long target; printf("\nEnter number of input vectors >>"); gets(string); s = atoi(string); for(i=0; i>", i); gets(string); a = atoi(string); x[i] = a; } } /* ends get_straight_input_from_user */ /* long get_target_from_user() This function gets a long from the user via the screen and keyboard. */ get_target_from_user() { char string[80]; long s; printf("\nEnter the target >>"); gets(string); s = atoi(string); return(s); } /* ends get_target_from_user */ /* void display_weights(w, N) This function displays the weight vector on the screen. */ display_weights(w, N) long w[], N; { int i; for(i=0; i>"); gets(string); s = atoi(string); while(adjusting){ counter++; adjusting = 0; fseek(inputs, 0L, SEEK_SET); for(i=0; i 20){ printf("\n\nTOO MUCH TRAINING - quiting"); adjusting = 0; } } /* ends while adjusting */ printf("\n\nwent through the training cycle %d times",counter); fclose(inputs); fwrite(w, (N+1)*sizeof(long), 1, weights); fclose(weights); } /* ends train_the_adaline */ /* void initialize_weights(w, N) This function initializes the members of the weights vector w. Set the to 0 10 20 30 0 ... */ initialize_weights(w, N) long w[], N; { int i; for(i=0; i= 0 output = 0 if net < 0 */ calculate_output(net) long net; { long result = 1; if(net < 0) result = -1; return(result); } /* ends calculate_output */ /* long train_weights(target, net, eta, w, x, N) This function adjusts the weights in the weight vector w. It uses the alpha LMS algorithm. */ train_weights(target, net, eta, w, x, N) long target, net, w[], x[], N; float eta; { long delta_w, i; for(i=0; i