2017-09-20

Sep 20 In-Class Exercise.

Hey Everyone,
Post your solutions to the Sep 20 In-class Exercise to this thread.
Best,
Chris
Hey Everyone, Post your solutions to the Sep 20 In-class Exercise to this thread. Best, Chris

-- Sep 20 In-Class Exercise
Probability by sum. -At initial state, we have 2 options. -Sum up the current square value with each adjacent value -Divide each total value with the sum from 1 to 9 which is 45 -Pick the next square based on the percentage
Or use 9 as the main value then calculate probability by 1-(adjacent value/9)
(Edited: 2017-09-20)
Probability by sum. -At initial state, we have 2 options. -Sum up the current square value with each adjacent value -Divide each total value with the sum from 1 to 9 which is 45 -Pick the next square based on the percentage Or use 9 as the main value then calculate probability by 1-(adjacent value/9)

-- Sep 20 In-Class Exercise
While in current square,
  total = reduce(lambda a, n: a + n.val, neighbours, 0)
  for neighbour in neighbours:
    neighbour.prob = neighbour.val / total
(Edited: 2017-09-20)
While in current square, total = reduce(lambda a, n: a + n.val, neighbours, 0) for neighbour in neighbours: neighbour.prob = neighbour.val / total

-- Sep 20 In-Class Exercise
Resource Description for IMG_9712.JPG Rodion Yaryy
// start at 1
import random
>>> random.choice('4' * 4 + '2' * 2)
'4'
>>> random.choice('1' * 1 + '5' * 5 + '7' * 7)
'5'
>>> random.choice('4'*4 + '8'*8 + '6'*6 +'2'*2 )
'6'
>>> random.choice('3'*3 + '5'*5 +'9'*9 )
'9'
// Goal Reached
(Edited: 2017-09-20)
((resource:IMG_9712.JPG|Resource Description for IMG_9712.JPG)) Rodion Yaryy // start at 1 import random >>> random.choice('4' * 4 + '2' * 2) '4' >>> random.choice('1' * 1 + '5' * 5 + '7' * 7) '5' >>> random.choice('4'*4 + '8'*8 + '6'*6 +'2'*2 ) '6' >>> random.choice('3'*3 + '5'*5 +'9'*9 ) '9' // Goal Reached

-- Sep 20 In-Class Exercise
 Suggested Algorithm: 
 Add all adjacent numbers to current position and divide each number by the total = 
 probability of moving to that square; if not adjacent, not a possible move so set to 0.000:
 
 7	8	9
 4	5	6
 1@	2	3
 
 Neighbors: 4 + 2 = 6
 4/6 = 0.667        2/6 = 0.333
 Therefore the probability graph changes to:
 
 0.000	0.000	0.000
 0.667	0.000	0.000
 1@	0.333	0.000
 
 0.667 > 0.334; Move to square 4
 
 7	8	9
 4@	5	6
 1	2	3
 
 Neighbors: 7 + 5 + 1 = 13
 7/13 = 0.538        5/13 = 0.385        1/13 = 0.077
 Therefore the probability graph changes to:
 
 0.538	0.000	0.000
 4@	0.385	0.000
 0.077	0.000	0.000
 
 0.538 > 0.385 > 0.077; Move to square 7
 
 
 7@	8	9
 4	5	6
 1	2	3
 
 Neighbors: 8 + 4 = 12
 8/12 = 0.667        4/12 = 0.333
 Therefore the probability graph changes to:
 
 7@	0.667	0.000
 0.333	0.000	0.000
 0.000	0.000	0.000
 
 0.667 > 0.333; Move to square 8
 
 7	8@	9
 4	5	6
 1	2	3
 
 Neighbors: 9 + 7 + 5 = 21
 9/21 = 0.429        7/21 = 0.333        5/21 = 0.238
 Therefore the probability graph changes to:
 
 0.333	8@	0.429
 0.000	0.238	0.000
 0.000	0.000	0.000
 
 0.429 > 0.333 > 0.238; Move to square 9
 
 7	8	9@
 4	5	6
 1	2	3
 
 We have reached the top corner – ending condition
 
(Edited: 2017-09-20)
Suggested Algorithm: Add all adjacent numbers to current position and divide each number by the total = probability of moving to that square; if not adjacent, not a possible move so set to 0.000: 7 8 9 4 5 6 1@ 2 3 Neighbors: 4 + 2 = 6 4/6 = 0.667 2/6 = 0.333 Therefore the probability graph changes to: 0.000 0.000 0.000 0.667 0.000 0.000 1@ 0.333 0.000 0.667 > 0.334; Move to square 4 7 8 9 4@ 5 6 1 2 3 Neighbors: 7 + 5 + 1 = 13 7/13 = 0.538 5/13 = 0.385 1/13 = 0.077 Therefore the probability graph changes to: 0.538 0.000 0.000 4@ 0.385 0.000 0.077 0.000 0.000 0.538 > 0.385 > 0.077; Move to square 7 7@ 8 9 4 5 6 1 2 3 Neighbors: 8 + 4 = 12 8/12 = 0.667 4/12 = 0.333 Therefore the probability graph changes to: 7@ 0.667 0.000 0.333 0.000 0.000 0.000 0.000 0.000 0.667 > 0.333; Move to square 8 7 8@ 9 4 5 6 1 2 3 Neighbors: 9 + 7 + 5 = 21 9/21 = 0.429 7/21 = 0.333 5/21 = 0.238 Therefore the probability graph changes to: 0.333 8@ 0.429 0.000 0.238 0.000 0.000 0.000 0.000 0.429 > 0.333 > 0.238; Move to square 9 7 8 9@ 4 5 6 1 2 3 We have reached the top corner – ending condition

-- Sep 20 In-Class Exercise
sum of adjacent squares then division of the adjacent with sum gives you probability Resource Description for Screen Shot 2017-09-20 at 3.47.34 PM.png
sum of adjacent squares then division of the adjacent with sum gives you probability ((resource:Screen Shot 2017-09-20 at 3.47.34 PM.png|Resource Description for Screen Shot 2017-09-20 at 3.47.34 PM.png))

-- Sep 20 In-Class Exercise
We start from the initial state which is 1, then we start by calculating the probability of the adjacent cells. In the first state it is 2 and 4. we get probability of 2/6 and 4/6 6 being the total of 2+4. Since 4/6>2/6, we go with that. Repeat step 1 over until we reach cell 9
'''We start from the initial state which is 1, then we start by calculating the probability of the adjacent cells. In the first state it is 2 and 4. we get probability of 2/6 and 4/6 6 being the total of 2+4. Since 4/6>2/6, we go with that. Repeat step 1 over until we reach cell 9'''

-- Sep 20 In-Class Exercise
Resource Description for sept20.png
(Edited: 2017-09-20)
((resource:sept20.png|Resource Description for sept20.png))

-- Sep 20 In-Class Exercise
Algorithm to assign probability for a state: For any state, take the values of the adjacent nodes and add them. Set this sum to total. The probability to move to an adjacent node is that node's value divided by total. Then the state will move to the node with the highest probability.
P(n) is the probability of n for the current state.
For State 1: Total = 6 = 2 + 4 P(4) = 4/6 P(2) = 2/6 4/6 > 2/6 so @ will move from State 1 to State 4.
For State 4: Total = 13 = 1 + 5 + 7 P(1) = 1/13 P(5) = 5/13 P(7) = 7/13 7/13 > 5/13 > 1/13 so @ will move from State 4 to State 7.
For State 7: Total = 12 = 8 + 4 P(4) = 4/12 P(8) = 8/12 8/12 > 4/12 so @ will move from State 7 to State 8.
For State 8: Total = 14 = 9 + 5 P(5) = 5/14 P(9) = 9/14 9/14 > 5/14 so @ will move from State 8 to State 9.
Student:Zahra Amin
(Edited: 2017-09-20)
Algorithm to assign probability for a state: For any state, take the values of the adjacent nodes and add them. Set this sum to total. The probability to move to an adjacent node is that node's value divided by total. Then the state will move to the node with the highest probability. P(n) is the probability of n for the current state. For State 1: Total = 6 = 2 + 4 P(4) = 4/6 P(2) = 2/6 4/6 > 2/6 so @ will move from State 1 to State 4. For State 4: Total = 13 = 1 + 5 + 7 P(1) = 1/13 P(5) = 5/13 P(7) = 7/13 7/13 > 5/13 > 1/13 so @ will move from State 4 to State 7. For State 7: Total = 12 = 8 + 4 P(4) = 4/12 P(8) = 8/12 8/12 > 4/12 so @ will move from State 7 to State 8. For State 8: Total = 14 = 9 + 5 P(5) = 5/14 P(9) = 9/14 9/14 > 5/14 so @ will move from State 8 to State 9. Student:Zahra Amin

-- Sep 20 In-Class Exercise
Resource Description for image.jpg
((resource:image.jpg|Resource Description for image.jpg))
[ Next ]
X