📄 『 高性能计算 』 - 神经网络遗传算法---绝对好东西.htm
字号:
hits[ total++ ] = 0; /* 0 for negative example */
<BR> } <BR> fclose( fd ); <BR> return
(0) ; <BR>}
<BR>/*-----------------------------------------------------------------------*\
<BR>|
| <BR>| best_pop - Find the
population with the best solution
| <BR>|
|
<BR>\*-----------------------------------------------------------------------*/
<BR>int best_pop() <BR>{ <BR> int i, p, best = 0;
<BR> for ( i = 0 ; i < POPS ; i++ ) <BR>
if ( score[0] > best ) <BR> {
<BR> best = score[0]; <BR>
p = i; <BR> }
<BR> return(p); <BR>}
<BR>/*-----------------------------------------------------------------------*\
<BR>|
| <BR>| charmap - draw a charmap
showing the NN's behaviour
| <BR>|
|
<BR>\*-----------------------------------------------------------------------*/
<BR>charmap( p ) <BR> int p; <BR>{ <BR> int
i, j, result; <BR> vector x; <BR> apply( p ,0 );
<BR> for ( i = 0 ; i < 350 ; i++ ) <BR> {
<BR> for ( j = 0 ; j < 350 ; j++ )
<BR> if ( (i%12==0) &&
(j%6==0) ) <BR> { <BR>
x.p[0] = j/1000.0;
<BR> x.p[1] =
i/1000.0; <BR> result
= net( x ); <BR>
printf("%c", (result==1 ? '+' : '.' ) ); <BR>
} <BR> if (
i%12==0 ) printf("\n"); <BR> } <BR>}
<BR>/*-----------------------------------------------------------------------*\
<BR>|
| <BR>| make_output - create the
output file
| <BR>|
|
<BR>\*-----------------------------------------------------------------------*/
<BR>make_output(p) <BR> int p; <BR>{
<BR> int i, j, result, oldresult, start; <BR> vector
x; <BR> char* FileName = "/tmp/nn-output"; <BR> FILE
*fd; <BR> printf("\n%s\n", (score[p][0]!=total ?
"Failed." : "Success" ) ); <BR> apply( p, 0 );
<BR> printf("Writing output file...\n"); <BR> /*
Open the file */ <BR> if ( (fd =
fopen(FileName,"w")) == NULL ) <BR> { <BR>
printf ("Can't open output file"); <BR>
exit(10); <BR> } <BR> /* line
scheme */ <BR> for ( i = 0 ; i < 350 ; i++ ) /*
Scan horizontally */ <BR> { <BR>
result = 0; <BR> for ( j = 0 ; j <
350 ; j++ ) <BR> { <BR>
oldresult = result; <BR>
x.p[0] = j/1000.0; <BR>
x.p[1] = i/1000.0; <BR>
result = net( x ); <BR>
if ( oldresult != result ) <BR>
fprintf( fd, "%d %d ", j, i
); <BR> } <BR> }
<BR> for ( j = 0 ; j < 350 ; j++ ) /* Scan
vertically */ <BR> { <BR>
result = 0; <BR> for ( i = 0 ; i <
350 ; i++ ) <BR> { <BR>
oldresult = result; <BR>
x.p[0] = j/1000.0; <BR>
x.p[1] = i/1000.0; <BR>
result = net( x ); <BR>
if ( oldresult != result ) <BR>
fprintf( fd, "%d %d ", j, i
); <BR> } <BR> }
<BR> fclose( fd ); <BR> printf("Done!\n"); <BR>}
<BR>/*-----------------------------------------------------------------------*\
<BR>|
| <BR>| Main
| <BR>|
|
<BR>\*-----------------------------------------------------------------------*/
<BR>main() <BR>{ <BR> int generation, j, p, best, done =
0; <BR> float px, py, px1, py1; <BR> randomize();
<BR> get_data(); /* Read input from file */
<BR> make_initial_population(); <BR> calc_score();
<BR> sort_population(); <BR> /* Educate the net */
<BR> generation = 0; <BR> while ( (done != 1 )
&& ( generation++ < SESSIONS ) ) <BR> {
<BR> make_next_generation( generation );
<BR> p = best_pop(); <BR>
/* Show a charmap every 50 generations */ <BR>
if ( generation % 50 == 0 ) charmap(p);
<BR> if ( score[p][0] == total ) <BR>
done = 1; <BR> } <BR> /*
return results */ <BR> 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> <A title=编辑这个贴子
href="http://www.lasg.ac.cn/cgi-bin/forum/postings.cgi?action=edit&forum=4&topic=1463&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&forum=4&topic=1463&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> <IMG height=15 alt=该用户目前不在线
src="『 高性能计算 』 - 神经网络遗传算法---绝对好东西.files/offline1.gif"
width=15></TD>
<TD>
<TABLE
style="FILTER: glow(color=#996699,direction=135)"> <FONT
color=#ffffff><B>海阔天空</B></FONT>
<TBODY></TBODY></TABLE></TD>
<
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -