这是一些物理实验的结果,可以用直方图[i, amount_of(i)]表示。我认为结果可以通过4-6个高斯函数的混合来估计。
Python中有没有一个包可以将直方图作为输入,并返回混合分布中每个高斯分布的均值和方差?
原始数据,例如:

发布于 2013-01-07 15:08:49
这是一个mixture of gaussians,可以使用expectation maximization方法来估计(基本上,它在估计分布的中心和均值的同时估计它们是如何混合在一起的)。
这是在PyMix包中实现的。下面我将生成一个混合法线的示例,并使用PyMix将混合模型拟合到它们,包括找出您感兴趣的是什么,这是子总体的大小:
# requires numpy and PyMix (matplotlib is just for making a histogram)
import random
import numpy as np
from matplotlib import pyplot as plt
import mixture
random.seed(010713) # to make it reproducible
# create a mixture of normals:
# 1000 from N(0, 1)
# 2000 from N(6, 2)
mix = np.concatenate([np.random.normal(0, 1, [1000]),
np.random.normal(6, 2, [2000])])
# histogram:
plt.hist(mix, bins=20)
plt.savefig("mixture.pdf")上面的代码所做的就是生成和绘制混合物。它看起来是这样的:

现在实际使用PyMix来计算百分比是多少:
data = mixture.DataSet()
data.fromArray(mix)
# start them off with something arbitrary (probably based on a guess from the figure)
n1 = mixture.NormalDistribution(-1,1)
n2 = mixture.NormalDistribution(1,1)
m = mixture.MixtureModel(2,[0.5,0.5], [n1,n2])
# perform expectation maximization
m.EM(data, 40, .1)
print m它的输出模型是:
G = 2
p = 1
pi =[ 0.33307859 0.66692141]
compFix = [0, 0]
Component 0:
ProductDist:
Normal: [0.0360178848449, 1.03018725918]
Component 1:
ProductDist:
Normal: [5.86848468319, 2.0158608802]注意,它非常正确地找到了两条法线(大约一条N(0, 1)和一条N(6, 2) )。它还估计了pi,这是两个发行版中的分数(您在评论中提到的是您最感兴趣的部分)。我们在第一个发行版中有1000个,在第二个发行版中有2000个,它几乎完全正确地划分了:[ 0.33307859 0.66692141]。如果您想要直接获取此值,请执行m.pi。
以下是一些注意事项:
[1.4, 1.4, 2.6, 2.6, 2.6])[(1.4, 2), (2.6, 3)]必须事先猜测高斯分布的数量(如果你要求2的混合,它不会计算出4的混合)。https://stackoverflow.com/questions/14189937
复制相似问题