+ - する条件が >= <= を含めて違っていたようなので、勝手に変更して再度メモしておく
import numpy as np
# [[Rs Rg]
# [Gs Gg]
# [Bs Bg]] という形の行列
weight=np.random.randint(-10,10,size=(3,2))
# 順に赤、黄、青
color_list=np.array([[100,0,0],[100,100,0],[0,100,50]])
total = 50
for i in range(total):
color=np.random.randint(0,3)
colors=color_list[color]
score=colors@weight
stop_score,go_score=score
change_idx=np.random.choice(list(np.where(np.array(colors)!=0))[0])
if color<2:
if stop_score>0 and go_score>0:
weight[:,1][change_idx]-=1
elif stop_score<=0 and go_score>0:
weight[:,0][change_idx]+=1
weight[:,1][change_idx]-=1
elif stop_score<=0 and go_score<=0:
weight[:,0][change_idx]+=1
else:
if stop_score>0 and go_score>0:
weight[:,0][change_idx]-=1
elif stop_score>0 and go_score<=0:
weight[:,0][change_idx]-=1
weight[:,1][change_idx]+=1
elif stop_score<=0 and go_score<=0:
weight[:,1][change_idx]+=1
print(weight)
color_name=[‘RED’,’YELLO’,’BLUE’]
for i in range(3):
color=color_list[i]
score=color@weight
print(color_name[i])
if score[0]>0 and score[1]<=0:
print(‘stop’)
elif score[0]<=0 and score[1]>0:
print(‘go’)
最後の判定は成立したときにのみ表示されるのだが、やはり50近く試みないと安定しないようだ。