ただいま無限ループ中....
無限ループは脱出したものの全然ショートカットの効果が感じられない。なぜ?
' SYNC model SW sim program
' started 2005/05/14
' by Hideki H.
#prompt
'#console
'初期設定
dim table_original[21,21] as single
dim table_temp[21,21] as single
dim retina_model[3,3] as single
dim i,j,k,l,dummy,yes_no as integer
dim x,y,z as single
dim mean_table,var_table as single
dim sw_table[20,20,2]
'table_original:一様乱数初期化サブルーチン
sub randam_table()
dim mean_value, var_value as single '乱数の最大値
input "テーブル初期値の平均値";mean_value
input "テーブル初期値の分散";var_value
for i=0 to 21
for j=0 to 21
if i=0 or j=0 then
table_original[i,j] = 0
else
table_original[i,j] = bell_rand(mean_value,var_value)
endif
next
next
endsub
'table_original:特定の値による初期化サブルーチン(メインで選択)
sub specified_table()
for i=0 to 21
for j=0 to 21
if i>10 and i<13 and j>10 and j<13 then
table_original[i,j] = 3
else
table_original[i,j] = 0
endif
next
next
endsub
' フィルター部分の定義:正方格子
sub fil_initial()
dim periphe_value, center_divident as single 'フィルターの周辺値、中央の分母
input "フィルターの周辺値";periphe_value
input "漸増させる分母";center_divident
for i=1 to 3
for j=1 to 3
retina_model[i,j]=periphe_value
next
next
retina_model[2,2]=center_divident
endsub
'正規分布乱数サブルーチン:引数c1,c2は、一様乱数
'[参照]wikipedia:乱数列:
'http://ja.wikipedia.org/wiki/%E4%B9%B1%E6%95%B0#.E6.AD.A3.E8.A6.8F.E4.B9.B1.E6.95.B0
function bell_rand(mm,vv) as single
'mm=平均値、vv=分散
dim d,e as single
d=Sqr(-2 * Log(1-Rnd())/Log(10))
e=2*3.1415926535897932*Rnd()
bell_rand=d*Cos(e)*vv+mm
't=sqrt(-2.0 * log(1-rnd()));
'u=2*PI*rnd();
'r1=t*cos(u) ; r2=t*sin(u);
end function
'スモールワールドリンク生成サブルーチン
'つなぎ変えでなく、ショートカットを追加する
'とりあえず最大でもひとつのセルにひとつリンク
'相互リンクとする
'sw_table[x_n,y_n,2]=対象セルとリンクしているセルのxよy(1=x、2=y)
sub sw_link(n) as single
'n=生成するリンクの数
dim x_n1,y_n1,x_n2,y_n2 as single
for i=1 to n
do
do
x_n1=Int(Rnd()*20+1)
loop until x_n1>0 and x_n1<21
do
y_n1=Int(Rnd()*20+1)
loop until y_n1>0 and y_n1<21
if sw_table[x_n1,y_n1,1]=0 then
do
do
x_n2=Int(Rnd()*20+1)
loop until x_n2>0 and x_n2<21
do
y_n2=Int(Rnd()*20+1)
loop until y_n2>0 and y_n2<21
loop while x_n1=x_n2 and y_n1=y_n2
print "(";x_n1;",";y_n1;")-(";x_n2;",";y_n2;")"
sw_table[x_n1,y_n1,1]=x_n2
sw_table[x_n1,y_n1,2]=y_n2
sw_table[x_n2,y_n2,1]=x_n1
sw_table[x_n2,y_n2,2]=y_n1
exit do
end if
loop
next
end sub
'table_original:表示サブルーチン
Sub p_table()
cls
for i=1 to 20
for j=1 to 20
x = Int(table_original[i,j])
Locate i*3+5,j+5
color x
print x;
color 7
next
next
endsub
'table_original:時間を進める、フィルターを一度かける
sub dev_table()
dim mean_temp,var_temp as single
mean_table=0
var_table=0
for i=1 to 20
for j=1 to 20
table_temp[i,j]=0
next
next
for i=1 to 20
for j=1 to 20
table_temp[i,j]=table_original[i,j]+(8-table_original[i,j])/retina_model[2,2]+table_temp[i,j]
If table_original[i,j]>=7 then
table_temp[i,j]=-10
table_temp[i-1,j-1]=table_temp[i-1,j-1]+retina_model[1,1]
table_temp[i-1,j]=table_temp[i-1,j]+retina_model[1,2]
table_temp[i-1,j+1]=table_temp[i-1,j+1]+retina_model[1,3]
table_temp[i,j-1]=table_temp[i,j-1]+retina_model[2,1]
table_temp[i,j+1]=table_temp[i,j+1]+retina_model[2,3]
table_temp[i+1,j-1]=table_temp[i+1,j-1]+retina_model[3,1]
table_temp[i+1,j]=table_temp[i+1,j]+retina_model[3,2]
table_temp[i+1,j+1]=table_temp[i+1,j+1]+retina_model[3,3]
if sw_table[i,j,1]>0 then
table_temp[sw_table[i,j,1],sw_table[i,j,2]]=table_temp[sw_table[i,j,1],sw_table[i,j,2]]+retina_model[3,3]
' print "(";i;",";j;")-(";sw_table[i,j,1];",";sw_table[i,j,2];")"
end if
End If
next
next
for i=1 to 20
for j=1 to 20
if table_temp[i,j]<0 then
table_original[i,j]=0
else
table_original[i,j]=table_temp[i,j]
endif
mean_temp=mean_temp+table_original[i,j]
next
next
mean_table=mean_temp/400
for i=1 to 20
for j=1 to 20
var_temp=var_temp+(table_original[i,j]-mean_table)^2
next
next
var_table=Sqr(var_temp/400)
endsub
'メイン
' 初期化はどちらか選択
Randomize
do
print "初期値はランダムにとりますか?サブルーチン指定の特定の値にしますか?"
input "(0=ランダム,それ以外特定)";yes_no
if yes_no=0 then
randam_table()
else
specified_table()
end if
do
print "ランダムリンクを加えますか?"
input "(0=生成しない,1以上200未満=生成するリンクの数)";yes_no
loop until yes_no>=0 and yes_no<200
if yes_no>0 then
sw_link(Int(yes_no))
end if
fil_initial()
p_table()
print
print
input "試行数";k
for l=1 to k
dev_table()
p_table()
print
print
print "試行回数=";l;" 平均値=";mean_table;" 分散値=";var_table
' Sleep(500)
next
input "終了しました。続けますか?(1=終了)";dummy
loop until dummy=1
end