FANN无法正确训练

我试图用FANN来近似平方函数。代码如下:

#include "../FANN-2.2.0-Source/src/include/doublefann.h"#include "../FANN-2.2.0-Source/src/include/fann_cpp.h"#include <cstdlib>#include <iostream>using namespace std;using namespace FANN;//Remember: fann_type is double!int main(int argc, char** argv) {    //create a test network: [1,2,1] MLP    neural_net * net = new neural_net;    const unsigned int layers[3] = {1,3,1};    net->create_standard_array(3,layers);    //net->create_standard(num_layers, num_input, num_hidden, num_output);    net->set_learning_rate(0.7f);    net->set_activation_steepness_hidden(0.7);    net->set_activation_steepness_output(0.7);    net->set_activation_function_hidden(SIGMOID_SYMMETRIC_STEPWISE);    net->set_activation_function_output(SIGMOID_SYMMETRIC_STEPWISE);    net->set_training_algorithm(TRAIN_QUICKPROP);    //cout<<net->get_train_error_function()    //exit(0);    //test the number 2    fann_type * testinput = new fann_type;    *testinput = 2;    fann_type * testoutput = new fann_type;    *testoutput = *(net->run(testinput));    double outputasdouble = (double) *testoutput;    cout<<"Test output: "<<outputasdouble<<endl;    //make a training set of x->x^2    training_data * squaredata = new training_data;    squaredata->read_train_from_file("trainingdata.txt");    net->train_on_data(*squaredata,1000,100,0.001);    cout<<endl<<"Easy!";    return 0;}

trainingdata.txt的内容如下:

10 1 11 22 43 94 165 256 367 498 649 8110 100

我觉得我在使用API时一切都做对了。然而,当我运行它时,我得到了一个巨大的错误,并且似乎随着训练从未减少。

Test output: -0.0311087Max epochs     1000. Desired error: 0.0010000000.Epochs            1. Current error: 633.9928588867. Bit fail 10.Epochs          100. Current error: 614.3250122070. Bit fail 9.Epochs          200. Current error: 614.3250122070. Bit fail 9.Epochs          300. Current error: 614.3250122070. Bit fail 9.Epochs          400. Current error: 614.3250122070. Bit fail 9.Epochs          500. Current error: 614.3250122070. Bit fail 9.Epochs          600. Current error: 614.3250122070. Bit fail 9.Epochs          700. Current error: 614.3250122070. Bit fail 9.Epochs          800. Current error: 614.3250122070. Bit fail 9.Epochs          900. Current error: 614.3250122070. Bit fail 9.Epochs         1000. Current error: 614.3250122070. Bit fail 9.Easy!

我做错了什么?


回答:

如果你在输出层使用Sigmoid函数,输出将提供(0,1)的范围。

你有两个选择,(1)将所有输出除以一个常数,比如1e4。当测试数据到来时,你也将它除以1e4。问题是你可能无法预测大于100的平方数(100^2=1e4);(2)将隐藏层和输出层都设为线性,网络将自动学习权重以提供你所需的任何输出值。

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

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