Generalized Uniform Distribution
# Modify your code to create probability vectors, p, of arbitrary
# size, n. Use n=5 to verify that your new solution matches
# the previous one.
p=[]
n=5
for i in range (n):
p.append(1./n)
print p
pHit and pMiss
#Write code that outputs p after multiplying each entry
#by pHit or pMiss at the appropriate places. Remember that
#the red cells 1 and 2 are hits and the other green cells
#are misses.
p=[0.2,0.2,0.2,0.2,0.2]
pHit = 0.6
pMiss = 0.2
p[0] = p[0]*pMiss
p[1] = p[1]*pHit
p[2] = p[2]*pHit
p[3] = p[3]*pMiss
p[4] = p[4]*pMiss
print p
Sum of Probabilities
#Modify the program to find and print the sum of all
#the entries in the list p.
p=[0.2, 0.2, 0.2, 0.2, 0.2]
pHit = 0.6
pMiss = 0.2
p[0]=p[0]*pMiss
p[1]=p[1]*pHit
p[2]=p[2]*pHit
p[3]=p[3]*pMiss
p[4]=p[4]*pMiss
# Enter your code below
print sum(p)
Sense Function
#Modify the code below so that the function sense, which
#takes p and Z as inputs, will output the NON-normalized
#probability distribution, q, after multiplying the entries
#in p by pHit or pMiss according to the color in the
#corresponding cell in world.
p=[0.2, 0.2, 0.2, 0.2, 0.2]
world=['green', 'red', 'red', 'green', 'green']
Z = 'red'
pHit = 0.6
pMiss = 0.2
def sense(p, Z):
q = [ ]
for i in range(len(p)):
hit = (Z == world[i])
q.append(p[i] * (hit * pHit + (1-hit) * pMiss))
return q
print sense(p,Z)
Hiç yorum yok:
Yorum Gönder