feat: complete q5
This commit is contained in:
parent
6de3e08829
commit
37b07afc50
24
inference.py
24
inference.py
@ -357,7 +357,12 @@ class DiscreteDistribution(dict):
|
|||||||
{}
|
{}
|
||||||
"""
|
"""
|
||||||
"*** YOUR CODE HERE ***"
|
"*** YOUR CODE HERE ***"
|
||||||
raiseNotDefined()
|
total = self.total()
|
||||||
|
print("TOTAL:", total)
|
||||||
|
print(self)
|
||||||
|
if total != 0:
|
||||||
|
for k, v in self.items():
|
||||||
|
self[k] = v/total
|
||||||
"*** END YOUR CODE HERE ***"
|
"*** END YOUR CODE HERE ***"
|
||||||
|
|
||||||
def sample(self):
|
def sample(self):
|
||||||
@ -382,9 +387,15 @@ class DiscreteDistribution(dict):
|
|||||||
0.0
|
0.0
|
||||||
"""
|
"""
|
||||||
"*** YOUR CODE HERE ***"
|
"*** YOUR CODE HERE ***"
|
||||||
raiseNotDefined()
|
total = self.total()
|
||||||
"*** END YOUR CODE HERE ***"
|
rand_number = random.random() * total
|
||||||
|
|
||||||
|
tmp = 0
|
||||||
|
for k, v in self.items():
|
||||||
|
tmp += v
|
||||||
|
if rand_number < tmp:
|
||||||
|
return k
|
||||||
|
"*** END YOUR CODE HERE ***"
|
||||||
|
|
||||||
class InferenceModule:
|
class InferenceModule:
|
||||||
"""
|
"""
|
||||||
@ -457,7 +468,12 @@ class InferenceModule:
|
|||||||
Return the probability P(noisyDistance | pacmanPosition, ghostPosition).
|
Return the probability P(noisyDistance | pacmanPosition, ghostPosition).
|
||||||
"""
|
"""
|
||||||
"*** YOUR CODE HERE ***"
|
"*** YOUR CODE HERE ***"
|
||||||
raiseNotDefined()
|
if ghostPosition == jailPosition or noisyDistance == None:
|
||||||
|
return 1 if ghostPosition == jailPosition and noisyDistance == None else 0
|
||||||
|
else:
|
||||||
|
true_distance = manhattanDistance(pacmanPosition, ghostPosition)
|
||||||
|
return busters.getObservationProbability(noisyDistance, true_distance)
|
||||||
|
|
||||||
"*** END YOUR CODE HERE ***"
|
"*** END YOUR CODE HERE ***"
|
||||||
|
|
||||||
def setGhostPosition(self, gameState, ghostPosition, index):
|
def setGhostPosition(self, gameState, ghostPosition, index):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user