Created
October 1, 2015 15:59
-
-
Save pravsripad/aa9edb92096133524702 to your computer and use it in GitHub Desktop.
Compute average mi and xcross across the data.
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
import numpy as np | |
import pyunicorn | |
import matplotlib.pyplot as pl | |
pl.ion() | |
data = np.load('all_fmri_data.npy') | |
mi_all = np.zeros((10, 90, 90)) | |
xcorr_all = np.zeros((10, 90, 90)) | |
from pyunicorn import funcnet | |
for subj in range(10): | |
ca = funcnet.CouplingAnalysis(data[subj].T) | |
mi_all[subj] = ca.mutual_information(tau_max=0, bins=4)[0] | |
xcorr_all[subj] = ca.cross_correlation(tau_max=0) | |
xcorr_all[subj] = (xcorr_all[subj] - np.min(xcorr_all[subj])) / (np.max(xcorr_all[subj]) - np.min(xcorr_all[subj])) | |
assert xcorr_all.max() <= 1 and xcorr_all.min() >= 0., 'Not normalized properly...' | |
avg_mi = np.mean(mi_all, axis=0) | |
avg_mi = avg_mi - np.eye(len(avg_mi)) | |
avg_xcorr = np.mean(xcorr_all, axis=0) | |
avg_xcorr = avg_xcorr - np.eye(len(avg_xcorr)) | |
# read the channel names from the numpy file | |
channel_names = np.load('labels.npy') | |
# initializing the network | |
net = pyunicorn.Network(avg_mi) | |
#surr = net.ErdosRenyi(n_nodes=net.N, n_links=net.n_links) | |
link_weights = np.abs(avg_mi) | |
net.set_link_attribute(attribute_name="weight", values=link_weights) | |
net.set_node_attribute(attribute_name="label", values=channel_names) | |
print 'Saving the file...' | |
net.save('avg_mi.gml') # save the network | |
# comute the network for average cross correlation | |
net2 = pyunicorn.Network(avg_xcorr) | |
#surr = net.ErdosRenyi(n_nodes=net.N, n_links=net.n_links) | |
link_weights = np.abs(avg_xcorr) | |
net2.set_link_attribute(attribute_name="weight", values=link_weights) | |
net2.set_node_attribute(attribute_name="label", values=channel_names) | |
net2.save('avg_xcorr.gml') # save the network |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment