• FANN学习2之建立简单工程


    因为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表示输出数目

    其余的是训练数据,第一行使输入,第二行是输出

  • 相关阅读:
    POJ 1953 World Cup Noise
    POJ 1995 Raising Modulo Numbers (快速幂取余)
    poj 1256 Anagram
    POJ 1218 THE DRUNK JAILER
    POJ 1316 Self Numbers
    POJ 1663 Number Steps
    POJ 1664 放苹果
    如何查看DIV被设置什么CSS样式
    独行DIV自适应宽度布局CSS实例与扩大应用范围
    python 从入门到精通教程一:[1]Hello,world!
  • 原文地址:https://www.cnblogs.com/xiangshancuizhu/p/2155684.html
Copyright © 2020-2023  润新知