5
votes

I have a angular distribution, and I want to fit a mixture of von Mises distribution to that

enter image description here

How can I do that?

I find an implementation in R, Fit a mixture of von Mises distributions in R

I also find it is possible to fit a single von Mises distributio in Python, http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.vonmises.html

I think maybe I can try to how to fit a mixture distribution, given I have the function already defined in scipy?


Finally, I solved this problem using rpy2. Specifcally, I cleaned data using Python, and traind the VMM using the R packages (so instll R and related packges is required).

1
How many von Mises distributions are you wanting to sum? Is it a fixed number? - Davis Herring
@DavisHerring within 10 - cqcn1991
Well, you’ll almost always get a better fit (and always at least as good) with more basis functions, so “within 10” just means 10. - Davis Herring
@DavisHerring goodness-of-fit is not the only consideration. I also take cross validation effect into account. So in my study, the actual range is between 3-6. With more components, the result only gets slightly better. - cqcn1991
Related: Mixture models in scipy - stackoverflow.com/questions/47759577/… - Itamar Mushkin

1 Answers

3
votes

I implemented an algorithm to solve a similar problem, see

https://framagit.org/fraschelle/mixture-of-von-mises-distributions

for full details.

Starting from a random sample (a 1D numpy.array), it applies an expectation-maximization algorithm to classify the data according to the von-Mises distribution.

The algorithm allows for any superposition of von-Mises distributions (although the mathematics associated with the algorithm (link to pdf) only describes a superposition of two distributions, it is quite easy to generalise), and it is as fast as I could do. It relies only on Numpy and the iv function of scipy.special, to call the modified Bessel function.

The mixture_mises_pdfit returns the weight of each distribution, and the $\mu$ and $\kappa$ parameters, see e.g. the Wikipedia page on von Mises distribution.

It would be nice to add a real classification outcome of the code, in order to allow classification of periodic data. Eventually, an extension to Scikit-learn should be feasible as well, though it requires more time to implement.