Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: How to fit a mixture of a von Mises Distribution?

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).

like image 696
cqcn1991 Avatar asked Oct 18 '22 05:10

cqcn1991


1 Answers

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.

like image 179
FraSchelle Avatar answered Oct 20 '22 22:10

FraSchelle