### particleFilter.py

'''
Licensing Information: Please do not distribute or publish solutions to this
project. You are free to use and extend Driverless Car for educational
purposes. The Driverless Car project was developed at Stanford, primarily by
Chris Piech (piech@cs.stanford.edu). It was inspired by the Pacman projects.
'''
from engine.const import Const
import util
import numpy
import random
import math
import scipy.stats
# Class: Particle Filter
# ----------------------
# Maintain and update a belief distribution over the probability of a car
# being in a tile using a set of particles.
class ParticleFilter(object):
NUM_PARTICLES = 100
# Function: Init
# --------------
# Constructer that initializes an ExactInference object which has
# numRows x numCols number of tiles.
def __init__(self, numRows, numCols):
''' initialize any variables you will need later '''
# Function: Observe
# -----------------
# Updates beliefs based on the distance observation and your agents position.
# The noisyDistance is a gaussian distribution with mean of the true distance
# and std = Const.SONAR_NOISE_STD.
def observe(self, agentX, agentY, observedDist):
''' your code here'''
# Function: Elapse Time
# ---------------------
# Update your inference to handle the passing of one heartbeat. Use the
# transition probability you created in Learner
def elapseTime(self):
''' your code here'''
# Function: Get Belief
# ---------------------
# Returns your belief of the probability that the car is in each tile. Your
# belief probabilities should sum to 1.
def getBelief(self):
return self.belief