これは、FANN の Web サイトから取得したサンプル プログラムを少し変更したものです。
私が作成した式は 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;
}
結果.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;
}
独自のデータセットを作成しました
データセット.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
サンプルデータ
100 2 1
95 27
9052
63 9
3978
38 53
1497
31 84
1045
28 56
840
95 80
9105
10 19
...
...
サンプル データの最初の行には、サンプル数、入力数、および最後の出力数が示されます。
しかし、私はエラーが発生しています
FANN Error 20: The number of output neurons in the ann (4196752) and data (1) don't match Epochs
ここで何が問題なのですか?4196752
ニューロンはどのように計算されますか?