I've a weighted sum of the 2 Gaussian distribution functions as below. How can I get a random number based on this sum of functions. The number of functions can vary up to 10.
Asked
Active
Viewed 124 times
1 Answers
0
Let's say your mixture components have probabilities $p_1,p_2$ (add up to $1$). A basic algorithm would probably choosing a uniform random variable between $u\in[0,1]$ and compare with $p$, if it's smaller sample from $\mathcal{N_1}$, else sample from $\mathcal{N_2}$. For $K$ components with probabilities $p_1,\dots,p_K$, do the same:
If $u<p_1$, sample from $\mathcal{N_1}$, else if $u<p_1+p_2$ sample from $\mathcal{N_2}$, ..., else if $u<\sum_{i=1}^m{p_i}$, sample from $\mathcal{N_m}$, which basically applies Inverse Transform Sampling in discrete.

gunes
- 49,700
- 3
- 39
- 75