?? machine learning - c++的bp算法源程序.htm
字號:
m,FILE* fp)<BR>{<BR>for (int
j=0;j<HN;j++)<BR> for (int
i=0;i<IN;i++)<BR>//cout<<"第"<
fprintf(fp,"第%d個(gè)樣本時(shí)的輸出層至隱層的權(quán)值為:%f\n",m,V[j][i]<BR>);<BR>W[j][i]+=beta*e_err[j]*P[i];//隱層至輸入層的權(quán)值調(diào)整<BR>}<BR>sita[j]+=beta*e_err[j];<BR>}<BR>return
1;<BR>}//子程序Delta_H_I()結(jié)束
<P>/////////////////////////////////<BR>//N個(gè)樣本的全局誤差計(jì)算子程序////<BR>/////////////////////////////////<BR>double
Err_Sum()<BR>{<BR>double total_err=0;<BR>for (int
m=0;m<N;m++)<BR> total_err+=err_m[m];//每個(gè)樣本的均方誤差加起來就成了全局誤差<BR>}<BR>return
1;<BR>}//子程序Err_sum()結(jié)束
<P>/**********************/<BR>/**程序入口,即主程序**/<BR>/**********************/<BR>main()<BR>{<BR>FILE
*fp;<BR>double sum_err;<BR>int study;//訓(xùn)練次數(shù)
<P>if
((fp=fopen("bp.txt","a+"))==NULL)<BR>{<BR>printf("不能創(chuàng)建bp.txt文件!\n");<BR>exit(1);<BR>}<BR>cout<<"請輸入輸出層到隱含層學(xué)習(xí)效率:
alpha=\n";<BR>cin>>alpha;
<P>cout<<"請輸入隱含層到輸入層學(xué)習(xí)效率:
beta=\n";<BR>cin>>beta;
<P>int study=0; //學(xué)習(xí)次數(shù)<BR>double Pre_error ;
//預(yù)定誤差<BR>cout<<"請輸入預(yù)定誤差: Pre_error=
\n";<BR>cin>>Pre_error;
<P>int
Pre_times;<BR>cout<<"請輸入預(yù)定最大學(xué)習(xí)次數(shù):Pre_times=\n";<BR>cin>>Pre_times;
<P>cout<<"請輸入學(xué)習(xí)樣本數(shù)據(jù)\n";<BR>{<BR>for (int
m=0;m<N;m++)<BR> cout<<"請輸入第"<<m+1<<"組學(xué)習(xí)樣本"<<endl;<BR>
for (int i=0;i<IN;i++)<BR>
cin>>Study_Data[m]->input[i];<BR>}<BR>{<BR>for
(int
m=0;m<N;m++)<BR>cout<<"請輸入第"<<m+1<<"組教師樣本"<<endl;<BR> for
(int
k=0;k<ON;k++)<BR>cin>>Study_Data[m]->teach[k];<BR>}
<P>initial(); //隱層、輸出層權(quán)、閾值初始化 (1)<BR>do<BR>{<BR>++study;
///???<BR>for (int m=0;m<N;m++)<BR>{<BR>input_P(m);
//輸入第m個(gè)學(xué)習(xí)樣本 (2)<BR>input_T(m);//輸入第m個(gè)樣本的教師信號
(3)<BR>H_I_O(); //第m個(gè)學(xué)習(xí)樣本隱層各單元輸入、輸出值 (4)<BR>O_I_O();
//第m個(gè)學(xué)習(xí)樣本輸出層各單元輸入、輸出值 (5)<BR>Err_O_H(m);
//第m個(gè)學(xué)習(xí)樣本輸出層至隱層一般化誤差 (6)<BR>Err_H_I();
//第m個(gè)學(xué)習(xí)樣本隱層至輸入層一般化誤差 (7)<BR>Delta_O_H(m,fp);
//第m個(gè)學(xué)習(xí)樣本輸出層至隱層權(quán)閾值調(diào)整、修改 (8)<BR>Delta_H_I(m,fp);
//第m個(gè)學(xué)習(xí)樣本隱層至輸入層權(quán)閾值調(diào)整、修改 (9)<BR>} //全部樣本訓(xùn)練完畢
<P>sum_err=Err_Sum(); //全部樣本全局誤差計(jì)算
(10)<BR>{<BR>cout<<"第"<<study<<"次學(xué)習(xí)的均方誤差為"<<sum_err<<endl;<BR>fprintf(fp,"第%d次學(xué)習(xí)的均方誤差為:%f\n",study,sum_err);<BR>}
<P>while (sum_err > Pre_error)
//or(study<BR>{ //N個(gè)樣本全局誤差小于預(yù)定誤差否? 小于則退出
(11)<BR>cout<<"網(wǎng)絡(luò)已經(jīng)學(xué)習(xí)了"<<study<<"次,學(xué)習(xí)的均方誤差為"<<sum_err<<endl;<BR>fprintf(fp,"網(wǎng)絡(luò)已經(jīng)學(xué)習(xí)了%d次,現(xiàn)在的全局誤差為:%f\n",study,total_err);<BR>fclose(fp);<BR>}<BR>char
s;<BR>cout<<"請隨便輸入一個(gè)字符,按回車退出程序!\n";<BR>cin>>s;<BR>return
1;<BR>}
<P><BR></P></FONT></TD></TR></TBODY></TABLE>
<TABLE style="TABLE-LAYOUT: fixed" cellSpacing=0 cellPadding=0
width="100%">
<TBODY>
<TR>
<TD
style="LEFT: 0px; WIDTH: 100%; WORD-WRAP: break-word; 130: "><BR><BR><IMG
height=3
src="Machine Learning - C++的BP算法源程序.files/none.gif"
width=1><BR><IMG height=12
src="Machine Learning - C++的BP算法源程序.files/signature.gif"><BR><IMG
height=5
src="Machine Learning - C++的BP算法源程序.files/none.gif"
width=1><BR>新的一天需要太陽來開啟!新的感覺需要熱情來澆灌!新的智慧需要執(zhí)著來積淀!</TD></TR></TBODY></TABLE></FONT><BR></TD>
<TD width=16></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD class=bottomline vAlign=bottom bgColor=#ffffff>
<HR width="100%" color=#000000 SIZE=1>
<TABLE cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD vAlign=bottom><FONT color=#000000> <IMG height=15
alt=發(fā)貼時(shí)間
src="Machine Learning - C++的BP算法源程序.files/posttime.gif"
width=16 align=absMiddle>2004/05/17 10:52am <IMG height=15
alt="此 IP 為代理服務(wù)器"
src="Machine Learning - C++的BP算法源程序.files/ip.gif" width=13
align=absMiddle>IP: 已設(shè)置保密</FONT></TD>
<TD vAlign=bottom align=right width=110 nowarp></TD></FORM>
<TD vAlign=bottom align=right
width=4></TD></TR></TBODY></TABLE></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=2 cellPadding=0 width="95%" align=center>
<TBODY>
<TR bgColor=#ccccff height=4></TR>
<TR>
<TD><FONT color=#333333> <FONT
color=#333333>該主題只有一頁</FONT></FONT></TD></TR></TBODY></TABLE><BR>
<FORM name=FORM action=post.cgi?action=reply&forum=20&topic=75
method=post encType=multipart/form-data><INPUT type=hidden value=addreply
name=action> <INPUT type=hidden value=20 name=forum> <INPUT type=hidden value=75
name=topic>
<TABLE cellSpacing=1 cellPadding=5 width="95%" align=center bgColor=#000000>
<TBODY>
<TR>
<TD width=220 bgColor=#ccccff><FONT color=#333333><B>快速回復(fù)主題:</B></FONT></TD>
<TD width=500 bgColor=#ccccff><FONT color=#333333>C++的BP算法源程序</FONT></TD></TR>
<TR>
<TD bgColor=#ccccff><FONT color=#333333><B>輸入用戶名和密碼:</B></FONT></TD>
<TD bgColor=#ccccff><FONT color=#333333><B>用戶名</B>: <INPUT
onmouseover=this.focus() onfocus=this.select() value=客人 name=membername>
<SPAN style="CURSOR: hand"
onclick="javascript:location.href='register.cgi?forum=20'">沒有注冊?</SPAN> <B>密碼:</B>
<INPUT onmouseover=this.focus() onfocus=this.select() type=password
name=password> <A style="CURSOR: help"
href="http://ir.hit.edu.cn/cgi-bin/newbbs/profile.cgi?action=lostpass">忘記密碼?</A></FONT></TD></TR>
<TR>
<TD bgColor=#ccccff><B>上傳附件或圖片</B> (最大容量 <B>500</B>KB)</TD>
<TD bgColor=#ccccff colSpan=2><INPUT type=file size=45
name=addme> <SELECT><OPTION value=# selected>支持類型:</OPTION><OPTION
value=#>----------</OPTION><OPTION>gif</OPTION><OPTION>jpg</OPTION><OPTION>bmp</OPTION><OPTION>zip</OPTION><OPTION>swf</OPTION><OPTION>doc</OPTION><OPTION>txt</OPTION></SELECT></TD></TR>
<TR>
<TD vAlign=top bgColor=#eeeeee><FONT color=#333333><B>選項(xiàng)</B>
<BR><BR><INPUT type=checkbox CHECKED value=yes name=uselbcode>使用 LB5000
標(biāo)簽?<BR><INPUT type=checkbox CHECKED value=yes
name=inshowsignature>顯示您的簽名?<BR><INPUT type=checkbox value=yes
name=notify>有回復(fù)時(shí)使用郵件通知您?<BR><INPUT type=checkbox CHECKED value=yes
name=inshowemoticons>使用表情字符轉(zhuǎn)換?<BR></FONT></TD>
<TD width=* bgColor=#eeeeee><TEXTAREA onkeydown=ctlent() name=inpost rows=8 cols=75></TEXTAREA><BR><INPUT onclick="return clckcntr();" type=submit value="發(fā) 表 回 復(fù)" name=Submit> <INPUT onclick=gopreview() type=button value="預(yù) 覽 內(nèi) 容" name=Button> <INPUT type=reset value="清 除" name=Clear> [使用
Ctrl+Enter 直接提交貼子] </TD></TR></TBODY></TABLE></FORM>
<FORM name=preview action=preview.cgi method=post target=preview_page><INPUT
type=hidden name=body><INPUT type=hidden value=20 name=forum></FORM>
<SCRIPT>function gopreview(){document.preview.body.value=document.FORM.inpost.value;var popupWin = window.open('preview.cgi', 'preview_page', 'scrollbars=yes,width=500,height=300');document.preview.submit()}</SCRIPT>
<TABLE cellSpacing=0 cellPadding=0 width="95%" align=center>
<TBODY>
<TR>
<TD> <A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/topic.cgi?forum=20&topic=75&show=50#top"><IMG
height=15 src="Machine Learning - C++的BP算法源程序.files/gotop.gif" width=15
align=absMiddle border=0>頂端</A> <A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/fav.cgi?action=add&forum=20&topic=75"><IMG
height=15 src="Machine Learning - C++的BP算法源程序.files/addfavorite.gif"
width=18 align=absMiddle border=0>加到"個(gè)人收藏夾"</A></TD>
<TD noWrap align=right><FONT color=#333333><B>主題管理</B>: <A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/postings.cgi?action=abslocktop&forum=20&topic=75">總固頂</A>
| <A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/postings.cgi?action=absunlocktop&forum=20&topic=75">取消總固頂</A>
| <A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/postings.cgi?action=locktop&forum=20&topic=75">固頂</A>
| <A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/postings.cgi?action=unlocktop&forum=20&topic=75">取消固頂</A>
| <A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/jinghua.cgi?action=add&forum=20&topic=75">精華</A>
| <A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/jinghua.cgi?action=del&forum=20&topic=75">取消精華</A>
|<BR><A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/postings.cgi?action=puttop&forum=20&topic=75">提升</A>
| <A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/postings.cgi?action=lock&forum=20&topic=75">鎖定</A>
| <A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/postings.cgi?action=unlock&forum=20&topic=75">解鎖</A>
| <A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/recyclebin.cgi?action=add&forum=20&topic=75">回收</A>
| <A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/recyclebin.cgi?action=del&forum=20&topic=75">復(fù)原</A>
| <A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/delpost.cgi?action=delete&forum=20&topic=75">刪除</A>
| <SPAN style="CURSOR: hand" onclick=javascript:DelReply();>刪除回復(fù)</SPAN> |
<A
href="http://ir.hit.edu.cn/cgi-bin/newbbs/delpost.cgi?action=movetopic&forum=20&topic=75">移動</A>
| </FONT></TD></TR></TBODY></TABLE>
<P>
<P>
<FORM name=DReply action=delpost.cgi method=post><INPUT type=hidden value=20
name=forum> <INPUT type=hidden value=75 name=topic> <INPUT type=hidden
value=directdel name=action> <INPUT type=hidden name=postno></FORM>
<CENTER>
<HR width=380 SIZE=1>
<TABLE cellSpacing=0 cellPadding=0 width="80%" align=center>
<TBODY>
<TR>
<TD align=middle><FONT color=#333333>© 中文版權(quán)所有: <A
href="http://ir.hit.edu.cn/">哈爾濱工業(yè)大學(xué)信息檢索實(shí)驗(yàn)室</A> 版本: <A
title=按此可以下載最新版本的雷傲超級論壇
href="http://www.cgier.com/cgi-bin/lbdown.cgi">LB5000XP v1201</A><BR><FONT
color=#000000>程序版權(quán)所有: <A href="http://www.cgier.com/" target=_blank>CGI
編程者之家</A> 程序編制: <A href="mailto:htc@263.net">山鷹(糊)</A>、 <A
href="mailto:info@cgier.net">花無缺</A></FONT><BR><IMG height=3
src="Machine Learning - C++的BP算法源程序.files/none.gif"
width=0><BR>本論壇言論純屬發(fā)表者個(gè)人意見,與<FONT color=#5577aa><B> 哈爾濱工業(yè)大學(xué)信息檢索實(shí)驗(yàn)室論壇
</B></FONT>立場無關(guān)<BR></FONT></TD></TR></TBODY></TABLE></CENTER>
<CENTER><FONT>程序占用 CPU 時(shí)間:0.44 usr + 0.01 sys</FONT></CENTER></BODY></HTML>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -