6

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

ZK Zhao
  • 19,885
  • 47
  • 132
  • 206
  • How many von Mises distributions are you wanting to sum? Is it a fixed number? – Davis Herring May 10 '19 at 16:58
  • @DavisHerring within 10 – ZK Zhao May 11 '19 at 23:02
  • 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 May 11 '19 at 23:12
  • 1
    @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. – ZK Zhao May 16 '19 at 06:39
  • Related: Mixture models in scipy - https://stackoverflow.com/questions/47759577/creating-a-mixture-of-probability-distributions-for-sampling – Itamar Mushkin Jun 15 '20 at 08:28

1 Answers1

5

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.

FraSchelle
  • 249
  • 4
  • 10
  • 1
    Links are not working. It would be really nice if you make a GitHub repository for your work :) – Yashas Jun 15 '20 at 06:21
  • 4
    @Yashas Sorry, I changed my account name at framagit. The link is now working. Tell me if it does not, and thank you for pointing this mistake of mine. – FraSchelle Jun 15 '20 at 08:26
  • 2
    thank you so much for this. I plan to write a paper using part of your solution, I'd like to know how I can properly cite it. – raulindo Sep 29 '21 at 18:09
  • @FraSchelle, your package cannot be installed through the PyPi channel using pip install – Feng Hu Apr 13 '23 at 09:47
  • @FengHu Indeed, and so what ? Better to make an extension of sk-learn I guess. I you have time, go :-) – FraSchelle Apr 15 '23 at 10:20