forked from libfann/fann
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmushroom.c
74 lines (52 loc) · 2.17 KB
/
mushroom.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
Fast Artificial Neural Network Library (fann)
Copyright (C) 2003-2016 Steffen Nissen ([email protected])
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include "fann.h"
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);
fann_set_activation_function_output(ann, FANN_SIGMOID);
/*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;
}