给定两个不同的高斯,如何创建两个高斯的混合,其中每个数据点来自第一个高斯,概率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
目前没有回答
相关问题 更多 >
编程相关推荐