python - 不可预测的泊松噪声

标签 python numpy random noise poisson

我正在比较两组应用了泊松噪声的值。 下面是我的代码和相应的结果:

import numpy as np
import pylab

size = 14000

# 1) Creating first array
np.random.seed(1)
sample = np.zeros((size),dtype="int")+1000
# Applying poisson noise
random_sample1 = np.random.poisson(sample)

# 2) Creating the second array (with some changed values)
# Update some of the value to 2000...
for x in range(size):
  if not(x%220):
    sample[x]=2000
# Reset the seed to the SAME as for the first array
# so that poisson shall rely on same random.
np.random.seed(1)
# Applying poisson noise
random_sample2 = np.random.poisson(sample)

# Display diff result
pylab.plot(random_sample2-random_sample1)
pylab.show()

poisson_pb

我的问题是:为什么我在 [10335-12542] 附近有这个奇怪的值,而我期望的只是一个完美的零?

我在 poisson() 中搜索信息文档没有成功。

我(仅)在 python 版本 1.7.6 和 1.7.9 中测试并重现该问题(可能会出现在其他版本上)。 测试的 Numpy 版本:1.6.2 和 1.9.2

如果我打印相关值,则会获得更多详细信息:

random_sample1[10335:10345]
[ 977 1053  968 1032 1051  953 1036 1035  967  954]
#  OK  OK    OK   OK   OK  OK!  ???  ???  ???  ???
random_sample2[10335:10345]
[ 977 1053  968 1032 1051 2051 1035  967  954 1034]
#  OK  OK    OK   OK   OK  OK!  ???  ???  ???  ???

我们清楚地看到索引 10339 之前的值完全相同,然后索引 10340 的值发生了变化,因为我们有 sample[10340] == 2000 这正是我们想要的。但接下来的值并不是我们期望的!它们似乎是从 1 个索引转移过来的!

最佳答案

这隐含在计算泊松分布随机样本的算法中。请参阅source code here.

随机样本在条件循环中计算,该循环获取一个新的随机值,并在该值高于基于 lambda 的某个阈值时返回。对于不同的 lambda,可能需要不同次数的尝试。随后的随机值将被偏移,导致您看到不同的结果。稍后,随机值再次同步。

在您的具体示例中,它使用一个额外的随机值来获取样本 #10340。之后,所有值都会偏移一。

关于python - 不可预测的泊松噪声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31289682/

相关文章:

python - 在 OS X Lion 的 pycharm 中使用 emacs 绑定(bind)

python - scrapy如何正确使用Rules、restrict_xpaths抓取解析URL?

Python之libfreenect Kinect 1深度图数据格式

python - 从一组 3D 点中采样 N 个点,使最小距离最大化

从序列内部正确转换为 ndarray 的 Numpy 可转换类?

php - 重定向到新页面后 MySQL 数据库未加载

php - 在 mysql 中只返回一次随机行

r - 为什么RUnit更改我的随机数?

python-Levenshtein比率计算

python - 按 id 过滤最大数量