⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 machine learning - c++的bp算法源程序.htm

📁 一个BP算法的C++实现
💻 HTM
📖 第 1 页 / 共 3 页
字号:
            border=0></A>&nbsp; <A 
            href="http://ir.hit.edu.cn/cgi-bin/newbbs/fav.cgi?action=add&amp;forum=20&amp;topic=75"><IMG 
            height=15 alt=加入个人收藏&amp;关注本贴 
            src="Machine Learning - C++的BP算法源程序.files/fav.gif" width=13 
            border=0></A>&nbsp; <A 
            href="http://ir.hit.edu.cn/cgi-bin/newbbs/printpage.cgi?forum=20&amp;topic=75"><IMG 
            alt=显示可打印的版本 
            src="Machine Learning - C++的BP算法源程序.files/printpage.gif" width=16 
            border=0></A>&nbsp; <IMG style="CURSOR: hand" 
            onclick="javascript:openScript('pag.cgi?forum=20&amp;topic=75',500,400)" 
            alt=把本贴打包邮递 src="Machine Learning - C++的BP算法源程序.files/pag.gif" 
            width=16 border=0>&nbsp; <SPAN style="CURSOR: hand" 
            onclick="window.external.AddFavorite('http://ir.hit.edu.cn/cgi-bin/newbbs/topic.cgi?forum=20&amp;topic=75', ' 哈尔滨工业大学信息检索实验室论坛 - C++的BP算法源程序')"><IMG 
            height=15 alt=把本贴加入IE收藏夹 
            src="Machine Learning - C++的BP算法源程序.files/fav_add1.gif" width=15 
            border=0></SPAN>&nbsp; <A 
            href="http://ir.hit.edu.cn/cgi-bin/newbbs/lbfriend.cgi?forum=20&amp;topic=75"><IMG 
            alt=发送本页面给朋友 
            src="Machine Learning - C++的BP算法源程序.files/emailtofriend.gif" 
            width=16 border=0></A>&nbsp;&nbsp;</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)">&nbsp;<FONT 
              color=#000066><B>billlang&nbsp;</B>
              <TBODY></TBODY></TABLE><FONT color=#000000>&nbsp;   </FONT><BR><FONT 
            color=#000000>&nbsp;</FONT> <BR>&nbsp; <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>总发贴数: <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=发送一个短消息给billlang style="CURSOR: hand" 
            onclick="javascript:openScript('messanger.cgi?action=new&amp;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&amp;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&amp;TYPE_OF_SEARCH=username_search&amp;NAME_SEARCH=topictitle_search&amp;FORUMS_TO_SEARCH=20&amp;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&amp;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&amp;forum=20&amp;topic=75&amp;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&amp;forum=20&amp;topic=75&amp;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&amp;forum=20&amp;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>&nbsp;</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>发信站: 华南木棉BBS &nbsp;
                        <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>&nbsp;{<BR>&nbsp;//sgn=pow((-1),random(100));<BR>&nbsp;sgn=rand();<BR>&nbsp;rnd=sgn*(rand()%100);<BR>&nbsp;W[j][i]= 
                        rnd/100;//隐层权值初始化。<BR>&nbsp;}<BR>//randomize();<BR>&nbsp;{<BR>//sgn=pow((-1),random(1000));<BR>&nbsp;sgn=rand();<BR>&nbsp;rnd=sgn*(rand()%1000);<BR>&nbsp;sita[j]= 
                        rnd/1000;//中间层阈值初始化<BR>&nbsp;cout&lt;&lt;"sita"&lt;&lt;sita[j]&lt;&lt;endl;<BR>&nbsp;}<BR>//输出层权、阈值初始化//<BR>//randomize();<BR>for 
                        (int k=0;k&lt;ON;k++)<BR>for (int 
                        j=0;j&lt;HN;j++)<BR>{<BR>//sgn=pow((-1),random(1000));<BR>&nbsp; 
                        sgn=rand();<BR>&nbsp; rnd=sgn*(rand()%1000);<BR>&nbsp; 
                        V[k][j]=rnd/1000;//第m个样本输出层权值初始化<BR>}<BR>//randomize();<BR>&nbsp;{<BR>&nbsp;//sgn=pow((-1),random(10));<BR>&nbsp;sgn=rand();<BR>&nbsp;rnd=sgn*(rand()%10);<BR>&nbsp;gama[k]=rnd/10;//输出层阈值初始化<BR>&nbsp;cout&lt;&lt;"gama[k]"&lt;&lt;endl;<BR>&nbsp;}<BR>&nbsp;return 
                        1;
                        <P>}//子程序initial()结束
                        <P><BR>////////////////////////////////<BR>////第m个学习样本输入子程序///<BR>///////////////////////////////<BR>input_P(int 
                        m)<BR>{<BR>for (int 
                        i=0;i&lt;IN;i++)<BR>P[i]=Study_Data[m]-&gt;input[i];<BR>//获得第m个样本的数据<BR>//cout&lt;&lt;"第"&lt; 
                        //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&lt;m;k++)<BR>T[k]=Study_Data[m]-&gt;teach[k];<BR>//cout&lt;&lt;"第"&lt; 
                        //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&lt;HN;j++)<BR>sigma=0.0;<BR>for 
                        (i=0;i&lt;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&lt;ON;k++)<BR>sigma=0.0;<BR>for 
                        (int 
                        j=0;j&lt;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&lt;ON;output++) 
                        &nbsp;//output???<BR>&nbsp;for (int 
                        k=0;k&lt;ON;k++)<BR>&nbsp;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>&nbsp;for (int 
                        j=0;j&lt;HN;j++)<BR>&nbsp;sigma=0.0;<BR>&nbsp; &nbsp; 
                        for (int k=0;k&lt;ON;k++)<BR>&nbsp; &nbsp; 
                        &nbsp;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&lt;ON;k++)<BR>for 
                        (int j=0;j&lt;HN;j++)<BR>&nbsp;//cout&lt;&lt;"第"&lt; 
                        fprintf(fp,"第%d个样本时的输出层至隐层的权值为:%f\n",m,W[k][j<BR>]);<BR>&nbsp;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 + -