このチュートリアルのように、Python で自己組織化マップを作成しています。部分的には機能しますが、while ループの 1 つで奇妙な問題に遭遇しました。問題部分のコードは次のとおりです。
radius = 15
while radius > 2:
#print(radius)
while checkW < targetImage.w:
while checkH < targetImage.h:
#print(radius)
nodeDistance = math.sqrt(math.fabs(bmuW - checkW) * math.fabs(bmuW - checkW) + math.fabs(bmuH - checkH) * math.fabs(bmuH - checkH))
if(nodeDistance <= radius):
theta = math.exp((-1) * ((nodeDistance * nodeDistance) / (2 * radius * radius)))
targetImage.canvas[checkW, checkH].w0 = targetImage.canvas[checkW, checkH].w0 + theta * 0.1 * (inputR - targetImage.canvas[checkW, checkH].w0)
targetImage.canvas[checkW, checkH].w1 = targetImage.canvas[checkW, checkH].w1 + theta * 0.1 * (inputG - targetImage.canvas[checkW, checkH].w1)
targetImage.canvas[checkW, checkH].w2 = targetImage.canvas[checkW, checkH].w2 + theta * 0.1 * (inputB - targetImage.canvas[checkW, checkH].w2)
targetImage.canvas[checkW,checkH].r = int(targetImage.canvas[checkW, checkH].w0 * 255)
targetImage.canvas[checkW,checkH].g = int(targetImage.canvas[checkW, checkH].w1 * 255)
targetImage.canvas[checkW,checkH].b = int(targetImage.canvas[checkW, checkH].w2 * 255)
checkH = checkH + 1
checkH = 0
checkW = checkW + 1
radius = radius - 1
#print(radius)
radius
最初は各ピクセル反復で 15 に設定されており、半径に応じて r、g、b 値を設定し、それを減らして新しい r、g、b 値を設定するという考え方です。半径の計算はアルゴリズムとは異なりradius = radius - 1
ますが、単純なものでテストしたかったことに注意してください。
私の問題は、1 番目と 3 番目print(radius)
で期待値 15,14,13,12 などを取得することです。しかし、中間では常に初期値である 15 を取得します。radius
他のポイントでは変化するのに、その時点では変化しない理由がわかりません。どんな助けでも大歓迎です。