void testOneEpochTrain(fann *ann, fann_train_data* train, unsigned int trainingAlgorithm, const std::string &header) { printf("TEST: One Epoch %20s ", header.c_str()); bool passed = true; fann *gpunn = fann_copy(ann); fann *cpunn = fann_copy(ann); gpunn->training_algorithm = (fann_train_enum)trainingAlgorithm; cpunn->training_algorithm = (fann_train_enum)trainingAlgorithm; gpuann_fann_train_on_data(gpunn, train, 1); fann_train_epoch(cpunn, train); fann_type *cpuValuesArray = (fann_type *)malloc(cpunn->total_neurons * sizeof(fann_type)); fann_type *gpuValuesArray = (fann_type *)malloc(cpunn->total_neurons * sizeof(fann_type)); fann *tmpnn = cpunn; struct fann_neuron * last_neuron = (tmpnn->last_layer - 1)->last_neuron; fann_neuron *neuronsArray = tmpnn->first_layer->first_neuron; struct fann_neuron * neuron_it = tmpnn->first_layer->first_neuron; for(; neuron_it != last_neuron; neuron_it++) { unsigned int currentNeuronShift = neuron_it - neuronsArray; cpuValuesArray[currentNeuronShift] = neuron_it->value; } tmpnn = gpunn; last_neuron = (tmpnn->last_layer - 1)->last_neuron; neuronsArray = tmpnn->first_layer->first_neuron; neuron_it = tmpnn->first_layer->first_neuron; for(; neuron_it != last_neuron; neuron_it++) { unsigned int currentNeuronShift = neuron_it - neuronsArray; gpuValuesArray[currentNeuronShift] = neuron_it->value; } passed &= isAlmostSameArrays(gpuValuesArray, cpuValuesArray, cpunn->total_neurons, true, "VALUES:"); passed &= isAlmostSameArrays(gpunn->weights, cpunn->weights, cpunn->total_connections, true, "WEIGHTS:"); fann_destroy(gpunn); fann_destroy(cpunn); if(passed) printf("PASSED\n"); else printf("FAILED\n"); }
int main() { //unsigned int layers[] = {17, 500, 400, 300, 200, 1}; //unsigned int layerCount = sizeof(layers) / sizeof(unsigned int); const char* netLoadFile = "data/AAPL_ADBE_ATVI_COKE_EBAY_EXPE_NFLX_VA.300.250.200_100.net"; const char* netSaveFile = "data/AAPL_ADBE_ATVI_COKE_EBAY_EXPE_NFLX_VA.300.250.200_200.net"; const float desired_error = (const float) 0.10; const unsigned int max_epochs = 100; const unsigned int epochs_between_reports = 1; //struct fann *ann = fann_create_standard_array(layerCount, layers); struct fann *ann = fann_create_from_file(netLoadFile); fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC); fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC); printf("%s\n", netSaveFile); fann_train_on_file(ann, "data/AAPL_ADBE_ATVI_COKE_EBAY_EXPE_NFLX_VA.train.fann", max_epochs, epochs_between_reports, desired_error); fann_save(ann, netSaveFile); fann_destroy(ann); printf("%s\n", netSaveFile); return 0; }
int main() { const unsigned int num_input = 1; const unsigned int num_output = 1; const unsigned int num_layers = 3; const unsigned int num_neurons_hidden = 10; const float desired_error = (const float) 0.0003; const unsigned int max_epochs = 50000; const unsigned int epochs_between_reports = 1000; struct fann_train_data *train_data; 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); train_data=fann_read_train_from_file("seno.data"); //AQUI //fann_set_scaling_params(ann,train_data,-1.0,1.0,-1.0,1.0); //fann_scale_train(ann,train_data); //fann_scale_train_data(train_data,-1,1); fann_train_on_data(ann, train_data, max_epochs, epochs_between_reports, desired_error); fann_save(ann, "mlp2.net"); fann_destroy(ann); return 0; }
int main() { fann_type *calc_out; const unsigned int num_input = 2; const unsigned int num_output = 1; const unsigned int num_layers = 3; const unsigned int num_neurons_hidden = 9; const float desired_error = (const float) 0; const unsigned int max_epochs = 500000; const unsigned int epochs_between_reports = 1000; struct fann *ann; struct fann_train_data *data; unsigned int i = 0; unsigned int decimal_point; printf("Creating network.\n"); ann = fann_create_standard(num_layers, num_input, num_neurons_hidden, num_output); data = fann_read_train_from_file("osyslec_train.data"); fann_set_activation_steepness_hidden(ann, 1); fann_set_activation_steepness_output(ann, 1); fann_set_activation_function_hidden(ann, FANN_SIGMOID); fann_set_activation_function_output(ann, FANN_SIGMOID); fann_set_train_stop_function(ann, FANN_STOPFUNC_BIT); fann_set_bit_fail_limit(ann, 0.01f); fann_set_training_algorithm(ann, FANN_TRAIN_RPROP); fann_init_weights(ann, data); printf("Training network.\n"); fann_train_on_data(ann, data, max_epochs, epochs_between_reports, desired_error); printf("Testing network. %f\n", fann_test_data(ann, data)); for(i = 0; i < fann_length_train_data(data); i++) { calc_out = fann_run(ann, data->input[i]); printf("GG test (%f,%f) -> %f, should be %f, difference=%f\n", data->input[i][0], data->input[i][1], calc_out[0], data->output[i][0], fann_abs(calc_out[0] - data->output[i][0])); } printf("Saving network.\n"); fann_save(ann, "osyslec_train_float.net"); decimal_point = fann_save_to_fixed(ann, "osyslec_train_fixed.net"); fann_save_train_to_fixed(data, "osyslec_train_fixed.data", decimal_point); printf("Cleaning up.\n"); fann_destroy_train(data); fann_destroy(ann); return 0; }
int main() { printf("Neural Network training\n"); const unsigned int num_input = 3; const unsigned int num_output = 4; const unsigned int num_layers = 4; const unsigned int num_neurons_hidden = 30; const float desired_error = (const float) 0.02; const unsigned int max_epochs = 500000; const unsigned int epochs_between_reports = 10; struct fann *ann = fann_create_standard( num_layers, num_input, num_neurons_hidden, num_neurons_hidden, // num_neurons_hidden, num_output); fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC); fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC); // fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC); fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC); struct fann_train_data *data = fann_read_train_from_file("../training.data"); fann_train_on_data(ann, data, max_epochs, epochs_between_reports, desired_error); fann_destroy_train(data); fann_save(ann, "../neural.net"); fann_destroy(ann); return 0; }
int main(int argc, char **argv) { const unsigned int num_input = 360; const unsigned int num_output = 1; const unsigned int num_layers = 4; const unsigned int num_neurons_hidden = num_input / 2; const float desired_error = (const float) 0.001; const unsigned int max_epochs = 300; const unsigned int epochs_between_reports = 10; struct fann_train_data * data = NULL; struct fann *ann = fann_create_standard(num_layers, num_input, num_neurons_hidden, num_neurons_hidden / 2, num_output); unsigned int i, j; if (argc != 2) { fprintf(stderr, "Use: %s arquivoTreino\n", argv[0]); exit(1); } fann_set_activation_function_hidden(ann, FANN_ELLIOT); fann_set_activation_function_output(ann, FANN_LINEAR); fann_set_training_algorithm(ann, FANN_TRAIN_RPROP); fann_set_learning_rate(ann, 0.1); fann_set_learning_momentum(ann, 0.6); data = fann_read_train_from_file(argv[1]); fann_train_on_data(ann, data, max_epochs, epochs_between_reports, desired_error); free(data); fann_save(ann, ARQ_RNA); fann_destroy(ann); return 0; }
int main() { fann_type *calc_out; fann_type input[2]; struct fann *ann = fann_create_from_file("and_float.net"); input[0] = 0; input[1] = 0; calc_out = fann_run(ann, input); printf("AND test (%f,%f) -> %f\n", input[0], input[1], calc_out[0]); input[0] = 1; input[1] = 0; calc_out = fann_run(ann, input); printf("AND test (%f,%f) -> %f\n", input[0], input[1], calc_out[0]); input[0] = 0; input[1] = 1; calc_out = fann_run(ann, input); printf("AND test (%f,%f) -> %f\n", input[0], input[1], calc_out[0]); input[0] = 1; input[1] = 1; calc_out = fann_run(ann, input); printf("AND test (%f,%f) -> %f\n", input[0], input[1], calc_out[0]); fann_destroy(ann); return 0; }
int sci_fann_destroy(char * fname) { int res; struct fann * result_fann = NULL; if (Rhs!=1) { Scierror(999,"%s usage: %s(ann_in)", fname, fname); return 0; } res = detect_fannlist(1); if (res==-1) return 0; result_fann = createCFannStructFromScilabFannStruct(1,&res); if (res==-1) return 0; if (result_fann==NULL) { Scierror(999,"%s: Problem while creating the fann scilab structure\n",fname); return 0; } fann_destroy(result_fann); return 0; }
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; 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, "xor.data", max_epochs, epochs_between_reports, desired_error); fann_save(ann, "xor_float.net"); fann_destroy(ann); return 0; }
int main( int argc, char** argv ) { fann_type *calc_out; unsigned int i; int ret = 0; struct fann *ann; struct fann_train_data *data; printf("Creating network.\n"); ann = fann_create_from_file("xor_float.net"); if(!ann) { printf("Error creating ann --- ABORTING.\n"); return 0; } fann_print_connections(ann); fann_print_parameters(ann); printf("Testing network.\n"); data = fann_read_train_from_file("5K.txt"); for(i = 0; i < fann_length_train_data(data); i++) { fann_reset_MSE(ann); fann_scale_input( ann, data->input[i] ); calc_out = fann_run( ann, data->input[i] ); fann_descale_output( ann, calc_out ); printf("Result %f original %f error %f\n", calc_out[0], data->output[i][0], (float) fann_abs(calc_out[0] - data->output[i][0])); } printf("Cleaning up.\n"); fann_destroy_train(data); fann_destroy(ann); return ret; }
void MainWindow::onLearnMyocardial() { QString trainFileName = QFileDialog::getOpenFileName(this, tr("Open training file"), "", tr("Training file (*.data)")); if(trainFileName.isEmpty()) return; if(mAnn != 0) fann_destroy(mAnn); const unsigned int num_input = 3; const unsigned int num_output = 1; const unsigned int num_layers = 3; const unsigned int num_neurons_hidden = 5; const float desired_error = 0.001f; const unsigned int max_epochs = 50000; const unsigned int epochs_between_reports = 0; mAnn= fann_create_standard(num_layers, num_input, num_neurons_hidden, num_output); fann_set_activation_function_hidden(mAnn, FANN_SIGMOID_SYMMETRIC); fann_set_activation_function_output(mAnn, FANN_SIGMOID_SYMMETRIC); QByteArray ba = trainFileName.toLocal8Bit(); fann_train_on_file(mAnn, ba.data(), max_epochs, epochs_between_reports, desired_error); QMessageBox::information(this, "Training Complete", QString("Training error = ") + QString::number(fann_get_MSE(mAnn))); ui->tabWidget->setTabEnabled(1, true); }
int main(int argc , char **argv) { unsigned int num_data; unsigned int num_input; unsigned int num_output; const unsigned int num_layers=3 ; //input, hidden and output unsigned int num_neurons_hidden; const float desired_error = 0.0001; const unsigned int max_iterations = 1000; const unsigned int iterations_between_reports = 5; if (argc != 5) { printf("usage : train trainFile.txt testFile.txt ouputNetBasename nbrHiddenNeurons\n"); return 0; } FILE *in= fopen(argv[1],"r"); fscanf(in,"%d %d %d\n",&num_data,&num_input,&num_output); fclose(in); num_neurons_hidden = (unsigned int) atoi (argv[4]); 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); train(ann, argv[1],argv[2],argv[3], max_iterations,iterations_between_reports, desired_error,num_neurons_hidden); fann_destroy(ann); return 0; }
int main( int argc, char** argv ) { const unsigned int num_input = 3; const unsigned int num_output = 1; const unsigned int num_layers = 4; const unsigned int num_neurons_hidden = 5; const float desired_error = (const float) 0.0001; const unsigned int max_epochs = 5000; const unsigned int epochs_between_reports = 1000; struct fann_train_data * data = NULL; struct fann *ann = fann_create_standard(num_layers, num_input, num_neurons_hidden, num_neurons_hidden, num_output); fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC); fann_set_activation_function_output(ann, FANN_LINEAR); fann_set_training_algorithm(ann, FANN_TRAIN_RPROP); data = fann_read_train_from_file("../../datasets/scaling.data"); fann_set_scaling_params( ann, data, -1, /* New input minimum */ 1, /* New input maximum */ -1, /* New output minimum */ 1); /* New output maximum */ fann_scale_train( ann, data ); fann_train_on_data(ann, data, max_epochs, epochs_between_reports, desired_error); fann_destroy_train( data ); fann_save(ann, "scaling.net"); fann_destroy(ann); return 0; }
void trainMethodsSpeedTestGPU(fann *ann, fann_train_data* train, unsigned int trainingAlgorithm, unsigned int epochCount) { fann *gpunn = fann_copy(ann); gpunn->training_algorithm = (fann_train_enum)trainingAlgorithm; { cudaEvent_t start, stop; float time; cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventRecord(start, 0); gpuann_fann_parallel_train_on_data(gpunn, train, epochCount); cudaEventRecord(stop, 0); cudaEventSynchronize(stop); cudaEventElapsedTime(&time, start, stop); cudaEventDestroy(start); cudaEventDestroy(stop); printf("%10.5f ", time); } fann_destroy(gpunn); }
void cunit_simple_test(void) { fann_type *calc_out; fann_type input[2]; struct fann *ann = fann_create_from_file("xor_float.net"); CU_ASSERT_PTR_NOT_NULL_FATAL(ann); input[0] = 1; input[1] = 1; calc_out = fann_run(ann, input); CU_ASSERT(IS_NEG(calc_out[0])); input[0] = -1; input[1] = 1; calc_out = fann_run(ann, input); CU_ASSERT(IS_POS(calc_out[0])); input[0] = 1; input[1] = -1; calc_out = fann_run(ann, input); CU_ASSERT(IS_POS(calc_out[0])); input[0] = 1; input[1] = 1; calc_out = fann_run(ann, input); CU_ASSERT(IS_NEG(calc_out[0])); fann_destroy(ann); }
int main(int argc, const char* argv[]) { const unsigned int max_epochs = 1000; unsigned int num_threads = 1; struct fann_train_data *data; struct fann *ann; long before; float error; unsigned int i; if(argc == 2) num_threads = atoi(argv[1]); data = fann_read_train_from_file("../../datasets/mushroom.train"); ann = fann_create_standard(3, fann_num_input_train_data(data), 32, fann_num_output_train_data(data)); fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC); fann_set_activation_function_output(ann, FANN_SIGMOID); before = GetTickCount(); for(i = 1; i <= max_epochs; i++) { error = num_threads > 1 ? fann_train_epoch_irpropm_parallel(ann, data, num_threads) : fann_train_epoch(ann, data); printf("Epochs %8d. Current error: %.10f\n", i, error); } printf("ticks %d", GetTickCount()-before); fann_destroy(ann); fann_destroy_train(data); return 0; }
int main() { int i, j, k,temp, num_test, num_input; fann_type *calc_out; fann_type input[NUM_INPUT]; FILE *in = fopen("test.data", "r"); fscanf(in, "%d", &num_test); printf("%d\n", num_test); //skip_space_newline(in); fscanf(in, "%d", &num_input); printf("%d\n", num_input); struct fann *ann = fann_create_from_file("ann.net"); for(i=0; i<num_test; i++){ for(j=0; j<num_input; j++){ fscanf(in, "%d", &temp); input[j] = temp; } calc_out = fann_run(ann, input); for(k=0; k<NUM_OUTPUT; k++){ printf("%f ", calc_out[k]); } printf("\n"); } //input[0] = -1; //input[1] = 1; //calc_out = fann_run(ann, input); //printf("xor test (%f,%f) -> %f\n", input[0], input[1], calc_out[0]); //for(i=0; i<NUM_OUTPUT; i++){ // printf("%f\n", calc_out[i]); //} fann_destroy(ann); return 0; }
int main() { struct fann *ann = fann_create(1,0.7,5,72,60,30,10,3); fann_train_on_file(ann, "training.data",200,10,0.1); fann_save(ann, "gesture_classify.net"); fann_destroy(ann); return 0; }
int main( int argc, char* argv[]) { const char * netfilename = argv[1]; const char * datfilename = argv[2]; const char * resfilename = argv[3]; FILE* fp_data; fp_data = fopen (datfilename,"r"); int i; int s; fann_type *calc_out; fann_type input[16]; //float ainput[16]; char* cinput[16]; struct fann *ann = fann_create_from_file( netfilename ); char line [400]; char flc [400]; FILE* fp_out; fp_out = fopen ( resfilename , "w"); while(fgets(line, 400, fp_data) != NULL) { line[strcspn(line, "\r\n")] = 0; snprintf(flc,sizeof(flc),"%s",line); // Read in line of input values cinput[0] = strtok(flc," "); input[0] = atof(cinput[0]); for (i=1; i<16; ++i) { cinput[i] = strtok(NULL," "); input[i] = atof(cinput[i]); } // run input through network calc_out = fann_run(ann, input); // Write to output file for (i=0; i<6; i++) { fprintf(fp_out,"%f ",calc_out[i]); } fprintf(fp_out,"\n"); } fclose(fp_data); fclose(fp_out); fann_destroy(ann); return 0; }
TwoAnn::~TwoAnn() { fann_destroy(ann1_); fann_destroy(ann2_); fann_destroy(ann3_); fann_destroy(ann4_); fann_destroy(ann5_); fann_destroy(ann6_); fann_destroy(ann7_); fann_destroy(ann8_); fann_destroy(annChairman_); delete data_; }
OcrNet::~OcrNet() { for(int i=0; i < DataSetSize; i++) { fann_destroy(Ann[i]); } delete [] Ann; }
int main() { //FANN TRAINING: const unsigned int num_input = 4; const unsigned int num_output = 3; const unsigned int num_layers = 3; const unsigned int num_neurons_hidden = 4; const float desired_error = (const float) 0.001; const unsigned int max_epochs = 200000; const unsigned int epochs_between_reports = 1000; 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, "irisDataSet.data", max_epochs, epochs_between_reports, desired_error); fann_save(ann, "irisFANN_float.net"); fann_destroy(ann); //FANN TESTING fann_type *calc_out; fann_type input[4]; struct fann *annR = fann_create_from_file("irisFANN_float.net"); input[0] = 5.1; input[1] = 3.5; input[2] = 1.4; input[3] = 0.2; calc_out = fann_run(annR, input); std::cout << "Testing irisFANN, with data: " << input[0] << ", " << input[1] << ", " << input[2] << ", " << input[3] << ", " << ", output: " << calc_out[0] << ", " << calc_out[1] << ", " << calc_out[2] << "\n"; fann_destroy(annR); return 0; }
void Classifier::createNew() { fann_destroy(neuralNetwork); neuralNetwork = fann_create_standard(NUM_LAYERS, NUM_INP, numHidden, NUM_OUTP); //fann_set_activation_function_hidden(neuralNetwork, FANN_SIGMOID_SYMMETRIC); //fann_set_activation_function_output(neuralNetwork, FANN_SIGMOID_SYMMETRIC); fann_set_activation_function_hidden(neuralNetwork, FANN_LINEAR_PIECE_SYMMETRIC); fann_set_activation_function_output(neuralNetwork, FANN_LINEAR_PIECE_SYMMETRIC); fann_set_training_algorithm(neuralNetwork,FANN_TRAIN_INCREMENTAL); }
int main(int argc, char *argv[]) { unsigned int layers[3] = {38, 17, 9}; struct fann *ann = fann_create_standard_array(3, layers); fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC); fann_set_activation_function_output(ann, FANN_LINEAR); fann_train_on_file(ann, "scotland.data", 100000, 100, 0.00001); fann_save(ann, "scotland_test.net"); fann_destroy(ann); return 0; }
void cunit_xor_test(void) { fann_type *calc_out = NULL; unsigned int i; int ret = 0; struct fann *ann = NULL; struct fann_train_data *data = NULL; #ifdef FIXEDFANN ann = fann_create_from_file("xor_fixed.net"); #else ann = fann_create_from_file("xor_float.net"); #endif CU_ASSERT_PTR_NOT_NULL_FATAL(ann); #ifdef FIXEDFANN data = fann_read_train_from_file("xor_fixed.data"); #else data = fann_read_train_from_file("xor.data"); #endif CU_ASSERT_PTR_NOT_NULL_FATAL(data); for(i = 0; i < fann_length_train_data(data); i++) { fann_reset_MSE(ann); calc_out = fann_test(ann, data->input[i], data->output[i]); CU_ASSERT_PTR_NOT_NULL_FATAL(calc_out); #ifdef FIXEDFANN /*printf("XOR test (%d, %d) -> %d, should be %d, difference=%f\n", data->input[i][0], data->input[i][1], calc_out[0], data->output[i][0], (float) fann_abs(calc_out[0] - data->output[i][0]) / fann_get_multiplier(ann));*/ if((float) fann_abs(calc_out[0] - data->output[i][0]) / fann_get_multiplier(ann) > 0.2) { CU_FAIL("XOR test failed."); ret = -1; } #else /*printf("XOR test (%f, %f) -> %f, should be %f, difference=%f\n", data->input[i][0], data->input[i][1], calc_out[0], data->output[i][0], (float) fann_abs(calc_out[0] - data->output[i][0]));*/ #endif } fann_destroy_train(data); fann_destroy(ann); }
bool runTest(struct fann *ann, fann_type * input) { fann_type *calc_out_c; fann_type *calc_out_g; fann_type calc_out_gpu, calc_out_cpu; fann *gpunn = fann_copy(ann); fann *cpunn = fann_copy(ann); calc_out_g = gpuann_fann_run(gpunn, input); calc_out_c = fann_run(cpunn, input); calc_out_gpu = calc_out_g[0]; calc_out_cpu = calc_out_c[0]; bool success = (calc_out_cpu - calc_out_gpu) * (calc_out_cpu - calc_out_gpu) < 0.001; fann_destroy(cpunn); fann_destroy(gpunn); return success; }
Classifier &Classifier::operator=(const Classifier &o) { if(neuralNetwork != o.neuralNetwork) { numHidden = o.numHidden; maxEpochs = o.maxEpochs; reqError = o.reqError; printEpochs = o.printEpochs; if(neuralNetwork) { fann_destroy(neuralNetwork); } neuralNetwork = fann_copy(o.neuralNetwork); } return *this; }
int main() { const unsigned int num_layers = 3; const unsigned int num_neurons_hidden = 32; const float desired_error = (const float) 0.0001; const unsigned int max_epochs = 300; const unsigned int epochs_between_reports = 10; struct fann *ann; struct fann_train_data *train_data, *test_data; unsigned int i = 0; printf("Creating network.\n"); train_data = fann_read_train_from_file("../datasets/mushroom.train"); ann = fann_create_standard(num_layers, train_data->num_input, num_neurons_hidden, train_data->num_output); printf("Training network.\n"); fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC_STEPWISE); fann_set_activation_function_output(ann, FANN_SIGMOID_STEPWISE); /*fann_set_training_algorithm(ann, FANN_TRAIN_INCREMENTAL); */ fann_train_on_data(ann, train_data, max_epochs, epochs_between_reports, desired_error); printf("Testing network.\n"); test_data = fann_read_train_from_file("../datasets/mushroom.test"); fann_reset_MSE(ann); for(i = 0; i < fann_length_train_data(test_data); i++) { fann_test(ann, test_data->input[i], test_data->output[i]); } printf("MSE error on test data: %f\n", fann_get_MSE(ann)); printf("Saving network.\n"); fann_save(ann, "mushroom_float.net"); printf("Cleaning up.\n"); fann_destroy_train(train_data); fann_destroy_train(test_data); fann_destroy(ann); return 0; }
int main(int argc, char **argv) { fann_type *calc_out; unsigned int i, j; struct fann *ann; struct fann_train_data *data; float error = 0.0; if (argc < 3) { fprintf(stderr, "Use: %s FANN_network.net patternsFile\n", argv[0]); exit(1); } printf("Openning ANN `%s'\n", argv[1]); ann = fann_create_from_file(argv[1]); if (!ann) { fprintf(stderr, "Error creating the ANN.\n"); return (1); } printf("Running ANN.\n"); data = fann_read_train_from_file(argv[2]); for(i = 0; i < fann_length_train_data(data); i++) { calc_out = fann_run(ann, data->input[i]); printf("ANN: %f ", calc_out[0]); printf("Expected: %f ", data->output[i][0]); printf("Error: %f ", (float) (data->output[i][0] -calc_out[0])); printf("Throttle_Effort: %f Brake_Effort: %f Current_Velocity: %f\n", // essa multiplicacao ocorre para desfazer o que o 'gerarEntrada.c' fez data->input[i][360-3]*100.0, data->input[i][360-2]*100.0, data->input[i][360-1]*5.0); error += (float) powf(fann_abs(calc_out[0] - data->output[i][0]),2); } printf("Test:: Squared Error: %f Mean Squared Error: %f\n", error, error/(fann_length_train_data(data)-1)); printf("Cleaning memory.\n"); fann_destroy_train(data); fann_destroy(ann); return (0); }
int main( void ) { fann_type *calc_out; fann_type input[ N ]; int i; struct fann *ann = fann_create_standard( 3, N, N, 1 ); fann_set_activation_function_hidden( ann, ACT ); fann_set_activation_function_output( ann, FANN_LINEAR ); for( i=0; i<1000; i++ ) calc_out = fann_run(ann, input); fann_destroy(ann); return 0; }