I am given the values for mean, co-variance, initial_weights for a mixture of Gaussian Models. Now how can I generate samples given those: In brief, I need a function like

X = GMMSamples(W, mu, sigma, d)

where W: weight vector, mu - mean vector, sigma - covariance vector, d - dimensions of samples How can I implement it in python ? I found scipy library that has GaussianMixture library. It basically takes input as sample values and calculate itself mean, co-variance. But for my case it is almost reverse. I am given mean, co-variance, and parameters mentioned above and I need to generate sample data values. Thank you.


Sampling from mixture distribution is super simple, the algorithm is as follows:

  1. Sample $I$ from categorical distribution parametrized by vector $\boldsymbol{w} = (w_1,\dots,w_d)$, such that $w_i \ge 0$ and $\sum_i w_i = 1$.
  2. Sample $x$ from normal distribution parametrized by $\mu_I$ and $\sigma_I$.

This thread on StackOverflow describes how to sample from categorical distribution.

| cite | improve this answer | |
  • $\begingroup$ Tim, can you please elaborate more ? $\endgroup$ – Shyamkkhadka Oct 31 '16 at 15:04
  • $\begingroup$ What is unclear for you? $\endgroup$ – Tim Oct 31 '16 at 15:04
  • $\begingroup$ Sample I from categorical distribution means what ? What is the role of value I ? $\endgroup$ – Shyamkkhadka Oct 31 '16 at 15:08
  • $\begingroup$ @Shyamkkhadka Actually I found other thread that asks about exactly the same thing stats.stackexchange.com/questions/226834/… , so please check it as it is a duplicate of your question. $\endgroup$ – Tim Oct 31 '16 at 15:09
  • $\begingroup$ @Shyamkkhadka the idea of a mixture is that you have $d$ components, each appearing with probability $w_i$, so $I$ is a way of saying "take $I$-th component with probability $w_i$", what follows from the definition of mixture distribution. $\endgroup$ – Tim Oct 31 '16 at 15:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.