Faster State Estimation
In last week's design lab, you implemented the StateEstimator class by implementing methods update and transition, as defined below. The update method of the StateEstimator class is supposed to take an observation and simulate both an observation and a transition, replacing self.belief with a new DDist representing the updated belief state.
The update method was defined as follows:
class StateEstimator: #other code removed def update(self, obs): self.observe(obs) self.transition()
This code does the right thing but, unfortunately it has a downside: it is slow! When the robot is localizing itself in the hallway world, for example, it is important that our update method is fast, so that the robot can make as many updates as possible as it is moving through the world.
As written, the method wastes time constructing several new instances of DDist while applying Bayes' rule and Total Probability to get an updated belief state, and it also spends time constructing the entire joint distribution over all possible states and all possible observations, even though we already know which observation occurred (so many of those joint probabilities are useless!).
Your goal is to write a faster version of update, which still computes the correct updated belief, but which does so faster than this reference implementation.
In this problem, your score will be based not only on your code producing the correct answer, but also on the speed with which your code computes that answer. For example, the default code computes the correct result, but it does so very slowly, so it is likely to get a score near 0. Our measure of speed will be based on the total number of Python instructions your code executes (rather than based on a measure of the time in seconds your code takes to execute, which can vary dramatically between runs).
Hint: You may find it helpful to review the graphical method for state estimation presented in the readings and mini-lectures.