FANN错误20:ann(4196752)和数据(1)中的输出神经元数量与Epochs不匹配

时间:2016-11-08 23:17:27

标签: c ruby neural-network fann

这是我从FANN网站上获取的一个改进的示例程序。

我创建的等式是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;
}

我创建了自己的数据集

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
...
...

样本数据第一行给出样本数,输入数和最后输出数。

但是我收到了一个错误 FANN Error 20: The number of output neurons in the ann (4196752) and data (1) don't match Epochs

这里的问题是什么?它如何计算4196752神经元?

1 个答案:

答案 0 :(得分:2)

此处,使用fann_create_standard,函数签名为fann_create_standard(num_layers, layer1_size, layer2_size, layer3_size...),而您尝试以不同方式使用它:

struct fann *ann = fann_create_standard(num_layers, num_input,
        num_neurons_hidden, num_output);

构建一个包含4层的网络,但只提供3的数据。输出层中的4196752个神经元可能来自未定义的值。