DELAY_MIN = 1 DELAY_MAX = 6 corrMat, corrDelMat = crossCorr(data, DELAY_MIN, DELAY_MAX, est='corr') sprMat, sprDelMat = crossCorr(data, DELAY_MIN, DELAY_MAX, est='spr') rez_file_h5.close() ####################### # Plot ####################### plotImshowMat([corrMat, corrDelMat, sprMat, sprDelMat], ['Corr', 'Spr', 'CorrDel', 'SprDel'], "Cross-correlation for " + filename, shape=(2, 2), lims=[[-1, 1], [0, DELAY_MAX], [-1, 1], [0, DELAY_MAX]], draw=True, savename=filename.split('.')[0] + '.png') ######################## ## Cross-correlation with velocities ######################## #data2 = np.vstack((DS1.data[:, :-1], DS1.data[:, 1:] - DS1.data[:, :-1])) #print(data2.shape) #corrMat, corrDelMat = crossCorr(data2, DELAY_MIN, DELAY_MAX, est='corr') #sprMat, sprDelMat = crossCorr(data2, DELAY_MIN, DELAY_MAX, est='spr')
# b) Initialise analysis object and define settings network_analysis = BivariateTE() settings = { 'cmi_estimator': 'JidtGaussianCMI', 'max_lag_sources': DELAY_MAX, 'min_lag_sources': DELAY_MIN } # c) Run analysis results = network_analysis.analyse_network(settings=settings, data=dataIDTxl) # d) Convert results into comfortable form results_mat = idtxlResults2matrix(results, N_NODE, method='BivariateTE') rez_file_h5.close() ####################### # Plot Results ####################### plotImshowMat(results_mat, ['BivariateTE', "Delays", "p-value"], 'IDTxl analysis of ' + filename, (1, 3), lims=[[0, 1], [0, DELAY_MAX], [0, 1]], draw=True, savename=filename.split('.')[0] + '.png') plt.show()
DELAY_MAX = 2 #data = np.random.uniform(0, 1, N_NODE*N_DATA).reshape((N_NODE, N_DATA)) # Generate progressively more random data data = np.zeros((N_NODE, N_DATA)) data[0] = np.random.normal(0, 1, N_DATA) for i in range(1, N_NODE): data[i] = np.hstack((data[i-1][1:], data[i-1][0])) corrMat, corrDelMat = crossCorr(data, DELAY_MIN, DELAY_MAX, est='corr') sprMat, sprDelMat = crossCorr(data, DELAY_MIN, DELAY_MAX, est='spr') plotImshowMat( [corrMat, corrDelMat, sprMat, sprDelMat], np.array(["Correlation", "Corr. Delays", "Spearmann", "Spr. Delays"]), "Test 1: Channels are shifts of the same data", (2, 2), lims = [[-1, 1], [0, DELAY_MAX], [-1, 1], [0, DELAY_MAX]], draw = True ) ''' Test 2: Generate random data, all copies of each other, each following one a bit more noisy than prev Expected outcomes: * Correlation decreases with distance between nodes, as they are separated by more noise * Correlation should be approx the same for any two nodes given fixed distance between them ''' N_NODE = 5 N_DATA = 1000
# 4) For each pair, select connection with strongest TE, out of those that are not NAN TE_mat_2D = np.zeros((N_NODE, N_NODE)) + np.nan P_mat_2D = np.zeros((N_NODE, N_NODE)) + np.nan for i in range(N_NODE): for j in range(N_NODE): maxThis = np.nanmax(TE_mat_3D[i, j]) if not np.isnan(maxThis): TE_mat_2D[i, j] = maxThis P_mat_2D[i, j] = P_mat_3D[i,j,np.nanargmax(TE_mat_3D[i,j])] else: Lag_mat_2D[i, j] = np.nan ####################### # Plot Results ####################### plotImshowMat( [TE_mat_2D, Lag_mat_2D, P_mat_2D, numNotNAN], ['NiftyTE', "Delays", "p-value", "count"], 'NIfTy analysis of ' + filename, (1, 4), lims = [[0, 1], [0, DELAY_MAX], [0, 1], [0, N_NODE]], draw = True, savename = filename.split('.')[0] + '.png' ) plt.show()
'cmi_estimator': 'JidtGaussianCMI', 'max_lag_sources': DELAY_MAX, 'min_lag_sources': DELAY_MIN } # c) Run analysis results_lst = [ net_analysis.analyse_network(settings=settings, data=dataIDTxl) for net_analysis in network_analysis_lst ] # d) Convert results into comfortable form results_mat_lst = [ idtxlResults2matrix(results, N_NODE, method=method) for results, method in zip(results_lst, method_lst) ] ####################### # Plot Results ####################### for results_matrices, method, title in zip(results_mat_lst, method_lst, title_lst): plotImshowMat(results_matrices, np.array([method, "Delays", "p-value"]), title, (1, 3), lims=[[0, 1], [0, DELAY_MAX], [0, 1]], draw=True) plt.show()