我正在用 numpy 编程一个神经域,对于 100*100 个神经元的映射,我需要管理一个 10000*10000 连接映射。
所以我用meshgrid创建了我的连接图,并尝试应用墨西哥帽子功能的改编。在这里,你有你可以尝试的代码:如果你输入taille = 60
or taille = 70
(神经图的宽度),它会工作(在我的电脑上,没问题)但是,如果你尝试使用taille = 100
,你会得到一个 MemoryError。
import numpy as np
def connection_map4(width, se1, se2, K, inh):
x = np.arange(0, width**2, 1)
y = np.arange(0, width**2, 1)
X,Y = np.meshgrid(x, y)
print "Meshgrid cree"
A1 = 1.0 + inh
A2 = inh
# exp(|x-xc|/b + |y-yc|) -> Mexican Hat equation
# 2D/1D transformation relation: i = width.y + x
# ligne = (X/witdh - Y/width)**2
ligne = (X-Y)/width ## empirically, it's the division that doesn't pass.
print "avant carre"
ligne *= ligne
print "ligne"
colonne = (X%width-Y%width)**2
print "colonne"
M1 = A1*np.exp(-( (colonne)/(2*se1**2) + (ligne)/(2*se2**2) ) )
print "Premiere operation finie"
M2 = -A2*np.exp(-( (colonne)/(2*(K*se1)**2) + (ligne)/(2*(K*se2)**2) ) )
print "Seconde operation finie"
return(M1+M2)
taille = 100
connection_map4(taille, 7.5, 4.0, 2.0, 2.0)
根据经验,经过一些尝试调试,我已经将meshgrid上的每个操作分开了,似乎是除法和取模没有通过。
有没有解决方案来进行这种划分?我真的不想使用循环并减慢计算速度。