拟合多峰分布 [英] Fitting multimodal distrubtions

查看:90
本文介绍了拟合多峰分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有两个正态分布的线性组合.我认为人们会将结果称为

如您所见,我们有两个正态分布的线性组合,其参数为 (mu1 = 0, s1 = 5)(mu2 = 20, s2 = 10).但当然,我们通常事先并不知道这些参数.

我想知道如何估计或拟合这些参数(mus 和 sigmas).我相信有一些方法可以做到这一点,但我还没有找到.

解决方案

您描述的问题是 高斯混合模型.为了能够估计这些参数,您需要有一些样本.如果您没有样本但已获得曲线,则可以根据曲线生成一些样本.然后你可以使用期望最大化算法来估计参数.Scikit-learn 有一种方法可以让你做到这一点:sklearn.mixture.GaussianMixture.您只需要提供您的样本、组件数量 (n_components)(在您的情况下为 2)以及协方差类型(在您的情况下为 full),如您对协方差矩阵没有先验假设.

Let's assume we're having a linear combination of two normal distributions. I think one would call the result a multimodal distribution.

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm

ls = np.linspace(0, 60, 1000)

distribution = norm.pdf(ls, 0, 5) + norm.pdf(ls, 20, 10)
distribution = (distribution * 1000).astype(int)
distribution = distribution/distribution.sum()

plt.plot(ls, distribution)

As you can see, we are having a linear combination of two normal distributions having parameters (mu1 = 0, s1 = 5) and (mu2 = 20, s2 = 10). But of course, we usually do not know these parameters beforehand.

I would like to know how I can estimate or fit those parameters (mus and sigmas). I am confident there are methods that would allow to do this but I couldn't find any yet.

解决方案

The problem that you describe is a special case of Gaussian Mixture model. In order to be able to estimate these parameters, you need to have some samples. If you don't have samples but you are given the curve, you could produce some samples based on the curve. Then you can use Expectation–maximization algorithm to estimate the parameters. Scikit-learn has a method that enables you to do that: sklearn.mixture.GaussianMixture. You just need to provide your samples, the number of components (n_components) which is 2 in your case, and a covariance type, which would be full in your case, as you have no prior assumptions on the covariance matrix.

这篇关于拟合多峰分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆