所以我想在我的计算机上建立一个耦合的映射晶格
耦合映射晶格(CML)由以下等式给出:
其中,函数f(Xn)是一个逻辑图:
对于该CML,x值为0-1,r=4
注意:“n”可以被认为是时间,“i”可以被认为是空间
我花了很多时间来理解迭代,并提出了如下代码,但是我不确定这是否是迭代这个等式的正确代码
注意:我使用了2d numpy数组,其中行是'n',列是'I',从代码中可以明显看出
基本上,我想开发一个代码来模拟这个等式,下面是我的看法
不要直接跳转到代码,如果不费心先看一下方程式,就无法理解发生了什么。
import numpy as np
import matplotlib.pyplot as plt
'''The 4 definitions created below are actually similar and only vary in their indexings. These 4
have been created only because of the if conditions I have put in the for loop '''
def logInit(r,x):
y[n,0]=r*x[n,0]*(1-x[n,0])
return y[n,0]
def logPresent(r,x):
y[n,i]=r*x[n,i]*(1-x[n,i])
return y[n,i]
def logLast(r,x):
y[n,L-1]=r*x[n,L-1]*(1-x[n,L-1])
return y[n,L-1]
def logNext(r,x):
y[n,i+1]=r*x[n,i+1]*(1-x[n,i+1])
return y[n,i+1]
def logPrev(r,x):
y[n,i-1]=r*x[n,i-1]*(1-x[n,i-1])
return y[n,i-1]
# 2d array with 4 row, 3 col. I created this because I want to store the evaluated values of log
function into this y[n,i] array
y=np.ones(12).reshape(4,3)
# creating an array of random numbers between 0-1 with 4 rows 3 columns
np.random.seed(0)
x=np.random.random((4,3))
L=3
r=4
eps=0.5
for n in range(3):
for i in range(L):
if i==0:
x[n+1,i]=(1-eps)*logPresent(r,x) + 0.5*eps*(logLast(r,x)+logNext(r,x))
elif i==L-1:
x[n+1,i]=(1-eps)*logPresent(r,x) + 0.5*eps*(logPrev(r,x) + logInit(r,x))
elif i > 0 and i < L - 1:
x[n+1,i]=(1-eps)*logPresent(r,x) + 0.5*eps*(logPrev(r,x) +logNext(r,x))
print(x)
这确实给出了一个输出。这是:
[[0.5488135 0.71518937 0.60276338]
[0.94538775 0.82547604 0.64589411]
[0.43758721 0.891773 0.96366276]
[0.38344152 0.79172504 0.52889492]]
[[0.5488135 0.71518937 0.60276338]
[0.94538775 0.82547604 0.92306303]
[0.2449672 0.49731638 0.96366276]
[0.38344152 0.79172504 0.52889492]]
[[0.5488135 0.71518937 0.60276338]
[0.94538775 0.82547604 0.92306303]
[0.2449672 0.49731638 0.29789622]
[0.75613708 0.93368134 0.52889492]]
但我很确定这不是我想要的
如果你能想出一个正确的方法,用代码迭代和循环CML方程?建议我必须做的改变。非常感谢
您必须考虑模拟该等式所需的迭代和循环。这可能会很乏味,但这是唯一可以建议我修改代码的方法。
我觉得你的计算很好。通过沿空间维度使用矢量化和重用中间结果
y
,可以提高速度。我对你的程序做了一点调整,但本质上和以前一样。对我来说,结果似乎是可信的。图像显示了第一行中的随机初始向量,随着时间的推移(从上到下),耦合开始发挥作用,形成小岛和图案相关问题 更多 >
编程相关推荐