使用FANN库

我一直在尝试使用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 10.0812069 0.0812069 0.381578 0.0812069 5.8931e-05 0.0843302 0.606695 10.429961 0.0509753 0.381578 0.0266957 0.000117862 0.00707172 0.0221581 10.0983558 0.486888 0.381578 0.000117862 0.0266957 0.00701279 0.0539808 10.0983558 0.486888 0.598562 0.0161471 0.0161471 0.000471448 0.00135541 1

完整的数据集可以在这里找到

使用训练数据文件中的一个样本数据,我应该能得到与之匹配的输出,对吗?然而,如果我这样做,我得到的输出是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;

能有人解释一下这里发生了什么吗?

我使用的是fann的2.2.0版本。

谢谢

编辑:看起来2.1.0测试版能得到预期的结果,但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

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

Related Posts

Keras Dense层输入未被展平

这是我的测试代码: from keras import…

无法将分类变量输入随机森林

我有10个分类变量和3个数值变量。我在分割后直接将它们…

如何在Keras中对每个输出应用Sigmoid函数?

这是我代码的一部分。 model = Sequenti…

如何选择类概率的最佳阈值?

我的神经网络输出是一个用于多标签分类的预测类概率表: …

在Keras中使用深度学习得到不同的结果

我按照一个教程使用Keras中的深度神经网络进行文本分…

‘MatMul’操作的输入’b’类型为float32,与参数’a’的类型float64不匹配

我写了一个简单的TensorFlow代码,但不断遇到T…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注