# How to use a particle filter for Bayesian inference?

I'm not very well versed in probability theory, so I'm not sure how to assess if my approach is correct. I hope this is the right place to ask.

I have implemented a particle filter to get an estimate of the state vector of an object that I'm tracking with some sensors. I choose a particle filter, because the state vector is subject to some nonlinear restrictions (walls, floor, etc.) that I can account for by setting the weights of invalid particles (states) to zero before resampling. My goal is to use the particles in a Bayesian classifier to see if the observed state is consistent with my hypothesis.

If I have understood correctly, after the resampling, the particle collection is a representation of the posterior probability density function $p(x)$. The average $\bar{x}$ obtained by averaging all states (particles) would be my best estimate for the true state. I define my evidence $E$ as the observation of $x$.

For the Bayesian classifier, I need to calculate the posterior probability $P(H|E) = \frac{P(E|H)}{P(E)} P(H)$. The prior probability $P(H)$ I can obtain from historical data regarding my hypothesis (in my case a Poisson distribution seems to be applicable).

My question pertains to how to obtain the likelihood and $P(E|H)$, given the fact that I have the probability density function $p(x)$ (or at least an approximation of it) in the form of the particle distribution.

I was thinking to use a normal distribution, with parameters $\mu,\sigma$ obtained from experiments, to approximate the probability density function $p(x|H)$, but then it is unclear how I would obtain the probability $P(E|H)$ from that.

Any pointers or ideas would be much appreciated.

Since it is a classifier, I don't need really need to calculate $P(E)$, but I think it would be helpful if I could, since I can then report actual probabilities $P(H|E=x)$ for various hypotheses, instead of only reporting the most likely hypotheses.

UPDATE

What I have so far is the following:

• The particle filter gives me a set of particles. From this I can obtain the estimate of the state as the average $\bar{x}$, together the standard deviation $\sigma$.
• With the particles I can also estimate the CDF of $x$ as $cdf(x) \approx \sum_{i=0}^{I_x} 1/N$, where $N$ is the number of particles and $I_x$ is the index of the particle nearest to $x$.
• For the classifier, $P(H)$ and $P(x|H)$ can be obtained from experiments and observations of the hypothesis.
• $P(x)$ can be approximated by calculating $P(\bar{x}-\sigma \leq x \leq \bar{x}+\sigma)$ using the approximated CDF.

The last part is still what I'm most unsure of. I'm trying to implement some simulations. Any comments on the correctness of this approach are also appreciated.

• I've speculatively adjusted your notation. Hope I haven't removed the sense. – conjugateprior Jul 22 '15 at 8:27
• @conjugateprior : I thought that my evidence is $\bar{x}$, since I cannot observe the true $x$? – user82875 Jul 22 '15 at 9:11
• You also entirely skip the time series aspect of the data and state. The posterior for $x_t$ comes from the $x_{t-1}$ passed through the state equation $p(x_t | x_{t-1})$ to generate a prior for $x_t$, then conditioned on $y_t$ via the likelihood function $p(y | x)$. What, in this scheme is then H? – conjugateprior Jul 22 '15 at 9:20
• In general a filtering gives you the likelihood of the data under the model which is the single number you want, I think: conceptually $p(y_1\ldots y_T | M)=\int p(y_1\ldots y_T | x_1\ldots x_T, M) p(x_1\ldots x_T) dx_1\ldots dx_T$ where $p(x_1\ldots x_T)$ is a construction from a genuine prior $p(x_{0})$ and a state dynamics model $p(x_t | x_{t-1})$ that can generate the rest. – conjugateprior Jul 26 '15 at 11:51
• On your update: if you think that the average state vector is a good feature to classify humans and non-humans, then - sure - use it. My point is only that any filter gives you P(E | H) for free. Thinking of particles is not necessary - just recall how you compute a Likelihood with a Kalman filter. – conjugateprior Jul 26 '15 at 11:56

One way to think of your problem is as a mixture model. There are two possible causes of $y_1\ldots y_T$, the data that you see, which could correspond to two generative models for it, indexed by $M$. For example $$p(y_1 \ldots y_T) = p(y_1 \ldots y_T \mid M=\text{human}) p(M=\text{human}) + p(y_1\ldots y_T \mid M=\text{non-human}) p(M=\text{non-human})$$ You can assert some $P(M)$ and fit the two likelihoods from training data as a start to see how it might work. Then you're interested in $$p(M \mid y_1\ldots y_T)$$ which is gotten easily from the model above via Bayes theorem.
Turning to the likelihoods, a filter (particle or otherwise) will give you the likelihood of the data under the model which seems to be the the single number you want above. That's because, conceptually at least $$p(y_1 \ldots y_T \mid M) = \int p(y_1\ldots y_T \mid x_1\ldots x_T, M) p(x_1\ldots x_T) dx_1 \ldots dx_T$$ where $p(x_1\ldots x_T)$ is a construction from a genuine prior $p(x_0)$ and a state dynamics model $p(x_t \mid x_{t−1})$ that can generate the rest, all conditioned on the observations.
If, on the other hand, you think that the average state vector is a good feature to classify humans and non-humans, then use it. You may want to smooth as well then. My point above is only that any filter gives you $P(E | H) = P(y_1\ldots y_T \mid M)$ for free. Thinking of particles is not necessary - just recall how you compute a Likelihood with a Kalman filter.