implementation of the particle filter. Not tested for bugs.