I have a angular distribution, and I want to fit a mixture of von Mises distribution to that
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With