境界条件を含んだランダムウォークver2
以前、境界条件を含んだランダムウォークについて質問させていただきました。python3でかいてあったので、今回はこれをJuliaで書き直しましたが、エラーなしで動くのですが、結果がおかしく、pythonと全く同じように書いてあるはずなのですが、間違えがわかりません。
function main()
n = 3
count0=0
count1=0
count2=0
count3=0
count4=0
count5=0
count6=0
count7=0
stage = zeros(Int8,n,n,n)
stage[:,:,1]=[1 1 1;1 0 1;1 1 1]
stage[:,:,2]=[1 0 1;0 0 0;1 0 1]
stage[:,:,3]=[1 1 1;1 0 1;1 1 1]
#println(walk)
for itr in 1:10
walk = zeros(Int8,n,n,n)
walk[1,1,1]=1
for t in 0:10
if t==0
continue
else
next_walk = zeros(Int8,n,n,n)
number=rand(UnitRange{Int8}(1:6))
for x = 1:n, y = 1:n, z =1:n
x1 = ((x-1 + (n-1)) %n) + 1
x2 = ((x+1 + (n-1)) %n) + 1
y1 = ((y-1 + (n-1)) %n) + 1
y2 = ((y+1 + (n-1)) %n) + 1
z1 = ((z-1 + (n-1)) %n) + 1
z2 = ((z+1 + (n-1)) %n) + 1
if stage[x,y,z]== 0
continue
else
if walk[x,y,z]== 0
continue
else
if number == 1
if stage[x2,y,z]==1
next_walk[x2,y,z]=walk[x,y,z]
else
next_walk[x,y,z]=walk[x,y,z]
end
elseif number == 2
if stage[x,y2,z]==1
next_walk[x,y2,z]=walk[x,y,z]
else
next_walk[x,y,z]=walk[x,y,z]
end
elseif number == 3
if stage[x,y,z2]==1
next_walk[x,y,z2]=walk[x,y,z]
else
next_walk[x,y,z]=walk[x,y,z]
end
elseif number == 4
if stage[x1,y,z]==1
next_walk[x1,y,z]=walk[x,y,z]
else
next_walk[x,y,z]=walk[x,y,z]
end
elseif number == 5
if stage[x,y1,z]==1
next_walk[x,y1,z]=walk[x,y,z]
else
next_walk[x,y,z]=walk[x,y,z]
end
elseif number == 6
if stage[x,y,z1]==1
next_walk[x,y,z1]=walk[x,y,z]
else
next_walk[x,y,z]=walk[x,y,z]
end
end
end
end
walk = next_walk
end
if t == 0
if walk[1,1,1]==1
count0 += 1
else
continue
end
elseif t == 6
if walk[1,1,1]==1
count1 += 1
else
continue
end
elseif t == 36
if walk[1,1,1]==1
count2 += 1
else
continue
end
elseif t == 216
if walk[1,1,1]==1
count3 += 1
else
continue
end
else
continue
#1296,7776,46656
end
end
end
#println("t=0:",count0,"\n","t=6:",count1,"\n","t=36:",count2,"\n","t=216:",count3,"\n","t=1296:",count4,"\n","t=7776:",count5,"\n","t=46656:",count6,"\n")
end
println("t=0:",count0,"\n","t=6:",count1,"\n","t=36:",count2,"\n","t=216:",count3,"\n","t=1296:",count4,"\n","t=7776:",count5,"\n","t=46656:",count6,"\n")
end
main()
ランダムウォークの再帰性ができているか、t=0で今回はcount0=10になるはずなのですが、0になったままで、すこしおかしいのですが、どこが間違っているのでしょうか、、、。
結果(乱数なので一例)
t=0:0
t=6:3
t=36:0
t=216:0
t=1296:0
t=7776:0
t=46656:0
宜しくお願い致します。わかり次第自分も報告します。