# Generate sample data from Gaussian mixture model [duplicate]

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.

## marked as duplicate by Tim♦, kjetil b halvorsen, gung - Reinstate Monica♦, mdewey, JohnOct 31 '16 at 19:20

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$.
• @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. – Tim Oct 31 '16 at 15:10