我对神经网络完全没有经验,现在我只是在玩 FANN 库来学习它们。所以目标是训练网络逼近正弦函数。为此,我使用 3 层 NN 1 个输入、3 个隐藏和 1 个输出神经元。代码是
const unsigned int num_input = 1;
const unsigned int num_output = 1;
const unsigned int num_layers = 3;
const unsigned int num_neurons_hidden = 3;
struct fann *ann;
ann = fann_create_standard(num_layers, num_input, num_neurons_hidden, num_output);
fann_set_activation_steepness_hidden(ann, 1);
fann_set_activation_steepness_output(ann, 1);
fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC);
fann_set_train_stop_function(ann, FANN_STOPFUNC_BIT);
fann_set_bit_fail_limit(ann, 0.01f);
fann_set_training_algorithm(ann, FANN_TRAIN_RPROP);
fann_randomize_weights(ann, 0, 1);
for(int i=0; i<2; ++i) {
for(float angle=0; angle<10; angle+=0.1) {
float sin_anle = sinf(angle);
fann_train(ann, &angle, &sin_anle);
}
}
int k = 0;
for(float angle=0; angle<10; angle+=0.1) {
float sin_anle = sinf(angle);
float *o = fann_run(ann, &angle);
printf("%d\t%f\t%f\t\n", k++, *o, sin_anle);
}
fann_destroy(ann);
但是,我得到的结果与真正的正弦函数无关。我想我的网络设计中存在一些基本错误。