reasoning under uncertainty note that it first advances time this is what is required if it is called after previous filtering if that is not what is wanted initiallydo an observe first ""for obs in obsseqself advance(advance time self observe(obsobserve self resample_particles(self display( ,"after observing"str(obs)"state distribution:"self histogram(self particles)self display( ,"final state distribution:"self histogram(self particles)return self histogram(self particles def advance(self)"""advance to the next time this assumes that all of the weights are ""self particles [sample_one(self hmm trans[st]for st in self particles def observe(selfobs)"""reweighs the particles to incorporate observations obs""for in range(len(self particles))for obv in obsif obs[obv]self weights[ *self hmm pobs[obv][self particles[ ]elseself weights[ * -self hmm pobs[obv][self particles[ ] def histogram(selfparticles)"""returns list of the probability of each state as represented by the particles""tot= hist {st for st in self hmm statesfor (st,wtin zip(self particles,self weights)hist[st]+=wt tot +wt return {st:hist[st]/tot for st in hist def resample_particles(self)"""resamples to give new set of particles ""self particles resample(self particlesself weightslen(self particles)self weights [ len(self particlesthe following are some queries for hmm probhmm py -(continuedversion june