gpt4 book ai didi

c++ - 使用 FANN 库

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:33:04 24 4
gpt4 key购买 nike

我一直在试验 FANN库,它似乎是一个很棒的神经网络库,但我在如何使用它方面遇到了一些问题。

所以我在这里尝试做的是训练一个神经网络,为了弄乱库,给它一个输入并期望一个输出。

FANN::neural_net nn;
const float desired_error = 0.00001;
const unsigned int max_epochs = 500000;
const unsigned int epochs_between_reports = 1000;
const unsigned int layers_count = 3;
const unsigned int layers[layers_count] = {7, 5, 1};
nn.create_standard_array(layers_count, layers);
nn.train_on_file(TRAINING_DATA, max_epochs, epochs_between_reports, desired_error);

这是我的训练数据文件 (TRAINING_DATA) 的第一行:

16969 7 1
0.0812069 0.0812069 0.381578 0.0812069 5.8931e-05 0.0843302 0.606695
1
0.429961 0.0509753 0.381578 0.0266957 0.000117862 0.00707172 0.0221581
1
0.0983558 0.486888 0.381578 0.000117862 0.0266957 0.00701279 0.0539808
1
0.0983558 0.486888 0.598562 0.0161471 0.0161471 0.000471448 0.00135541
1

可以找到完整数据集here

使用训练数据文件中的示例数据,我应该得到与之匹配的输出,对吗?但是,如果我执行以下操作,我会得到 0 作为输出...

fann_type i[7], *o;
i[0] = 0.429961; i[1] = 0.0509753; i[2] = 0.381578; i[3] = 0.0266957; i[4] = 0.000117862; i[5] = 0.00707172; i[6] = 0.0221581;
o = nn.run(i);
std::cout << "output (run) is " << o[0] << std::endl;

有人能真正向我解释这里发生了什么吗?

我用的是2.2.0版本的fann。

谢谢

编辑:似乎 2.1.0 beta 版本给出了预期的结果,但 2.2.0 版本没有。

编辑 2:这实际上是我使用的版本中的一个错误。

最佳答案

我试图重现您的错误,但我做不到。这是我的程序:

#include<iostream>
using namespace std;
#include <fann.h>
#include <fann_cpp.h>
#include <floatfann.h>
int main()
{
FANN::neural_net nn;
const float desired_error = 0.00001;
const unsigned int max_epochs = 500000;
const unsigned int epochs_between_reports = 1000;
const unsigned int layers_count = 3;
const unsigned int layers[layers_count] = {7, 5, 1};
nn.create_standard_array(layers_count, layers);
nn.train_on_file("test.train", max_epochs, epochs_between_reports, desired_error);

fann_type i[7];
i[0] = 0.429961; i[1] = 0.0509753; i[2] = 0.381578; i[3] = 0.0266957; i[4] = 0.000117862; i[5] = 0.00707172; i[6] = 0.0221581;
fann_type *o = nn.run(i);
std::cout << "output (run) is " << o[0] << std::endl;

return 0;
}

这是输出:

Max epochs   500000. Desired error: 0.0000100000.
Epochs 1. Current error: 0.2283857614. Bit fail 4.
Epochs 7. Current error: 0.0000000000. Bit fail 0.
output (run) is 1

也许您可以提供完整的训练集?

关于c++ - 使用 FANN 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9612697/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com