In [1]:
import functools
import geopy
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pyproj
import requests
import scipy as sp
import rtree
import seaborn as sb
from scipy import signal
from statsmodels.tsa.arima_process import arma_generate_sample 
# import shapely
import shapely.geometry
%pylab inline
import data_munging


Populating the interactive namespace from numpy and matplotlib
/home/zblan/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py:872: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
  warnings.warn(self.msg_depr % (key, alt_key))

In [2]:
length_road = 1000
x = np.array(range(1000))

In [3]:
help(arma_generate_sample)


Help on function arma_generate_sample in module statsmodels.tsa.arima_process:

arma_generate_sample(ar, ma, nsample, sigma=1, distrvs=<built-in method randn of mtrand.RandomState object>, burnin=0)
    Generate a random sample of an ARMA process
    
    Parameters
    ----------
    ar : array_like, 1d
        coefficient for autoregressive lag polynomial, including zero lag
    ma : array_like, 1d
        coefficient for moving-average lag polynomial, including zero lag
    nsample : int
        length of simulated time series
    sigma : float
        standard deviation of noise
    distrvs : function, random number generator
        function that generates the random numbers, and takes sample size
        as argument
        default: np.random.randn
        TODO: change to size argument
    burnin : integer (default: 0)
        to reduce the effect of initial conditions, burnin observations at the
        beginning of the sample are dropped
    
    Returns
    -------
    sample : array
        sample of ARMA process given by ar, ma of length nsample
    
    Notes
    -----
    As mentioned above, both the AR and MA components should include the
    coefficient on the zero-lag. This is typically 1. Further, due to the
    conventions used in signal processing used in signal.lfilter vs.
    conventions in statistics for ARMA processes, the AR paramters should
    have the opposite sign of what you might expect. See the examples below.
    
    Examples
    --------
    >>> import numpy as np
    >>> np.random.seed(12345)
    >>> arparams = np.array([.75, -.25])
    >>> maparams = np.array([.65, .35])
    >>> ar = np.r_[1, -arparams] # add zero-lag and negate
    >>> ma = np.r_[1, maparams] # add zero-lag
    >>> y = sm.tsa.arma_generate_sample(ar, ma, 250)
    >>> model = sm.tsa.ARMA(y, (2, 2)).fit(trend='nc', disp=0)
    >>> model.params
    array([ 0.79044189, -0.23140636,  0.70072904,  0.40608028])


In [4]:
arparams = np.array([.75, .25])
maparams = np.array([.65, .35])
ar = np.r_[1, -arparams] # add zero-lag and negate
ma = np.r_[1, maparams] # add zero-lag
y = arma_generate_sample(ar, ma, 1000, burnin=1000, sigma=1.0)
plt.plot(y)
fig = plt.gcf()
fig.set_size_inches(18.5, 10.5)
plt.show()



In [5]:
arparams = np.array([1.0])
maparams = np.array([.02] * 50)
ar = np.r_[1, -arparams] # add zero-lag and negate
ma = np.r_[1, maparams] # add zero-lag
y = arma_generate_sample(ar, ma, 1000, burnin=1000, sigma=2.0)
interp_y = sp.interpolate.UnivariateSpline(x=x,y=y, s=0)
interp_y.set_smoothing_factor(100000)
plt.plot(x, y, 'bo', label='Data')
plt.plot(x, interp_y(x), 'r-', label='Spline')
fig = plt.gcf()
fig.set_size_inches(18.5, 10.5)
plt.show()



In [6]:
arparams = np.array([.40, .25, .20, .10])
maparams = np.array([.65, .10, .10, .10, .05])
ar = np.r_[1, -arparams] # add zero-lag and negate
ma = np.r_[1, maparams] # add zero-lag
y = arma_generate_sample(ar, ma, 1000, burnin=1000)
plt.plot(y)
fig = plt.gcf()
fig.set_size_inches(18.5, 10.5)
plt.show()