SciPy 反卷积函数 [英] SciPy deconvolution function

查看:65
本文介绍了SciPy 反卷积函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 SciPy 的反卷积函数来找到给定两个高斯分布的未知分布.没有与此功能相关的文档SciPy,所以我只是在寻找一个关于如何在我的情况下使用这个函数的例子.例如,给定两个正态分布 N(100, 1), N(300, 2),我想了解如何找到反卷积 N(200, 1) 的分布.

<预><代码>>>>sample1 = np.round(scipy.around(scipy.stats.norm(100, 1).rvs(size=1000)))>>>sample2 = np.round(scipy.stats.norm(300, 2).rvs(size=2000))>>>信号.反卷积(样本1,样本2)

上面的代码给了我负值,这似乎是错误的.我怎样才能从这个反卷积中恢复分布 N(200, 1)?特别是,我认为我的问题是我不明白如何获得除数.

我真正想看到的是如何使用 SciPy 的反卷积从这些样本中恢复 ~ N(200, 1) 的示例.

解决方案

我觉得你对你的期望有点困惑......因为我们都知道两个正态分布的卷积是另一个正态分布的均值是均值之和,方差是方差之和,您似乎期望两个正态随机样本的卷积也将是正态随机样本.事实并非如此:

a = scipy.stats.norm(100, 1).rvs(size=1000)b = scipy.stats.norm(200, 1).rvs(size=1000)c = scipy.convolve(a, b)plt.subplot(311)plt.hist(a, bins=50)plt.subplot(312)plt.hist(a, bins=50)plt.subplot(313)plt.hist(a, bins=50)

您可能正在考虑以下内容:

a = scipy.stats.norm(100, 10).pdf(np.arange(500))b = scipy.stats.norm(200, 20).pdf(np.arange(500))c = scipy.convolve(a, b)m_ = max(a.max(), b.max(), c.max())plt.subplot(311)plt.axis([0, 1000, 0, 1.25*m_])plt.plot(a)plt.subplot(312)plt.axis([0, 1000, 0, 1.25*m_])plt.plot(b)plt.subplot(313)plt.axis([0, 1000, 0, 1.25*m_])plt.plot(c)

无论如何,回到 deconvolve... 如果你用两个长度为 mn 的数组调用它,它会返回一个包含两个数组的元组:

  • 长度为 m - n + 1 的第一个是解卷积的数组,即你应该用第二个卷积得到第一个的数组
  • 第二个长度 m 是用第二个数组与第一个返回数组的卷积替换第一个数组时的错误.

I would like to use SciPy's deconvolve function to find an unknown distribution given two Gaussian distribions. There is no documentation associated with this function in SciPy, so I'm just looking for an example as to how this function can be used in my situation. For example, given two normal distributions N(100, 1), N(300, 2), I would like to understand how I can find the distribution of the deconvolution N(200, 1).

>>> sample1 = np.round(scipy.around(scipy.stats.norm(100, 1).rvs(size=1000)))
>>> sample2 = np.round(scipy.stats.norm(300, 2).rvs(size=2000))
>>> signal.deconvolve(sample1, sample2)

The above code gives me negative values, which seems wrong. How can I recover the distribtion N(200, 1) from this deconvolution? In particular, I think my problem is that I do not understand how to get the divisor.

What I would really like is to see is an example of how I can recover ~ N(200, 1) from these samples using SciPy's deconvolution.

解决方案

I think you are a little confused about your expectations... Since we all know that the convolution of two normal distributions is another normal distribution with mean the sum of the means, and variance the sum of the variances, you seem to expect that the convolution of two normal random samples will also be a normal random sample. And that just ain't so:

a = scipy.stats.norm(100, 1).rvs(size=1000)
b = scipy.stats.norm(200, 1).rvs(size=1000)
c = scipy.convolve(a, b)
plt.subplot(311)
plt.hist(a, bins=50)
plt.subplot(312)
plt.hist(a, bins=50)
plt.subplot(313)
plt.hist(a, bins=50)

You were probably thinking of something along the lines of:

a = scipy.stats.norm(100, 10).pdf(np.arange(500))
b = scipy.stats.norm(200, 20).pdf(np.arange(500))
c = scipy.convolve(a, b)
m_ = max(a.max(), b.max(), c.max())
plt.subplot(311)
plt.axis([0, 1000, 0, 1.25*m_])
plt.plot(a)
plt.subplot(312)
plt.axis([0, 1000, 0, 1.25*m_])
plt.plot(b)
plt.subplot(313)
plt.axis([0, 1000, 0, 1.25*m_])
plt.plot(c)

In any case, getting back to deconvolve... If you call it with two arrays of length m and n, it will return you a tuple with two arrays:

  • the first of length m - n + 1 is the deconvolved array, i.e. the array you should convolve the second one with, to get the first
  • the second of length m is the error in replacing the first array with the convolution of the second with the first returned one.

这篇关于SciPy 反卷积函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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