summaryrefslogtreecommitdiff
path: root/nitime/analysis/tests/test_granger.py
diff options
context:
space:
mode:
Diffstat (limited to 'nitime/analysis/tests/test_granger.py')
-rw-r--r--nitime/analysis/tests/test_granger.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/nitime/analysis/tests/test_granger.py b/nitime/analysis/tests/test_granger.py
index 9deb5ca..b9921b6 100644
--- a/nitime/analysis/tests/test_granger.py
+++ b/nitime/analysis/tests/test_granger.py
@@ -5,11 +5,12 @@ Testing the analysis.granger submodule
import numpy as np
+import numpy.testing as npt
+
import nitime.analysis.granger as gc
import nitime.utils as utils
import nitime.timeseries as ts
-import numpy.testing as npt
def test_model_fit():
"""
@@ -53,22 +54,26 @@ def test_model_fit():
ecov = np.empty((N, n_process, n_process))
for i in xrange(N):
- this_order, this_Rxx, this_coef, this_ecov = gc.fit_model(z[i][0], z[i][1], order=2)
+ this_order, this_Rxx, this_coef, this_ecov = gc.fit_model(z[i][0],
+ z[i][1],
+ order=2)
Rxx[i] = this_Rxx
coef[i] = this_coef
ecov[i] = this_ecov
- npt.assert_almost_equal(cov, np.mean(ecov,0), decimal=1)
- npt.assert_almost_equal(am, np.mean(coef,0), decimal=1)
+ npt.assert_almost_equal(cov, np.mean(ecov, axis=0), decimal=1)
+ npt.assert_almost_equal(am, np.mean(coef, axis=0), decimal=1)
# Next we test that the automatic model order estimation procedure works:
est_order = []
for i in xrange(N):
- this_order, this_Rxx, this_coef, this_ecov = gc.fit_model(z[i][0], z[i][1])
+ this_order, this_Rxx, this_coef, this_ecov = gc.fit_model(z[i][0],
+ z[i][1])
est_order.append(this_order)
npt.assert_almost_equal(order, np.mean(est_order), decimal=1)
+
def test_GrangerAnalyzer():
"""
Testing the GrangerAnalyzer class, which simplifies calculations of related
@@ -98,11 +103,11 @@ def test_GrangerAnalyzer():
g1 = gc.GrangerAnalyzer(ts1)
# Check that things have the right shapes:
- npt.assert_equal(g1.frequencies.shape[-1], g1._n_freqs//2 + 1)
- npt.assert_equal(g1.causality_xy[0,1].shape, g1.causality_yx[0,1].shape)
+ npt.assert_equal(g1.frequencies.shape[-1], g1._n_freqs // 2 + 1)
+ npt.assert_equal(g1.causality_xy[0, 1].shape, g1.causality_yx[0, 1].shape)
# Test inputting ij:
- g2 = gc.GrangerAnalyzer(ts1, ij = [(0, 1), (1, 0)])
+ g2 = gc.GrangerAnalyzer(ts1, ij=[(0, 1), (1, 0)])
# x => y for one is like y => x for the other:
npt.assert_almost_equal(g1.causality_yx[1, 0], g2.causality_xy[0, 1])