xhat5, err5 = VARMA(x, B, C) #print err5 #in differences #VARMA(np.diff(x,axis=0),B,C) #Note: # * signal correlate applies same filter to all columns if kernel.shape[1]<K # e.g. signal.correlate(x0,np.ones((3,1)),'valid') # * if kernel.shape[1]==K, then `valid` produces a single column # -> possible to run signal.correlate K times with different filters, # see the following example, which replicates VAR filter x0 = np.column_stack([np.arange(T), 2 * np.arange(T)]) B[:, :, 0] = np.ones((P, K)) B[:, :, 1] = np.ones((P, K)) B[1, 1, 1] = 0 xhat0 = VAR(x0, B) xcorr00 = signal.correlate(x0, B[:, :, 0]) #[:,0] xcorr01 = signal.correlate(x0, B[:, :, 1]) print np.all( signal.correlate(x0, B[:, :, 0], 'valid')[:-1, 0] == xhat0[P:, 0]) print np.all( signal.correlate(x0, B[:, :, 1], 'valid')[:-1, 0] == xhat0[P:, 1]) #import error #from movstat import acovf, acf from gwstatsmodels.tsa.stattools import acovf, acf aav = acovf(x[:, 0]) print aav[0] == np.var(x[:, 0]) aac = acf(x[:, 0])
plt.plot(wm,sdm/sdm[0], '-', wm[maxind], sdm[maxind]/sdm[0], 'o') else: plt.plot(wm, sdm, '-', wm[maxind], sdm[maxind], 'o') plt.title('matplotlib') if hastalkbox: sdp, wp = stbs.periodogram(x) plt.subplot(2,3,3) if rescale: plt.plot(wp,sdp/sdp[0]) else: plt.plot(wp, sdp) plt.title('stbs.periodogram') xacov = acovf(x, unbiased=False) plt.subplot(2,3,4) plt.plot(xacov) plt.title('autocovariance') nr = len(x)#*2/3 #xacovfft = np.fft.fft(xacov[:nr], 2*nr-1) xacovfft = np.fft.fft(np.correlate(x,x,'full')) #abs(xacovfft)**2 or equivalently xacovfft = xacovfft * xacovfft.conj() plt.subplot(2,3,5) if rescale: plt.plot(xacovfft[:nr]/xacovfft[0]) else: plt.plot(xacovfft[:nr])
arrvs = ar_generator() ##arma = ARIMA() ##res = arma.fit(arrvs[0], 4, 0) arma = ARIMA(arrvs[0]) res = arma.fit((4,0, 0)) print res[0] acf1 = acf(arrvs[0]) acovf1b = acovf(arrvs[0], unbiased=False) acf2 = autocorr(arrvs[0]) acf2m = autocorr(arrvs[0]-arrvs[0].mean()) print acf1[:10] print acovf1b[:10] print acf2[:10] print acf2m[:10] x = arma_generate_sample([1.0, -0.8], [1.0], 500) print acf(x)[:20] import gwstatsmodels.api as sm print sm.regression.yule_walker(x, 10) import matplotlib.pyplot as plt #ax = plt.axes()
xhat5, err5 = VARMA(x,B,C) #print err5 #in differences #VARMA(np.diff(x,axis=0),B,C) #Note: # * signal correlate applies same filter to all columns if kernel.shape[1]<K # e.g. signal.correlate(x0,np.ones((3,1)),'valid') # * if kernel.shape[1]==K, then `valid` produces a single column # -> possible to run signal.correlate K times with different filters, # see the following example, which replicates VAR filter x0 = np.column_stack([np.arange(T), 2*np.arange(T)]) B[:,:,0] = np.ones((P,K)) B[:,:,1] = np.ones((P,K)) B[1,1,1] = 0 xhat0 = VAR(x0,B) xcorr00 = signal.correlate(x0,B[:,:,0])#[:,0] xcorr01 = signal.correlate(x0,B[:,:,1]) print np.all(signal.correlate(x0,B[:,:,0],'valid')[:-1,0]==xhat0[P:,0]) print np.all(signal.correlate(x0,B[:,:,1],'valid')[:-1,0]==xhat0[P:,1]) #import error #from movstat import acovf, acf from gwstatsmodels.tsa.stattools import acovf, acf aav = acovf(x[:,0]) print aav[0] == np.var(x[:,0]) aac = acf(x[:,0])
plt.plot(wm, sdm / sdm[0], '-', wm[maxind], sdm[maxind] / sdm[0], 'o') else: plt.plot(wm, sdm, '-', wm[maxind], sdm[maxind], 'o') plt.title('matplotlib') if hastalkbox: sdp, wp = stbs.periodogram(x) plt.subplot(2, 3, 3) if rescale: plt.plot(wp, sdp / sdp[0]) else: plt.plot(wp, sdp) plt.title('stbs.periodogram') xacov = acovf(x, unbiased=False) plt.subplot(2, 3, 4) plt.plot(xacov) plt.title('autocovariance') nr = len(x) #*2/3 #xacovfft = np.fft.fft(xacov[:nr], 2*nr-1) xacovfft = np.fft.fft(np.correlate(x, x, 'full')) #abs(xacovfft)**2 or equivalently xacovfft = xacovfft * xacovfft.conj() plt.subplot(2, 3, 5) if rescale: plt.plot(xacovfft[:nr] / xacovfft[0]) else: plt.plot(xacovfft[:nr])