Skip to content

Commit

Permalink
new possibility of plotting and new example of usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dokato committed Aug 17, 2015
1 parent 8b5727d commit 1658e81
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
3 changes: 2 additions & 1 deletion connectivipy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# plain plotting from values
def plot_conn(values, name='', fs=1, ylim=None, xlim=None, show=True):
'''
Plot connectivity estimation results.
Plot connectivity estimation results. Allows to plot your results
without using *Data* class.
Args:
*values* : numpy.array
Expand Down
4 changes: 2 additions & 2 deletions connectivipy/mvar/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def mvar_gen(Acf, n, omit=500):
Generating data point from MVAR coefficiencs matrix *Acf*.
Args:
*Acf* : numpy.array
array of dimension kxkxp where *k* is number of channels and
array in shape of (p,k,k) where *k* is number of channels and
*p* is a model order.
*n* : int
number of data points.
Expand All @@ -36,7 +36,7 @@ def mvar_gen_inst(Acf, n, omit=500):
instantenous interaction not as in *mvar_gen* one data point lagged.
Args:
*Acf* : numpy.array
array of dimension kxkxp where *k* is number of channels and
array in shape of (p,k,k) where *k* is number of channels and
*p* is a model order.
*n* : int
number of data points.
Expand Down
3 changes: 0 additions & 3 deletions doc/conn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
Connectvity
==================

.. automodule:: __init__
:members:

Connectivity methods classes.

.. automodule:: conn
Expand Down
5 changes: 5 additions & 0 deletions doc/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ Data loading

.. automodule:: load.loaders
:members:

Additional functions
########

.. autofunction:: __init__.plot_conn
45 changes: 45 additions & 0 deletions examples/example2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import numpy as np
import matplotlib.pyplot as plt
import connectivipy as cp
from connectivipy.mvar.fitting import mvar_gen

fs = 256.
acf = np.zeros((3,3,3))
# matrix shape meaning (p,k,k) k - number of channels,
# p - order of mvar parameters

acf[0,0,0] = 0.3
acf[0,1,0] = 0.6
acf[1,0,0] = 0.1
acf[1,1,1] = 0.2
acf[1,2,0] = 0.6
acf[2,2,2] = 0.2
acf[2,1,0] = 0.4

# generate 3-channel signal from matrix above
y = mvar_gen(acf,int(10e4))

# assign static class cp.Mvar to variable mv
mv = cp.Mvar

# find best model order
best, crit = mv._order_akaike(y,15,'vm')
plt.plot(1+np.arange(len(crit)),crit,'g')
plt.show()
print best
# here we know that this is 3 but in real-life cases
# we are always uncertain about it

# now let's fit parameters to the signal
av, vf = mv.fit(y, best, 'vm')

# and check whether values are correct +/- 0.01
print np.allclose(acf, av, 0.01, 0.01)

# now we can calculate Directed Transfer Function from the data
dtf = cp.conn.DTF()
dtfval = dtf.calculate(av, vf, 128)
# all possible methods are visible in that dictionary:
print cp.conn.conn_estim_dc.keys()

cp.plot_conn(dtfval,'DTF values', fs)

0 comments on commit 1658e81

Please sign in to comment.