将两个高斯人组合成另一个高斯人 [英] Combining two Gaussians into another Guassian

查看:152
本文介绍了将两个高斯人组合成另一个高斯人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,我有两个高斯曲线,一个是红色,另一个是紫色曲线.我想知道python中是否有一种方法可以将两个高斯曲线都组合到第三条曲线上,而第三条曲线看起来应该像蓝色曲线(这只是高斯曲线的一个例子,据说它更高,更宽)?任何帮助将不胜感激.

In the code below I have two Gaussian one red and the other in a purple curve. I am wondering if there is a way in python to combining both Gaussian unto a third curve which is suppose to look like the blue curve (which just serves as an example of a Gaussian supposedly being higher and wider)? Any help will be appreciated.

import numpy as np
import scipy.optimize as opt
import matplotlib.pyplot as plt

def gauss(x, p): # p[0]==mean, p[1]==stdev, p[2]==heightg, p[3]==baseline                   
    a = p[2]
    mu = p[0]
    sig = p[1]
    base = p[3]
    return a * np.exp(-1.0 * ((x - mu)**2.0) / (2.0 * sig**2.0)) + base

p0 = [6804.5, 1.2, 23.0, 25.3532] # Inital guess is a normal distribution
p02 = [6804.5, 6.5, 5.0, 25.09098]

xp = np.linspace(6780, 6810, 200)
fig = plt.figure()
a1 = fig.add_subplot(111)
a1.plot(xp, gauss(xp, p0), lw=3, alpha=2.5, color='r')
a1.plot(xp, gauss(xp, p02), lw=3, alpha=2.5, color='purple')
a1.set_xlim([6798, 6810])

plt.tight_layout()
plt.show()

推荐答案

在我看来,您正在寻找两个高斯的卷积吗?在这种情况下,您可以使用numpy.convolve函数( http://en. wikipedia.org/wiki/Convolution

It seems to me that you are looking for the convolution of the two Gaussians? In this case you can make use of the function numpy.convolve (http://docs.scipy.org/doc/numpy/reference/generated/numpy.convolve.html#numpy.convolve). Note that the output array will be twize the length of the two input arrays. This is related to the definition of this convolution, where the functions are kind of shifted along each other. See Wikipedia for a nice illustration showing differences between convolution, cross-correlation and auto-corellation: http://en.wikipedia.org/wiki/Convolution

这篇关于将两个高斯人组合成另一个高斯人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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