22. 非精确移动函数
非精确移动函数
Question:
Start Quiz:
#Modify the move function to accommodate the added
#probabilities of overshooting or undershooting
#the intended destination.
p=[0, 1, 0, 0, 0]
world=['green', 'red', 'red', 'green', 'green']
measurements = ['red', 'green']
pHit = 0.6
pMiss = 0.2
pExact = 0.8
pOvershoot = 0.1
pUndershoot = 0.1
def sense(p, Z):
q=[]
for i in range(len(p)):
hit = (Z == world[i])
q.append(p[i] * (hit * pHit + (1-hit) * pMiss))
s = sum(q)
for i in range(len(q)):
q[i] = q[i] / s
return q
def move(p, U):
q = []
for i in range(len(p)):
q.append(p[(i-U)%len(p)])
return q
print move(p, 1)
Solution:
INSTRUCTOR NOTE:
切勿修改末尾的 print 语句。你可以添加额外的 print 语句来测试代码,但在点击提交之前一定要添加评论。否则自动评分可能会拒绝你的解决方案。