In [1]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [1]:
from numpy import random

In [3]:
random.poisson?

In [5]:
s = random.poisson(1,1000)

In [6]:
s.view()


Out[6]:
array([0, 1, 1, 2, 1, 1, 3, 1, 1, 1, 1, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 1, 1,
       0, 1, 2, 1, 1, 1, 1, 1, 1, 1, 0, 0, 4, 0, 0, 0, 2, 1, 2, 3, 0, 1, 3,
       1, 2, 3, 0, 1, 1, 1, 1, 1, 0, 1, 3, 2, 1, 0, 2, 0, 1, 1, 1, 2, 1, 3,
       0, 1, 1, 0, 0, 1, 1, 0, 3, 1, 1, 0, 2, 1, 2, 1, 2, 0, 1, 1, 0, 0, 0,
       1, 1, 0, 2, 2, 0, 2, 0, 2, 1, 1, 0, 0, 0, 2, 3, 1, 2, 0, 2, 1, 0, 2,
       1, 1, 2, 2, 2, 1, 0, 2, 1, 1, 2, 0, 0, 1, 1, 0, 2, 0, 1, 0, 0, 1, 0,
       1, 0, 2, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1, 2, 0, 2, 1, 0, 1, 1, 3, 3, 3,
       2, 1, 0, 0, 3, 0, 0, 1, 2, 0, 0, 0, 1, 0, 1, 0, 0, 2, 1, 1, 0, 0, 1,
       0, 3, 1, 3, 2, 2, 2, 0, 0, 4, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 2, 4, 0,
       0, 1, 1, 2, 2, 1, 0, 1, 0, 0, 0, 1, 3, 0, 0, 0, 0, 1, 1, 0, 2, 1, 1,
       0, 1, 0, 0, 1, 0, 0, 3, 2, 2, 0, 0, 2, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1,
       3, 2, 0, 0, 0, 2, 1, 0, 2, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 1, 0, 1, 2,
       1, 0, 2, 0, 2, 0, 0, 1, 1, 1, 1, 0, 0, 2, 2, 1, 0, 1, 3, 1, 0, 3, 2,
       1, 1, 0, 0, 1,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 1, 2, 0, 0, 0, 1, 1, 0, 2, 0, 0, 3,
       0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 2])

In [18]:
plot(s)


Out[18]:
[<matplotlib.lines.Line2D at 0x106ab7ad0>]

In [23]:
hist(s,50)
show()



In [24]:
s.mean()


Out[24]:
0.99199999999999999

In [25]:
s.std()


Out[25]:
0.99996799948797799

In [19]:
#Calculate Auto-correlation function based on fft
#only support 1D
#for cross correlation, in optimisation
#input data suggest to be numpy.ndarray(1d) or pandas.core.series.Series
def acf_fft(data):
    """ Series or 1darray ---> Series 
        Calculate the auto correlation function of input data
    """
    data_mean = data.mean()
    
    #Step 1: calculate fft for data
    fft_data = fft.fft(data)
    
    #Step 2: Calculate the pow spectrom,
    S_f = fft_data.__mul__(fft_data.conj())
                           
    #Step 3: calculate auto correlation function, result as g(\tau)
    acf = ifft(S_f)/fft_data[0]/data_mean - 1;
    
    #Clean up, return half of data
    acf = acf.real[0:int(len(acf)/2)]
    return acf

In [26]:
plot(acf_fft(s),'o')


Out[26]:
[<matplotlib.lines.Line2D at 0x106ca6190>]

In [7]:
import os

In [8]:
os?

In [ ]: