您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python – 泊松过程的测试

5b51 2022/1/14 8:20:36 python 字数 3357 阅读 504 来源 www.jb51.cc/python

我想对零假设进行一些测试,即我所拥有的事件的时间是从均匀Poisson过程创建的(参见例如http://en.wikipedia.org/wiki/Poisson_process).因此,对于固定数量的事件,时间应该看起来像是在适当范围内的均匀分布的排序版本.在http://docs.scipy.org/doc/scipy-0.7.x/reference/g

概述

我想对零假设进行一些测试,即我所拥有的事件的时间是从均匀Poisson过程创建的(参见例如http://en.wikipedia.org/wiki/Poisson_process).因此,对于固定数量的事件,时间应该看起来像是在适当范围内的均匀分布的排序版本.在http://docs.scipy.org/doc/scipy-0.7.x/reference/generated/scipy.stats.kstest.html一个Kolmogorov-Smirnov测试的实现,但我不知道如何在这里使用它作为scipy.stats似乎不知道泊松过程.

举个简单的例子,这个样本数据应该为任何这样的测试提供高p值.

import random
nopoints = 100
max = 1000

points = sorted([random.randint(0,max) for j in xrange(nopoints)])

我怎样才能对这个问题进行合理的测试?

来自www.stat.wmich.edu/wang/667/classnotes/pp/pp.pdf我明白了


备注6.3(测试POISSON)上述定理也可用于检验假设
给定的计数过程是泊松过程.这可以通过观察固定时间t的过程来完成.如果在这段时间内我们观察到n次出现并且如果过程是泊松,那么无序的出现时间将独立且均匀地分布在(0,t)上.因此,我们可以通过测试假设来测试该过程是否为泊松. n个出现时间来自均匀(0,t)种群.这可以通过标准统计程序完成,例如Kolmogorov-Smirov检验.

什么是适合于chisquare测试的指数,自由度的估计

根据讲义

三种测试中的任何一种都不会拒绝同质性的含义.
说明如何使用scipy.stats的kstest和chisquare测试

# -*- coding: utf-8 -*-
"""Tests for homogeneity of Poissson Process

Created on Tue Sep 17 13:50:25 2013

Author: Josef Perktold
"""

import numpy as np
from scipy import stats

# create an example dataset
nobs = 100
times_ia = stats.expon.rvs(size=nobs) # inter-arrival times
times_a = np.cumsum(times_ia) # arrival times
t_total = times_a.max()

# not used
#times_as = np.sorted(times_a)
#times_ia = np.diff(times_as)

bin_limits = np.array([ 0.,0.5,1.,1.5,2.,np.inf])
nfreq_ia,bins_ia = np.histogram(times_ia,bin_limits)


# implication: arrival times are uniform for fixed interval
# using times.max() means we don't really have a fixed interval
print stats.kstest(times_a,stats.uniform(0,t_total).cdf)

# implication: inter-arrival times are exponential
lambd = nobs * 1. / t_total
scale = 1. / lambd

expected_ia = np.diff(stats.expon.cdf(bin_limits,scale=scale)) * nobs
print stats.chisquare(nfreq_ia,expected_ia,ddof=1)

# implication: given total number of events,distribution of times is uniform
# binned version
n_mean_bin = 10
n_bins_a = nobs // 10
bin_limits_a = np.linspace(0,t_total+1e-7,n_bins_a + 1)
nfreq_a,bin_limits_a = np.histogram(times_a,bin_limits_a)
# expect uniform distributed over every subinterval
expected_a = np.ones(n_bins_a) / n_bins_a * nobs
print stats.chisquare(nfreq_a,expected_a,ddof=1)

总结

以上是编程之家为你收集整理的python – 泊松过程的测试全部内容,希望文章能够帮你解决python – 泊松过程的测试所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶