# How to calculate the mean of an unsymmetric distribution (Particle Filter)

I'm attempting to implement a variant of Monte Carlo localization in a 2D space with obstacles. While the object is moving around the obstacles the particles flow around the obstacle like in images below. But the weighted mean (arithmetic) of all particles falls outside the distribution on the obstacle. What are other ways of calculating the mean such that the estimate is actually in the distribution outside the obstacle?

The mean itself is precisely defined and there's no alternative definition for it. It simply is what it is.

Instead you need a different summary statistic; in this case something like a mode might be useful but how do you decide which mode to use if your distribution is multi-modal? I haven't worked with this particular application so can't say what others have done. You might be stuck coming up with your own way of deciding what single position should represent the cloud.

Only real advice I can give is in a proper Bayesian framework like this you can often delay collapsing your state to a single position until very late. e.g. for as many calculations as possible consider all particles weighted by their probability.

If you have a set of $$n$$ point $$p_i$$ with $$i=1,2,...,n$$, its mean is also the minimum of

$$J(x) = \sum_{i=1}^n \|p_i - x\|_2^2. \tag{1}$$

In your case instead of using Euclidean norm you could use the length squared of the shortest valid path from point $$p_i$$ to $$x$$ as shown in the figure below. Do keep in mind that this would mean that you would have to solve a optimization problem.

In order to find the shortest path from $$p_i$$ to the current guess for $$x$$ you might have to do some path finding, for example by using the A* search algorithm.