-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new possibility of plotting and new example of usage
- Loading branch information
Showing
5 changed files
with
54 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |