Created
December 23, 2018 01:54
-
-
Save gangliao/68075b5dde3e93d910f848606b773143 to your computer and use it in GitHub Desktop.
ai for robtics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Given the list motions=[1,1] which means the robot | |
#moves right and then right again, compute the posterior | |
#distribution if the robot first senses red, then moves | |
#right one, then senses green, then moves right again, | |
#starting with a uniform prior distribution. | |
p=[0.2, 0.2, 0.2, 0.2, 0.2] | |
world=['green', 'red', 'red', 'green', 'green'] | |
measurements = ['red', 'green'] | |
motions = [1,1] | |
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)): | |
s = pExact * p[(i-U) % len(p)] | |
s = s + pOvershoot * p[(i-U-1) % len(p)] | |
s = s + pUndershoot * p[(i-U+1) % len(p)] | |
q.append(s) | |
return q | |
# | |
# ADD CODE HERE | |
# | |
p = sense(p, 'red') | |
p = move(p, 1) | |
p = sense(p, 'green') | |
p = move(p, 1) | |
print p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment