0

给定两个不同的高斯,我如何创建两个高斯的混合,其中每个数据点来自概率 p = 0.3 的第一个高斯和概率 0.7 的第二个高斯(使用概率的伯努利分布)。

这是我的开始:

import numpy as np
mu1, sigma1 = 1, 2 # mean and standard deviation
g1 = np.random.normal(mu1, sigma1, 1000)

mu2, sigma2 = 4, 8 # mean and standard deviation 2
g2 = np.random.normal(mu2, sigma2, 1000)

p = .3  # probability
b = np.random.binomial(1, p, 1000)

# How to combine these to sample from mixture?

# Combining gaussians would be:
combined_gaussians = np.random.normal(mu1+mu2, np.sqrt(sigma1^2 + sigma2^2))

# In this case, can we just do a linear combination of the samples?:
combined_samples = b*g1+(1-b)g2

4

0 回答 0