/********* * from http://leenissen.dk/fann/html/files2/gettingstarted-txt.html * * On cs, compile and run with * $ export LD_LIBRARY_PATH=/usr/local/lib * $ gcc -O2 -march=athlon64 -lfann -lm train_xor.c -o train_xor * $ ./train_xor * * The format of the input file (xor.data here) is : * * n_input_output_pairs numbers_per_input numbers_per_output * in_1_number1 in1_number2 ... * out_1_number1 out_1_number2 ... * in_2_number1 in_2_number2 ... * out_2_number1 ... * ... * in_n_number1 ... * out_n_number1 ... * * *****************/ #include "fann.h" int main(){ const unsigned int num_input = 2; const unsigned int num_output = 1; const unsigned int num_layers = 3; const unsigned int num_neurons_hidden = 3; const float desired_error = (const float) 0.001; const unsigned int max_epochs = 500000; const unsigned int epochs_between_reports = 1000; char* input_data_file = "xor.data"; char* output_network_file = "xor.net"; struct fann *ann = fann_create_standard(num_layers, num_input, num_neurons_hidden, num_output); fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC); fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC); fann_train_on_file(ann, input_data_file, max_epochs, epochs_between_reports, desired_error); fann_save(ann, output_network_file); fann_destroy(ann); return 0; }