You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use upper triangle instead of lower in drawmatrix_channels()
This is to fix the issue #173.
`GrangerAnalyzer` put its outputs in the upper triangle only, which
would be removed by `drawmatrix_channels()` which takes only the lower
triangle, creating an array of all nans.
This fix changes the `drawmatrix_channels()` to let it take the upper
triangle instead, then transpose the matrix before plotting.
Another possible fix is to transposes outputs of `GrangerAnalyzer` into the
lower triangle. However this would break with the old behavior including
failing unit tests (`test_granger.py`).
Another reason to change the `drawmatrix_channels()` instead is that
other similar functions, including `CorrelationAnalyzer.xcorr`,
`CoherenceAnalyzer.coherence` all computes the upper triangle first,
then transpose to fill the lower, e.g.
```
idx = tril_indices(tseries_length, -1)
xcorr[idx[0], idx[1], ...] = xcorr[idx[1], idx[0], ...]
```
But granger is a bit different in that it is not symmetrical so we don't
just mirror the upper triangle into the low.
Another reason to keep the upper triangle in granger is that the
indices of pairs argument (`ij`) of the `GrangerAnalyzer.__init__()`
translates more naturally to the upper triangle indices, e.g. pair (0,
1) -> (row-0, column-1), (2, 4) -> (row-2, column-4). If feels more
intuitive (to me at least) to preserve this, rather than doing a
transpose here. This also passes the `test_granger.py` unit test.
Related changes needed:
in `doc/examples/multi_taper_coh.py`, I have to change the nested `for` loop
so the results are put into the upper triangle. The old `for` loop:
```
for i in range(nseq):
for j in range(i):
```
New:
```
for i in range(nseq):
for j in range(i, nseq):
```
This is also consistent with `CoherenceAnalyzer` etc..
I've tested all scripts in the `doc/examples` folder that involve the
`drawmatrix_channels()` function. All figures look good.
0 commit comments