• API
• FAQ
• Tools
• Trends
• Archive
daily pastebin goal
24%
SHARE
TWEET

# Untitled

nekosune Mar 3rd, 2012 112 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. colors = [['red', 'green', 'green', 'red' , 'red'],
2.           ['red', 'red', 'green', 'red', 'red'],
3.           ['red', 'red', 'green', 'green', 'red'],
4.           ['red', 'red', 'red', 'red', 'red']]
5.
6. measurements = ['green', 'green', 'green' ,'green', 'green']
7.
8.
9. motions = [[0,0],[0,1],[1,0],[1,0],[0,1]]
10.
11. sensor_right = 0.7
12.
13. p_move = 0.8
14.
15. def show(p):
16.     for i in range(len(p)):
17.         print p[i]
18.
19. #DO NOT USE IMPORT
20. #ENTER CODE BELOW HERE
21. #ANY CODE ABOVE WILL CAUSE
23. #INCORRECT
24. #INCORRECT
25. p = []
26. sensor_wrong=1.-sensor_right
27.
28. def sense(p, Z):
29.     q=[]
30.     for i in range(len(p)):
31.         r=[]
32.         for j in range(len(p[i])):
33.             hit = (Z == colors[i][j])
34.             r.append(p[i][j] * (hit * sensor_right + (1-hit) * sensor_wrong))
35.         q.append(r)
36.     s = 0
37.     for i in q:
38.         s+=sum(i)
39.
40.     for i in range(len(q)):
41.         for j in range(len(q[i])):
42.             q[i][j]=q[i][j]/s
43.     return q
44.
45. def move(p, U,V):
46.     q = []
47.     for i in range(len(p)):
48.         r=[]
49.         for j in range(len(p[i])):
50.             s = p_move * p[(i-U) % len(p)][(j-V) % len(p[i])]
51.             p_stationary=1.-p_move
52.             s = s + (p_stationary) * p[i % len(p)][j % len(p[i])]
53.             r.append(s)
54.         q.append(r)
55.     return q
56.
57. def Norm():
58.     p=[]
59.     norm = len(colors)*len(colors[0])
60.     norm=1./norm
61.     for i in range(len(colors)):
62.         r=[]
63.         for j in range(len(colors[i])):
64.             r.append(norm)
65.         p.append(r)
66.     return p
67.
68. p=Norm()
69. for i in range(len(motions)):
70.     p=move(p,motions[i][0],motions[i][1])
71.     p=sense(p,measurements[i])
72.
73.
74.
75.
76.
77.
78.
79. #Your probability array must be printed
80. #with the following code.
81.
82. show(p)
RAW Paste Data
Top