Created
September 30, 2015 15:26
-
-
Save pravsripad/22e913c134c0cb4b954b to your computer and use it in GitHub Desktop.
compute recurrence in networks
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 | |
from pyunicorn.timeseries import RecurrenceNetwork | |
from matplotlib import pyplot as pl | |
from mpl_toolkits.mplot3d import Axes3D | |
# Loading the data for 1 subject | |
data = np.load('all_fmri_data.npy')[0] | |
pl.plot(data) | |
pl.show() | |
# Find a good time lag for embedding | |
possible_lags = np.arange(1, data.size) | |
for lag in possible_lags: | |
ac = np.corrcoef(data[lag:], data[:-lag])[0, 1] | |
# Stop as soon as AC(tau) drops below 1/e | |
if ac <= 1. / np.exp(1): | |
break | |
print "Using lag:", lag | |
# Construct a recurrence network | |
r_net = RecurrenceNetwork(data, dim=3, tau=lag, recurrence_rate=0.05) | |
r_net.save("ice_core_recurrence_network.gml") | |
# Visualize the embedded time series | |
embedded_ts = r_net.embedding | |
x, y, z = embedded_ts.T | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection='3d') | |
ax.plot(x, y, z) | |
plt.show() | |
# Visualize the recurrence matrix | |
adjacency_matrix = r_net.adjacency | |
plt.imshow(adjacency_matrix, cmap="binary") | |
plt.show() | |
# Show some measures | |
print "Transitivity:", r_net.transitivity() | |
print "Determinism", r_net.determinism() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment