gpt4 book ai didi

python - python中的对数正态混合

转载 作者:行者123 更新时间:2023-12-04 14:21:15 25 4
gpt4 key购买 nike

我正在尝试将 3 个正态分布的混合拟合到我的转换数据日志中,但我有点困惑如何去做。我尝试了 scikit learn python 中的 gmm 函数,但它似乎无法正常工作。

g = mixture.GMM(n_components=3)
g.fit(lines)
f1 = arange(0, 13, 0.01)
f2 = arange(0, 13, 0.01)
f3 = arange(0, 13, 0.01)
f = arange(0, 13, 0.01)

for x in arange(0, 13, 0.01):
f1[x] = numpy.round(g.weights_[0],5) * numpy.exp(-numpy.power(x - means[0], 2) / 2 * numpy.power(covars[0], 2)) * (1 / (covars[0] * numpy.power(2 * pi, 0.5)))
f2[x] = numpy.round(g.weights_[1],5) * numpy.exp(-numpy.power(x - means[1], 2) / 2 * numpy.power(covars[1], 2)) * (1 / (covars[1] * numpy.power(2 * pi, 0.5)))
f3[x] = numpy.round(g.weights_[2],5) * numpy.exp(-numpy.power(x - means[2], 2) / 2 * numpy.power(covars[2], 2)) * (1 / (covars[2] * numpy.power(2 * pi, 0.5)))

f=f1+f2+f3
plt.plot(f)
plt.show()

最后我想得到 3 个分量的 pdf 图,即 f=f1+f2+f3。但是它不起作用。

是不是因为我试图将法线混合到对数正态数据?

您能否解释我的错误和/或就用于拟合对数正态混合的包向我提供建议?

最佳答案

这是我使用 OpenTURNS 混合了 3 个 LogNormal 分布图书馆

import openturns as ot
from openturns.viewer import View

distribution1 = ot.LogNormal(0.01, 0.8, 3.)
distribution2 = ot.LogNormal(0.01, 0.5, 0.)
distribution3 = ot.LogNormal(0.1, 1., 7.)

final_dist = ot.Mixture([distribution1, distribution2, distribution3])

graph = final_dist.drawPDF()

View(graph, add_legend=False)
mixture of 3 lognormal distributions
这是您要找的吗?
您可以通过调用 final_dist.computePDF([p]) 访问任何点 p 中生成的 PDF 的值。并使其适合您的数据。
如果你熟悉 matplotlib 和 numpy,这里是使用这些相同的情节
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-3, 18, 100).reshape(-1, 1)
plt.plot(x, final_dist.computePDF(x))
enter image description here

关于python - python中的对数正态混合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25037217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com