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

📄 『 高性能计算 』 - 神经网络遗传算法---绝对好东西.htm

📁 遗传算法matlab实现 用遗传算法优化神经网络算法的实现
💻 HTM
📖 第 1 页 / 共 5 页
字号:
                   hits[ total++ ] = 0; /* 0 for negative example */ 
                  <BR>&nbsp; &nbsp;} <BR>&nbsp;fclose( fd ); <BR>&nbsp;return 
                  (0) ; <BR>} 
                  <BR>/*-----------------------------------------------------------------------*\ 
                  <BR>| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; | <BR>| &nbsp; best_pop &nbsp;- &nbsp;Find the 
                  population with the best solution &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; | <BR>| &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 
                  <BR>\*-----------------------------------------------------------------------*/ 
                  <BR>int best_pop() <BR>{ <BR>&nbsp;int i, p, best = 0; 
                  <BR>&nbsp;for ( i = 0 ; i &lt; POPS ; i++ ) <BR>&nbsp; 
                  &nbsp;if ( score[0] &gt; best ) <BR>&nbsp; &nbsp; &nbsp;{ 
                  <BR>&nbsp; &nbsp; &nbsp; &nbsp;best = score[0]; <BR>&nbsp; 
                  &nbsp; &nbsp; &nbsp;p = i; <BR>&nbsp; &nbsp; &nbsp;} 
                  <BR>&nbsp;return(p); <BR>} 
                  <BR>/*-----------------------------------------------------------------------*\ 
                  <BR>| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; | <BR>| &nbsp; charmap &nbsp;- &nbsp;draw a charmap 
                  showing the NN's behaviour &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; | <BR>| &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 
                  <BR>\*-----------------------------------------------------------------------*/ 
                  <BR>charmap( p ) <BR>&nbsp; &nbsp; int p; <BR>{ <BR>&nbsp;int 
                  i, j, result; <BR>&nbsp;vector x; <BR>&nbsp;apply( p ,0 ); 
                  <BR>&nbsp;for ( i = 0 ; i &lt; 350 ; i++ ) <BR>&nbsp; &nbsp;{ 
                  <BR>&nbsp; &nbsp; &nbsp;for ( j = 0 ; j &lt; 350 ; j++ ) 
                  <BR>&nbsp; &nbsp; &nbsp; &nbsp;if ( (i%12==0) &amp;&amp; 
                  (j%6==0) ) <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ <BR>&nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x.p[0] = j/1000.0; 
                  <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x.p[1] = 
                  i/1000.0; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result 
                  = net( x ); <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp;printf("%c", (result==1 ? '+' : '.' ) ); <BR>&nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp;} <BR>&nbsp; &nbsp; &nbsp;if ( 
                  i%12==0 ) printf("\n"); <BR>&nbsp; &nbsp;} <BR>} 
                  <BR>/*-----------------------------------------------------------------------*\ 
                  <BR>| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; | <BR>| &nbsp; make_output &nbsp;- &nbsp;create the 
                  output file &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp;| <BR>| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; | 
                  <BR>\*-----------------------------------------------------------------------*/ 
                  <BR>make_output(p) <BR>&nbsp; &nbsp; int p; <BR>{ 
                  <BR>&nbsp;int i, j, result, oldresult, start; <BR>&nbsp;vector 
                  x; <BR>&nbsp;char* FileName = "/tmp/nn-output"; <BR>&nbsp;FILE 
                  *fd; <BR>&nbsp;printf("\n%s\n", (score[p][0]!=total ? 
                  "Failed." : "Success" ) ); <BR>&nbsp;apply( p, 0 ); 
                  <BR>&nbsp;printf("Writing output file...\n"); <BR>&nbsp;/* 
                  Open the file &nbsp;*/ <BR>&nbsp;if ( (fd = 
                  fopen(FileName,"w")) == NULL ) <BR>&nbsp; &nbsp;{ <BR>&nbsp; 
                  &nbsp; &nbsp;printf ("Can't open output file"); <BR>&nbsp; 
                  &nbsp; &nbsp;exit(10); <BR>&nbsp; &nbsp;} <BR>&nbsp;/* line 
                  scheme */ <BR>&nbsp;for ( i = 0 ; i &lt; 350 ; i++ ) &nbsp;/* 
                  Scan horizontally */ <BR>&nbsp; &nbsp;{ <BR>&nbsp; &nbsp; 
                  &nbsp;result = 0; <BR>&nbsp; &nbsp; &nbsp;for ( j = 0 ; j &lt; 
                  350 ; j++ ) <BR>&nbsp; &nbsp; &nbsp; &nbsp;{ <BR>&nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp;oldresult = result; <BR>&nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp;x.p[0] = j/1000.0; <BR>&nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp;x.p[1] = i/1000.0; <BR>&nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp;result = net( x ); <BR>&nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp;if ( oldresult != result ) <BR>&nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fprintf( fd, "%d %d ", j, i 
                  ); <BR>&nbsp; &nbsp; &nbsp; &nbsp;} <BR>&nbsp; &nbsp;} 
                  <BR>&nbsp;for ( j = 0 ; j &lt; 350 ; j++ ) &nbsp;/* Scan 
                  vertically */ <BR>&nbsp; &nbsp;{ <BR>&nbsp; &nbsp; 
                  &nbsp;result = 0; <BR>&nbsp; &nbsp; &nbsp;for ( i = 0 ; i &lt; 
                  350 ; i++ ) <BR>&nbsp; &nbsp; &nbsp; &nbsp;{ <BR>&nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp;oldresult = result; <BR>&nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp;x.p[0] = j/1000.0; <BR>&nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp;x.p[1] = i/1000.0; <BR>&nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp;result = net( x ); <BR>&nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp;if ( oldresult != result ) <BR>&nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fprintf( fd, "%d %d ", j, i 
                  ); <BR>&nbsp; &nbsp; &nbsp; &nbsp;} <BR>&nbsp; &nbsp;} 
                  <BR>&nbsp;fclose( fd ); <BR>&nbsp;printf("Done!\n"); <BR>} 
                  <BR>/*-----------------------------------------------------------------------*\ 
                  <BR>| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; | <BR>| &nbsp;Main &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; | <BR>| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                  &nbsp; &nbsp; &nbsp; | 
                  <BR>\*-----------------------------------------------------------------------*/ 
                  <BR>main() <BR>{ <BR>&nbsp;int generation, j, p, best, done = 
                  0; <BR>&nbsp;float px, py, px1, py1; <BR>&nbsp;randomize(); 
                  <BR>&nbsp;get_data(); &nbsp;/* Read input from file */ 
                  <BR>&nbsp;make_initial_population(); <BR>&nbsp;calc_score(); 
                  <BR>&nbsp;sort_population(); <BR>&nbsp;/* Educate the net */ 
                  <BR>&nbsp;generation = 0; <BR>&nbsp;while ( (done != 1 ) 
                  &amp;&amp; ( generation++ &lt; SESSIONS ) ) <BR>&nbsp; &nbsp;{ 
                  <BR>&nbsp; &nbsp; &nbsp;make_next_generation( generation ); 
                  <BR>&nbsp; &nbsp; &nbsp;p = best_pop(); <BR>&nbsp; &nbsp; 
                  &nbsp;/* Show a charmap every 50 generations */ <BR>&nbsp; 
                  &nbsp; &nbsp;if ( generation % 50 == 0 ) charmap(p); 
                  <BR>&nbsp; &nbsp; &nbsp;if ( score[p][0] == total ) <BR>&nbsp; 
                  &nbsp; &nbsp; &nbsp;done = 1; <BR>&nbsp; &nbsp;} <BR>&nbsp;/* 
                  return results */ <BR>&nbsp;make_output(p); <BR>} <BR>
                  <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
                    <TBODY>
                    <TR>
                      <TD><BR><BR>------------------------------------------------------------------------------------<BR>简单就好</TD></TR></TBODY></TABLE><BR></FONT></FONT></TD>
                <TD width=16></TD></TR></TBODY></TABLE></TD></TR>
        <TR>
          <TD class=bottomline vAlign=bottom bgColor=#f2f8ff>
            <HR width="100%" color=#000000 SIZE=1>

            <TABLE cellSpacing=0 cellPadding=0 width="100%">
              <TBODY>
              <TR>
                <TD vAlign=bottom><FONT color=#555555>&nbsp;<A title=编辑这个贴子 
                  href="http://www.lasg.ac.cn/cgi-bin/forum/postings.cgi?action=edit&amp;forum=4&amp;topic=1463&amp;postno=1"><IMG 
                  height=15 src="『 高性能计算 』 - 神经网络遗传算法---绝对好东西.files/edit.gif" 
                  width=16 border=0>编辑</A> <A title=删除这个回复 
                  href="http://www.lasg.ac.cn/cgi-bin/forum/postings.cgi?action=directdel&amp;forum=4&amp;topic=1463&amp;postno=1"><IMG 
                  height=16 
                  src="『 高性能计算 』 - 神经网络遗传算法---绝对好东西.files/a_delete.gif" width=52 
                  align=absMiddle border=0></A> <IMG height=15 alt=发贴时间 
                  src="『 高性能计算 』 - 神经网络遗传算法---绝对好东西.files/posttime.gif" 
                  width=16>2004/04/27 10:47am <IMG height=15 alt="" 
                  src="『 高性能计算 』 - 神经网络遗传算法---绝对好东西.files/ip.gif" width=13>IP: 
                  已设置保密</FONT></TD>
                <TD vAlign=bottom align=right width=110 nowarp></TD></FORM>
                <TD vAlign=bottom align=right width=4></TD></TR></TBODY></TABLE><IMG 
            height=4 src="" width=0><BR></TD></TR></TBODY></TABLE></TD>
    <TD width=1 bgColor=#000000 height=24></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="97%" align=center bgColor=#000000 
border=0>
  <TBODY>
  <TR>
    <TD height=1></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="97%" align=center border=0>
  <TBODY>
  <TR>
    <TD width=1 bgColor=#000000 height=24></TD>
    <TD bgColor=#e8f4ff>
      <TABLE cellSpacing=0 cellPadding=4 width="100%" bgColor=#e8f4ff>
        <TBODY>
        <TR>
          <TD vAlign=top width=178 bgColor=#e8f4ff rowSpan=2><IMG height=4 
            src="" width=0><BR>
            <TABLE cellSpacing=0 cellPadding=0 border=0>
              <TBODY>
              <TR>
                <TD width=30>&nbsp;<IMG height=15 alt=该用户目前不在线 
                  src="『 高性能计算 』 - 神经网络遗传算法---绝对好东西.files/offline1.gif" 
                width=15></TD>
                <TD>
                  <TABLE 
                    style="FILTER: glow(color=#996699,direction=135)">&nbsp;<FONT 
                    color=#ffffff><B>海阔天空</B></FONT>&nbsp;
                    <TBODY></TBODY></TABLE></TD>
                <

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -