范恩训练不当
FANN doesn't train properly
本文关键字:范恩训 更新时间:2023-10-16
我正在尝试用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 1
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
10 100
我觉得我在API方面做得很好。然而,当我运行它时,我会遇到巨大的错误,这种错误似乎永远不会随着训练而减少。
Test output: -0.0311087
Max 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) 将隐藏层和输出层都设置为线性,网络将自动学习权重,以给出您所拥有的任何输出值。
相关文章:
- 向量范数的c++中的||运算符
- C++中的无穷范数函数
- 尝试应用肖恩父母谈话"inheritance is the base class of evil"中的模式
- _CrtIsValidHeapPointer(块)错误在应用单例-帕特恩后退出主窗口时引发
- 使用异步/期货并行和并发计算向量的范数
- 增强精神解析器:绕过贪婪的克莱恩*
- 特征中范数、归一化和归一化之间的区别
- 将双重价值从小恩迪安转换为大恩迪安
- 在Facebook的愚蠢中,大恩德尼亚人和小恩迪安
- 字节内的恩迪亚
- 解释为 4 个字节的两个整数之间的计算范数
- C++记忆霍夫莱恩斯·
- 范恩异或培训
- 范恩训练不当
- 提升灵气:省略克莱恩星辰解析器中的元素
- 克洛克沃恩.无符号字符上的签名位
- 霍夫莱恩不工作
- 不急于提升灵气的克莱恩星
- 图书馆访问比格尔骨黑(3.8 克恩 - 埃)
- 如何保存一个范恩字符串