1

我将 scikit 中的混合建模问题提炼到以下 1D 示例。简单地将混合模型拟合到一维密度。我在使用简单 GMM 时体验到了良好的性能,但在使用变分或狄利克雷过程 GMM 时出现了奇怪的行为。首先,拟合非常差,其次,推断的分布没有标准化(参见下面的代码和图像)。

在示例http://scikit-learn.org/stable/auto_examples/mixture/plot_gmm_pdf.html中,同样的行为很明显。GMM 类返回的概率近似归一化,而 DPGMM 类返回的概率没有。通过附加以下行来计算归一化:

print np.sum(np.exp(-Z)) * (x[1] - x[0]) * (y[1] - y[0])

这是一个错误,还是我做错了什么?

代码:

import numpy as np
import numpy.random as rndn

import sklearn.mixture as skmix

import matplotlib.pyplot as plt

X = rnd.randn(0.7 * 300, 1) - 5
X = np.vstack((X, rnd.randn(0.3 * 300, 1) * 0.3 + 3))

# gmm = skmix.GMM(2)
gmm = skmix.DPGMM(2)
gmm.fit(X)

x = np.linspace(-10, 10, 1000)
p = np.exp(gmm.score(x))

plt.hist(X, bins=50, normed=True)
plt.plot(x, p)
plt.show()

integral = np.sum(p) * (x[1] - x[0])
print integral

DPGMM 不合适

4

0 回答 0