feat: complete q10, q11
This commit is contained in:
parent
83a3634e2a
commit
81c58289c1
18
inference.py
18
inference.py
@ -683,7 +683,19 @@ class ParticleFilter(InferenceModule):
|
|||||||
the DiscreteDistribution may be useful.
|
the DiscreteDistribution may be useful.
|
||||||
"""
|
"""
|
||||||
"*** YOUR CODE HERE ***"
|
"*** YOUR CODE HERE ***"
|
||||||
raiseNotDefined()
|
pacman_position = gameState.getPacmanPosition()
|
||||||
|
jail_position = self.getJailPosition()
|
||||||
|
|
||||||
|
particle_weights = DiscreteDistribution()
|
||||||
|
for particle in self.particles:
|
||||||
|
particle_weights[particle] += self.getObservationProb(observation, pacman_position, particle, jail_position)
|
||||||
|
|
||||||
|
total = sum([v for k, v in particle_weights.items()])
|
||||||
|
if total == 0:
|
||||||
|
self.initializeUniformly(gameState)
|
||||||
|
else:
|
||||||
|
self.particles = [particle_weights.sample() for time in range(self.numParticles)]
|
||||||
|
|
||||||
"*** END YOUR CODE HERE ***"
|
"*** END YOUR CODE HERE ***"
|
||||||
|
|
||||||
########### ########### ###########
|
########### ########### ###########
|
||||||
@ -696,6 +708,8 @@ class ParticleFilter(InferenceModule):
|
|||||||
gameState.
|
gameState.
|
||||||
"""
|
"""
|
||||||
"*** YOUR CODE HERE ***"
|
"*** YOUR CODE HERE ***"
|
||||||
raiseNotDefined()
|
for index, old_particle_position in enumerate(self.particles):
|
||||||
|
distribution = self.getPositionDistribution(gameState, old_particle_position)
|
||||||
|
self.particles[index] = distribution.sample()
|
||||||
"*** END YOUR CODE HERE ***"
|
"*** END YOUR CODE HERE ***"
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user