声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1972|回复: 1

[人工智能] 请教:将工具箱中训练好的网络用C编写出来的问题。急,求高手解答!

[复制链接]
发表于 2008-10-8 12:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
我用工具箱训练了一个BP网络,为8×20×6,训练好之后,用工具箱查看其权值和阈值为:
输入到隐层的权值:[1.5425 0.1557 7.4534 7.7078 2.225 0.29745 3.281 -17.918;
-15.5792 11.9521 6.0416 -6.8565 1.7624 -1.0447 0.94895 -7.0977;
4.1454 -3.1611 -20.6911 11.768 -0.514 -0.067343 -1.5599 -4.1126;
2.8776 -3.0168 -3.7894 3.3449 0.77696 -0.38856 -1.8145 0.32113;
9.8777 -2.955 6.2403 -4.3953 -8.7673 3.4041 -1.7579 4.2281;
0.62288 -1.083 -1.6363 1.5902 0.24489 -0.085903 0.20295 0.062707;
-5.6988 4.65 10.8123 -7.2696 -0.48403 0.19825 0.88139 -0.82578;
-0.36979 0.16138 -0.13108 0.098552 0.011959 -0.0030787 -0.0010932 0.010651;
-0.48744 1.0891 2.6424 -2.1806 -0.49328 0.18394 0.20297 2.3043;
-6.7884 7.3584 -13.7028 1.1913 -2.6038 0.39317 -3.4252 3.0261;
0.61231 -0.45252 0.36505 -0.058921 0.052499 -0.016937 0.03281 0.00588;
0.94708 0.011808 -3.5766 1.5117 -1.6839 0.8089 -0.67065 -0.24673;
0.11886 -1.0512 -4.3145 3.3719 -0.38245 1.442 -0.18678 0.051635;
-3.0363 2.4866 4.8241 -3.3973 -0.44821 0.11787 0.51218 -0.66691;
-8.7172 10.1896 -0.76856 -5.4672 -0.33666 -9.9833 2.9053 1.9123;
0.39698 -1.0848 -1.9722 1.8741 0.54372 -0.20275 -0.14715 -2.147;
19.5128 -15.4767 8.9333 1.0071 -2.2212 1.1156 1.8334 -4.9948;
3.1321 -3.4085 -14.5556 9.3205 0.23674 -0.36096 -0.16292 -3.0463;
4.7365 -4.08 -2.5269 2.9336 -0.87616 1.4121 -0.054356 -0.10646;
-4.6936 4.0695 2.9874 -3.2003 0.96092 -1.4772 0.13629 0.14299]

隐层到输出的权值:
[-0.0018732 0.0046684 0.0046614 0.3614 0.018686 0.3003 0.12593 -5.4158 -0.023657 -0.020012 -0.76493 -0.10354 -0.003836 -0.56037 -0.00095883 -0.039072 0.0010599 0.0041794 0.27986 0.38321;
0.0068477 -0.023898 0.0023512 -0.38224 0.013854 -0.90346 -0.19436 3.0237 0.44663 0.091487 5.7421 0.13503 0.0036644 0.81828 0.0012917 0.50087 -0.0043091 -0.039521 -1.2922 -1.8785;
0.032862 0.41344 0.039149 0.3556 -1.2683 -2.9528 5.36 1.6559 7.3559 0.7918 -3.962 -1.2286 -0.4359 -18.8243 -0.024955 7.1419 0.089469 0.49069 6.6401 7.6066;
0.17392 0.31471 0.23599 1.3903 1.897 -1.7755 5.5848 -4.7809 11.2261 2.5142 -13.1738 0.15543 -0.44958 -19.3449 -0.02391 11.1506 0.088596 0.28876 6.6977 7.7442;
0.60538 -0.1027 0.39475 3.2749 12.4791 0.74273 1.9874 -8.3339 10.7397 10.6964 -13.1334 3.1947 -0.25471 -5.716 -0.00064417 10.7787 0.022503 -0.10514 12.7446 18.0538;
0.84108 -0.27181 0.0039705 14.5787 19.8675 -2.8488 -3.5584 13.6027 -2.9324 16.3787 17.3554 16.9566 0.15118 10.0309 0.013569 -2.6271 -0.06394 -0.22675 7.5337 13.0826]

隐层阈值:[-0.12838;
5.1737;
3.618;
3.2465;
-5.3018;
-0.96399;
1.4505;
-0.11932;
-1.4966;
5.918;
-0.95923;
-1.2938;
0.31587;
1.8292;
0.42188;
1.3443;
5.897;
1.5421;
-1.839;
1.99]

输出层阈值:
[-1.0786;
4.3852;
2.8966;
-1.5988;
-9.3928;
7.4305]

我用C将这个网络编写出来,程序如下:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include<iostream.h>
#include <math.h>



void main()
{
        double input[8][1]={-0.2815,-0.2957,-0.1649,-0.1814,1,0.4667,0.66,0.7112};
        static double W[20][8]={{1.5425,0.1557,7.4534,7.7078,2.225,0.29745,3.281,-17.918}, //输入到隐层的权值//
        {-15.5792,11.9521,6.0416,-6.8565,1.7624,-1.0447,0.94895,-7.0977},
        {4.1454,-3.1611,-20.6911,11.768,-0.514,-0.067343,-1.5599,-4.1126},
        {2.8776,-3.0168,-3.7894,3.3449,0.77696,-0.38856,-1.8145,0.32113},
        {9.8777,-2.955,6.2403,-4.3953,-8.7673,3.4041,-1.7579,4.2281},
        {0.62288,-1.083,-1.6363,1.5902,0.24489,-0.085903,0.20295,0.062707},
        {-5.6988,4.65,10.8123,-7.2696,-0.48403,0.19825,0.88139,-0.82578},
        {-0.36979,0.16138,-0.13108,0.098552,0.011959,-0.0030787,-0.0010932,0.010651},
        {-0.48744,1.0891,2.6424,-2.1806,-0.49328,0.18394,0.20297,2.3043},
        {-6.7884,7.3584,-13.7028,1.1913,-2.6038,0.39317,-3.4252,3.0261},
        {0.61231,-0.45252,0.36505,-0.058921,0.052499,-0.016937,0.03281,0.00588},
        {0.94708,0.011808,-3.5766,1.5117,-1.6839,0.8089,-0.67065,-0.24673},
        {0.11886,-1.0512,-4.3145,3.3719,-0.38245,1.442,-0.18678,0.051635},
        {-3.0363,2.4866,4.8241,-3.3973,-0.44821,0.11787,0.51218,-0.66691},
        {-8.7172,10.1896,-0.76856,-5.4672,-0.33666,-9.9833,2.9053,1.9123},
        {0.39698,-1.0848,-1.9722,1.8741,0.54372,-0.20275,-0.14715,-2.147},
        {19.5128,-15.4767,8.9333,1.0071,-2.2212,1.1156,1.8334,-4.9948},
        {3.1321,-3.4085,-14.5556,9.3205,0.23674,-0.36096,-0.16292,-3.0463},
        {4.7365,-4.08,-2.5269,2.9336,-0.87616,1.4121,-0.054356,-0.10646},
        {-4.6936,4.0695,2.9874,-3.2003,0.96092,-1.4772,0.13629,0.14299}};

        //隐层到输出的权值//
        static double M[6][20]={{-0.0018732,0.0046684,0.0046614,0.3614,0.018686,0.3003,0.12593,-5.4158,-0.023657,-0.020012,-0.76493,-0.10354,-0.003836,-0.56037,-0.00095883,-0.039072,0.0010599,0.0041794,0.27986,0.38321},
        {0.0068477,-0.023898,0.0023512,-0.38224,0.013854,-0.90346,-0.19436,3.0237,0.44663,0.091487,5.7421,0.13503,0.0036644,0.81828,0.0012917,0.50087,-0.0043091,-0.039521,-1.2922,-1.8785},
        {0.032862,0.41344,0.039149,0.3556,-1.2683,-2.9528,5.36,1.6559,7.3559,0.7918,-3.962,-1.2286,-0.4359,-18.8243,-0.024955,7.1419,0.089469,0.49069,6.6401,7.6066},
        {0.17392,0.31471,0.23599,1.3903,1.897,-1.7755,5.5848,-4.7809,11.2261,2.5142,-13.1738,0.15543,-0.44958,-19.3449,-0.02391,11.1506,0.088596,0.28876,6.6977,7.7442},
        {0.60538,-0.1027,0.39475,3.2749,12.4791,0.74273,1.9874,-8.3339,10.7397,10.6964,-13.1334,3.1947,-0.25471,-5.716,-0.00064417,10.7787,0.022503,-0.10514,12.7446,18.0538},
        {0.84108,-0.27181,0.0039705,14.5787,19.8675,-2.8488,-3.5584,13.6027,-2.9324,16.3787,17.3554,16.9566,0.15118,10.0309,0.013569,-2.6271,-0.06394,-0.22675,7.5337,13.0826}};
        static double Byin[20][1]={-0.12838,5.1737,3.618,3.2465,-5.3018,-0.96399,1.4505,-0.11932,-1.4966,5.918,-0.95923,-1.2938,0.31587,1.8292,0.42188,1.3443,5.897,1.5421,-1.839,1.99};
        static double Bout[6][1]={-1.0786,4.3852,2.8966,-1.5988,-9.3928,7.4305};
        double yinout[20][1]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
        double output[6][1]={0,0,0,0,0,0};
        int mm,nn;
        for (mm=0;mm<20;mm=mm+1)
        {
                double i=0;
                for (nn=0;nn<8;nn=nn+1)
                {
                        i+=W[mm][nn]*input[nn][0];    //求隐层输入//
                }
                i=i-Byin[mm][0];                  //隐层节点减去隐层阈值//
                yinout[mm][0]=(2/(1+exp(-2*i)))-1; //求隐层输出//
        }

        for (mm=0;mm<6;mm=mm+1)
        {
                double i=0;
                for (nn=0;nn<20;nn=nn+1)
                {
                        i+=M[mm][nn]*yinout[nn][0];  //求输出层输入//
                }
                i=i-Bout[mm][0];                 //输出层节点减去阈值//
                output[mm][0]=i;//输出层输出//
        }
        cout<<"output1="<<output[0][0]<<'\n';
        cout<<"output2="<<output[1][0]<<'\n';
        cout<<"output3="<<output[2][0]<<'\n';
        cout<<"output4="<<output[3][0]<<'\n';
        cout<<"output5="<<output[4][0]<<'\n';
        cout<<"output6="<<output[5][0]<<'\n';
}


我用同样的输入:p={-0.2815,-0.2957,-0.1649,-0.1814,1,0.4667,0.66,0.7112}
带入工具箱和我编写的BP程序,工具箱的输出为:
-0.266168601191774
-0.148600759680153
-0.507519232876979
-0.490610356161087
-0.126658667699664
-0.146530202339096

而C编写的BP的输出为:
-0.232652
-0.261644
4.11038
-4.85179
-30.9328
-65.7135

应该是一样的输出,但是差别怎么这么大,求高手指点。
回复
分享到:

使用道具 举报

发表于 2009-3-6 16:44 | 显示全部楼层
我也遇到这个问题了,还不知道为什么,是否matlab内部实现情况更复杂呢?
哪位指点一下呢?
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-12-23 18:51 , Processed in 0.076610 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表