Particle Filtering in a Dynamic Bayesian Network

Particle filtering is an application of likelihood weighting to a dynamic Bayesian network. In particular, it is an approximate inference algorithm for estimating the state of a dynamic Bayesian network at time t given evidence up to that point in time.



PARTICLE-FILTERING(bn, e1:t, N)
    S ← randomly sample N times from the prior p(X0)

    for i=1...t
        S ← PARTICLE-FILTERING-HELPER(ei, N, S, bn)
    end

    return S
end


PARTICLE-FILTERING-HELPER(e, N, S, bn)
    weighted_set ← {} // Use this to compute a distribution over the state

    for s=1...N
        old_sample = S(s)

        // Sample an updated state
        new_sample ← randomly sample from p(Xi | Xi-1 = old_sample)
        
        // Weight the sample according to the likelihood of the evidence
        weight ← p(e| X = new_sample)

        weighted_set{new_sample} += weight
    end

    weighted_set.normalize()

    // Here we resample according to the weights
    for s=1...N
        S(s) = weighted_set.sample()
    end
    
    return S
end