python - Unpredictable poisson noise -
i'm in process of comparing 2 sets of values apply poisson noise. below code , corresponding result:
import numpy 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 second array (with changed values) # update of value 2000... x in range(size): if not(x%220): sample[x]=2000 # reset seed same first array # 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()
my question is: why have strange values around [10335-12542] expect perfect zero?
i search info in poisson() documentation without success.
i (only) test , reproduce problem in python version 1.7.6 , 1.7.9 (it may appear on others). numpy version tested: 1.6.2 , 1.9.2
more details if print related values:
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! ??? ??? ??? ???
we see values index 10339 same index 10340 change since have sample[10340] == 2000
want. next values not expect be! appear shifted 1 index!
this implicit in algorithm calculate random sample of poisson distribution. see source code here.
the random sample calculated in conditional loop, gets new random value , returns when value above threshold based on lambda. different lambda's might take different number of tries. following random values offset, leading different results see. lateron, random values synced again.
in specific example, uses 1 random value sample #10340. after that, values offset one.
Comments
Post a Comment