因为FANN是在C下编写的,对C++支持不好,开始建立C++文件,发现调用的时候出现了模板调用之类的错误,而运行FANN自带的VC6.0工程却正确运行,后来发现他们写的都是C文件。
1.首先把fann-2.1.0下MicrosoftVisualC++6.0的all.daw用VC6.0打开,rebulid all
2.建立新工程,把fann的include包含进去
3.并把fann里面的libfann.lib放进当前文件夹下,否则会出现link错误
4.新建main.c文件
网络训练
下面的例子展示了如何利用数据集训练网络,并保存网络:
#include <stdio.h>
#include "floatfann.h"
#include "fann.h"
#pragma comment(lib, "libfann.lib ")
int main()
{
const unsigned int num_input = 2;
const unsigned int num_output = 1;
const unsigned int num_layers = 3;
const unsigned int num_neurons_hidden = 3;
const float desired_error = (const float) 0.001;
const unsigned int max_epochs = 500000;
const unsigned int epochs_between_reports = 1000;
struct fann *ann = fann_create_standard(num_layers, num_input,
num_neurons_hidden, num_output);
fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC);
fann_train_on_file(ann, "xor.data", max_epochs,
epochs_between_reports, desired_error);
fann_save(ann, "xor_float.net");
fann_destroy(ann);
return 0;
}
其中xor.data里面的数据有:
4 2 1 训练数据参数
-1 -1 输入
-1 输出
-1 1
1
1 -1
1
1 1
-1
第一行的4表示训练数据数目,2表示输入数目,1表示输出数目
其余的是训练数据,第一行使输入,第二行是输出