Reputation: 5859
This is a litle modified sample program I took from FANN website.
The equation I created is c = pow(a,2) + b.
Train.c
#include "fann.h"
int main()
{
const unsigned int num_input = 2;
const unsigned int num_output = 1;
const unsigned int num_layers = 4;
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, "sample.data", max_epochs,
epochs_between_reports, desired_error);
fann_save(ann, "sample.net");
fann_destroy(ann);
return 0;
}
Result.c
#include <stdio.h>
#include "floatfann.h"
int main()
{
fann_type *calc_out;
fann_type input[2];
struct fann *ann = fann_create_from_file("sample.net");
input[0] = 1;
input[1] = 1;
calc_out = fann_run(ann, input);
printf("sample test (%f,%f) -> %f\n", input[0], input[1], calc_out[0]);
fann_destroy(ann);
return 0;
}
I created my own dataset
dataset.rb
f= File.open("sample.data","w")
f.write("100 2 1\n")
i=0
while i<100 do
first = rand(0..100)
second = rand(0..100)
third = first ** 2 + second
string1 = "#{first} #{second}\n"
string2 = "#{third}\n"
f.write(string1)
f.write(string2)
i=i+1
end
f.close
sample.data
100 2 1
95 27
9052
63 9
3978
38 53
1497
31 84
1045
28 56
840
95 80
9105
10 19
...
...
sample data first line gives number of samples, number of inputs and last number of outputs.
But I am getting an error
FANN Error 20: The number of output neurons in the ann (4196752) and data (1) don't match Epochs
What's the issue here? How does it calculate 4196752
neurons?
Upvotes: 0
Views: 402
Reputation: 27207
Here, using fann_create_standard, the function signature is fann_create_standard(num_layers, layer1_size, layer2_size, layer3_size...)
, whilst you are trying to use it differently:
struct fann *ann = fann_create_standard(num_layers, num_input,
num_neurons_hidden, num_output);
you construct a network with 4 layers, but only provide data for 3. The 4196752 neurons in the output layer are likely coming from an undefined value.
Upvotes: 3