?? machine learning - c++的bp算法源程序.htm
字號:
border=0></A> <A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/fav.cgi?action=add&forum=20&topic=75"><IMG
height=15 alt=加入個人收藏&關注本貼
src="Machine Learning - C++的BP算法源程序.files/fav.gif" width=13
border=0></A> <A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/printpage.cgi?forum=20&topic=75"><IMG
alt=顯示可打印的版本
src="Machine Learning - C++的BP算法源程序.files/printpage.gif" width=16
border=0></A> <IMG style="CURSOR: hand"
onclick="javascript:openScript('pag.cgi?forum=20&topic=75',500,400)"
alt=把本貼打包郵遞 src="Machine Learning - C++的BP算法源程序.files/pag.gif"
width=16 border=0> <SPAN style="CURSOR: hand"
onclick="window.external.AddFavorite('http://ir.hit.edu.cn/cgi-bin/newbbs/topic.cgi?forum=20&topic=75', ' 哈爾濱工業(yè)大學信息檢索實驗室論壇 - C++的BP算法源程序')"><IMG
height=15 alt=把本貼加入IE收藏夾
src="Machine Learning - C++的BP算法源程序.files/fav_add1.gif" width=15
border=0></SPAN> <A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/lbfriend.cgi?forum=20&topic=75"><IMG
alt=發(fā)送本頁面給朋友
src="Machine Learning - C++的BP算法源程序.files/emailtofriend.gif"
width=16 border=0></A> </TD></TR></TBODY></TABLE></TD>
<TD width=1 bgColor=#000000 height=24></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="95%" align=center bgColor=#000000>
<TBODY>
<TR>
<TD height=1></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="95%" align=center>
<TBODY>
<TR>
<TD width=1 bgColor=#000000 height=24></TD>
<TD bgColor=#ffffff><A name=bottom></A>
<TABLE cellSpacing=5 cellPadding=4 width="100%" bgColor=#ffffff>
<TBODY>
<TR>
<TD vAlign=top width=168 bgColor=#ffffff rowSpan=2>
<TABLE style="FILTER: glow(color=none,direction=135)"> <FONT
color=#000066><B>billlang </B>
<TBODY></TBODY></TABLE><FONT color=#000000> </FONT><BR><FONT
color=#000000> </FONT> <BR> <IMG height=50
src="Machine Learning - C++的BP算法源程序.files/billlang.gif" width=50
border=0> <BR><A title=光明使者
href="http://ir.hit.edu.cn/cgi-bin/newbbs/lookinfo.cgi?action=style"
target=_blank><IMG
src="Machine Learning - C++的BP算法源程序.files/pips5.gif" width=100
border=0></A> <BR><FONT color=#000000>信息: <IMG alt=該用戶目前不在線
src="Machine Learning - C++的BP算法源程序.files/offline1.gif" width=15
align=absMiddle> <IMG alt=帥哥
src="Machine Learning - C++的BP算法源程序.files/mal.gif" width=20
align=absMiddle> <IMG height=15 alt=酉雞
src="Machine Learning - C++的BP算法源程序.files/sx10s.gif"
align=absMiddle> <IMG height=15 alt=天秤座
src="Machine Learning - C++的BP算法源程序.files/z7.gif"
align=absMiddle></FONT> <BR><FONT color=#000000>威望: 0</FONT>
<BR><FONT color=#000000>魅力: <IMG height=8 alt=15214
src="Machine Learning - C++的BP算法源程序.files/bar4.gif" width=41></FONT>
<BR><FONT color=#000000>經驗: <IMG height=8 alt=9146
src="Machine Learning - C++的BP算法源程序.files/bar5.gif" width=15></FONT>
<BR><FONT color=#000000>現金: 27337 IR 元</FONT> <BR><FONT
color=#000000>存款: 153781 IR 元</FONT> <BR><FONT color=#000000>貸款:
沒貸款</FONT> <BR><FONT color=#000000>來自: 黑龍江哈爾濱 <IMG height=14 alt=中國
src="Machine Learning - C++的BP算法源程序.files/China.gif"
align=absMiddle></FONT> <BR><FONT color=#000000>在線: 329 時 28 分 06
秒</FONT> <BR><FONT color=#000000>總發(fā)貼數: <B>845</B> 篇</FONT> <BR><FONT
color=#000000>注冊日期: 2003/07/25</FONT><BR></FONT></TD>
<TD width=1 bgColor=#ffffff height="100%" rowSpan=2>
<TABLE height="100%" cellSpacing=0 cellPadding=0 width=1
bgColor=#ccccff>
<TBODY>
<TR>
<TD width=1></TD></TR></TBODY></TABLE></TD>
<TD vAlign=top width=* bgColor=#ffffff height="100%"><SPAN
title=發(fā)送一個短消息給billlang style="CURSOR: hand"
onclick="javascript:openScript('messanger.cgi?action=new&touser=billlang',420,320)"><IMG
src="Machine Learning - C++的BP算法源程序.files/message.gif" width=16
align=absMiddle border=0>消息</SPAN> <A title=查看billlang的個人資料
href="http://ir.hit.edu.cn/cgi-bin/newbbs/profile.cgi?action=show&member=billlang"><IMG
src="Machine Learning - C++的BP算法源程序.files/profile.gif" width=16
align=absMiddle border=0>查看</A> <A title=搜索billlang在本分論壇的全部貼子
href="http://ir.hit.edu.cn/cgi-bin/newbbs/search.cgi?action=startsearch&TYPE_OF_SEARCH=username_search&NAME_SEARCH=topictitle_search&FORUMS_TO_SEARCH=20&SEARCH_STRING=billlang"
target=_blank><IMG
src="Machine Learning - C++的BP算法源程序.files/find.gif" width=16
align=absMiddle border=0>搜索</A> <SPAN title=加billlang為我的好友
style="CURSOR: hand"
onclick="javascript:openScript('friendlist.cgi?action=adduser&adduser=billlang',420,320)"><IMG
src="Machine Learning - C++的BP算法源程序.files/friend.gif" width=16
align=absMiddle border=0>好友</SPAN> <A title=電子郵件地址
href="mailto:bill_lang@ir.hit.edu.cn"><IMG
src="Machine Learning - C++的BP算法源程序.files/email.gif" width=16
align=absMiddle border=0>郵件</A> <A title="訪問 billlang 的主頁"
href="http://ir.hit.edu.cn/~bill_lang" target=_blank><IMG
src="Machine Learning - C++的BP算法源程序.files/homepage.gif" width=16
align=absMiddle border=0>主頁</A> <A title="查看 QQ:45304224的資料"
href="http://search.tencent.com/cgi-bin/friend/user_show_info?ln=45304224"
target=_blank><IMG
src="Machine Learning - C++的BP算法源程序.files/oicq.gif" width=16
align=absMiddle border=0>QQ</A> <A title=復制這個貼子
href="http://ir.hit.edu.cn/cgi-bin/newbbs/post.cgi?action=copy1&forum=20&topic=75&postno=1"><IMG
src="Machine Learning - C++的BP算法源程序.files/copy.gif" width=16
align=absMiddle border=0>復制</A> <A title=引用回復這個貼子
href="http://ir.hit.edu.cn/cgi-bin/newbbs/post.cgi?action=replyquote&forum=20&topic=75&postno=1"><IMG
src="Machine Learning - C++的BP算法源程序.files/reply.gif" width=16
align=absMiddle border=0>引用</A> <A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/post.cgi?action=reply&forum=20&topic=75"><IMG
alt=回復貼子 src="Machine Learning - C++的BP算法源程序.files/replynow.gif"
width=16 border=0>回復</A> <BR>
<HR width="100%" color=#000000 SIZE=1>
<TABLE style="TABLE-LAYOUT: fixed" cellSpacing=0 cellPadding=0
width="100%">
<TBODY>
<TR>
<TD vAlign=top width=32><IMG height=13
src="Machine Learning - C++的BP算法源程序.files/05.gif"
width=13> </TD>
<TD
style="LEFT: 0px; WIDTH: 100%; WORD-WRAP: break-word; 130: ">
<TABLE style="TABLE-LAYOUT: fixed" height=120 cellSpacing=0
cellPadding=0 width="100%">
<TBODY>
<TR vAlign=top>
<TD
style="LEFT: 0px; WIDTH: 100%; WORD-WRAP: break-word; 130: "><FONT
color=#000000>發(fā)信站: 華南木棉BBS
<P>#include "iostream.h"<BR>#include
"iomanip.h"<BR>#define N 20 //學習樣本個數<BR>#define IN 1
//輸入層神經元數目<BR>#define HN 8 //隱層神經元數目<BR>#define ON 1
//輸出層神經元數目<BR>double P[IN]; //單個樣本輸入數據<BR>double T[ON];
//單個樣本教師數據<BR>double W[HN][IN]; //輸入層至隱層權值<BR>double
V[ON][HN]; //隱層至輸出層權值<BR>double X[HN]; //隱層的輸入<BR>double
Y[ON]; //輸出層的輸入<BR>double H[HN]; //隱層的輸出<BR>double
O[ON]; //輸出層的輸出<BR>double sita[HN]; //隱層的閾值<BR>double
gama[ON]; //輸出層的閾值<BR>double err_m[N];
//第m個樣本的總誤差<BR>double alpha; //輸出層至隱層的學習效率<BR>double
beta; //隱層至輸入層學習效率<BR>//定義一個放學習樣本的結構<BR>struct
{<BR>double input[IN];<BR>double
teach[ON];<BR>}Study_Data[N][IN];
<P>///////////////////////////<BR>//初始化權、閾值子程序/////<BR>///////////////////////////<BR>initial()<BR>{<BR>float
sgn;<BR>float rnd;<BR>int
i,j;<BR>//隱層權、閾值初始化//<BR> {<BR> //sgn=pow((-1),random(100));<BR> sgn=rand();<BR> rnd=sgn*(rand()%100);<BR> W[j][i]=
rnd/100;//隱層權值初始化。<BR> }<BR>//randomize();<BR> {<BR>//sgn=pow((-1),random(1000));<BR> sgn=rand();<BR> rnd=sgn*(rand()%1000);<BR> sita[j]=
rnd/1000;//中間層閾值初始化<BR> cout<<"sita"<<sita[j]<<endl;<BR> }<BR>//輸出層權、閾值初始化//<BR>//randomize();<BR>for
(int k=0;k<ON;k++)<BR>for (int
j=0;j<HN;j++)<BR>{<BR>//sgn=pow((-1),random(1000));<BR>
sgn=rand();<BR> rnd=sgn*(rand()%1000);<BR>
V[k][j]=rnd/1000;//第m個樣本輸出層權值初始化<BR>}<BR>//randomize();<BR> {<BR> //sgn=pow((-1),random(10));<BR> sgn=rand();<BR> rnd=sgn*(rand()%10);<BR> gama[k]=rnd/10;//輸出層閾值初始化<BR> cout<<"gama[k]"<<endl;<BR> }<BR> return
1;
<P>}//子程序initial()結束
<P><BR>////////////////////////////////<BR>////第m個學習樣本輸入子程序///<BR>///////////////////////////////<BR>input_P(int
m)<BR>{<BR>for (int
i=0;i<IN;i++)<BR>P[i]=Study_Data[m]->input[i];<BR>//獲得第m個樣本的數據<BR>//cout<<"第"<
//fprintf(fp,"第%d個樣本的學習輸入:<BR>//P[%d]=%f\n",m,P[i]);<BR>return
1;<BR>}//子程序input_P(m)結束
<P>/////////////////////////////<BR>////第m個樣本教師信號子程序//<BR>/////////////////////////////<BR>input_T(int
m)<BR>{<BR>for (int
k=0;k<m;k++)<BR>T[k]=Study_Data[m]->teach[k];<BR>//cout<<"第"<
//fprintf(fp,"第%d個樣本的教師信號:T[%d]=%f\n",m,T[k]);<BR>return
1;<BR>}//子程序input_T(m)結束
<P>/////////////////////////////////<BR>//隱層各單元輸入、輸出值子程序///<BR>/////////////////////////////////<BR>H_I_O(){<BR>double
sigma;<BR>int i,j;<BR>for
(j=0;j<HN;j++)<BR>sigma=0.0;<BR>for
(i=0;i<IN;i++)<BR>sigma+=W[j][i]*P[i];//求隱層內積<BR>}<BR>X[j]=sigma
-
sita[i];//求隱層凈輸入<BR>H[j]=1.0/(1.0+exp(-X[j]));//求隱層輸出<BR>}<BR>return
1;<BR>}//子程序H_I_O()結束
<P>///////////////////////////////////<BR>//輸出層各單元輸入、輸出值子程序///<BR>///////////////////////////////////<BR>O_I_O()<BR>{<BR>double
sigma;<BR>for (int k=0;k<ON;k++)<BR>sigma=0.0;<BR>for
(int
j=0;j<HN;j++)<BR>sigma+=V[k][j]*H[k];//求輸出層內積<BR>}<BR>Y[k]=sigma-gama[k];
//求輸出層凈輸入<BR>O[k]=1.0/(1.0+exp(-Y[k]));//求輸出層輸出<BR>}<BR>return
1;<BR>}//子程序O_I_O()結束
<P>////////////////////////////////////<BR>//輸出層至隱層的一般化誤差子程序////<BR>////////////////////////////////////<BR>double
d_err[ON];<BR>Err_O_H(int m)<BR>{<BR>double
abs_err[ON];//每個樣本的絕對誤差都是從0開始的<BR>double
sqr_err=0;//每個樣本的平方誤差計算都是從0開始的<BR>//for (int
output=0;output<ON;output++)
//output???<BR> for (int
k=0;k<ON;k++)<BR> abs_err[k]=T[k]-O[k];<BR>//求第m個樣本下的第k個神經元的絕對誤差<BR>sqr_err+=(abs_err[k])*(abs_err[k]);//求第m個樣本下輸出層的平方誤差
<P>d_err[k]=abs_err[k]*O[k]*(1.0-O[k]);//d_err[k]輸出層各神經元的一般化誤差<BR>}<BR>err_m[m]=sqr_err/2;//第m個樣本下輸出層的平方誤差/2=第m個樣本的均方誤差<BR>return
1;<BR>}//子程序Err_O_H(m)結束
<P>////////////////////////////////////<BR>//隱層至輸入層的一般化誤差子程序////<BR>////////////////////////////////////<BR>double
e_err[HN];<BR>Err_H_I(){<BR>double sigma;<BR>//for (int
hidden=0;hidden<BR> for (int
j=0;j<HN;j++)<BR> sigma=0.0;<BR>
for (int k=0;k<ON;k++)<BR>
sigma=d_err[k]*V[k][j];<BR>}<BR>e_err[j]=sigma*H[j]*(1-H[j]);//隱層各神經元的一般化誤差<BR>}<BR>return
1;<BR>}//子程序Err_H_I()結束
<P>////////////////////////////////////////////////////////<BR>//輸出層至隱層的權值調整、輸出層閾值調整計算子程序//////<BR>////////////////////////////////////////////////////////<BR>Delta_O_H(int
m,FILE* fp)<BR>{<BR>for (int k=0;k<ON;k++)<BR>for
(int j=0;j<HN;j++)<BR> //cout<<"第"<
fprintf(fp,"第%d個樣本時的輸出層至隱層的權值為:%f\n",m,W[k][j<BR>]);<BR> V[k][j]+=alpha*d_err[k]*H[j];//輸出層至隱層的權值調整<BR>}<BR>gama[k]+=alpha*d_err[k];//輸出層至隱層的閾值調整<BR>}<BR>return
1;<BR>}//子程序Delta_O_H()結束
<P>/////////////////////////////////////////////////////<BR>//隱層至輸入層的權值調整、隱層閾值調整計算子程序/////<BR>/////////////////////////////////////////////////////<BR>Delta_H_I(int
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -