def test_visualise_multivariate_te(): """Visualise output of multivariate TE estimation.""" data = Data() data.generate_mute_data(100, 5) settings = { 'cmi_estimator': 'JidtKraskovCMI', 'max_lag_sources': 5, 'min_lag_sources': 4, 'n_perm_max_stat': 25, 'n_perm_min_stat': 25, 'n_perm_omnibus': 50, 'n_perm_max_seq': 50, } network_analysis = MultivariateTE() results = network_analysis.analyse_network(settings, data, targets=[0, 1, 2]) # generate graph plots visualise_graph.plot_selected_vars(results, target=1, sign_sources=False) plt.show() visualise_graph.plot_network(results, fdr=False) plt.show() visualise_graph.plot_network(results, fdr=True) plt.show() visualise_graph.plot_selected_vars(results, target=1, sign_sources=True) plt.show()
def test_plot_network(): """Test results class for multivariate TE network inference.""" covariance = 0.4 n = 10000 delay = 1 normalisation = False source = np.random.normal(0, 1, size=n) target_1 = (covariance * source + (1 - covariance) * np.random.normal(0, 1, size=n)) target_2 = (covariance * source + (1 - covariance) * np.random.normal(0, 1, size=n)) source = source[delay:] target_1 = target_1[:-delay] target_2 = target_2[:-delay] # Discretise data for speed settings_dis = {'discretise_method': 'equal', 'n_discrete_bins': 5} est = JidtDiscreteCMI(settings_dis) source_dis, target_1_dis = est._discretise_vars(var1=source, var2=target_1) source_dis, target_2_dis = est._discretise_vars(var1=source, var2=target_2) data = Data(np.vstack((source_dis, target_1_dis, target_2_dis)), dim_order='ps', normalise=normalisation) settings = { 'cmi_estimator': 'JidtDiscreteCMI', 'discretise_method': 'none', 'n_discrete_bins': 5, # alphabet size of the variables analysed 'n_perm_max_stat': 21, 'n_perm_omnibus': 30, 'n_perm_max_seq': 30, 'min_lag_sources': 1, 'max_lag_sources': 2, 'max_lag_target': 1, 'alpha_fdr': 0.5 } nw = MultivariateTE() # Analyse a single target and the whole network res_single = nw.analyse_single_target(settings=settings, data=data, target=1) res_network = nw.analyse_network(settings=settings, data=data) graph, fig = plot_network(res_single, 'max_te_lag', fdr=False) plt.close(fig) graph, fig = plot_network(res_network, 'max_te_lag', fdr=False) plt.close(fig) for sign_sources in [True, False]: graph, fig = plot_selected_vars(res_network, target=1, sign_sources=True, fdr=False) plt.close(fig)
def test_visualise_multivariate_te(): """Visualise output of multivariate TE estimation.""" dat = Data() dat.generate_mute_data(100, 5) settings = { 'cmi_estimator': 'JidtKraskovCMI', 'max_lag_sources': 5, 'min_lag_sources': 4, 'n_perm_max_stat': 25, 'n_perm_min_stat': 25, 'n_perm_omnibus': 50, 'n_perm_max_seq': 50, } network_analysis = MultivariateTE() res = network_analysis.analyse_network(settings, dat, targets=[0, 1, 2]) vis.plot_network(res)
def test_visualise_multivariate_te(): """Visualise output of multivariate TE estimation.""" dat = Data() dat.generate_mute_data(100, 5) max_lag = 5 min_lag = 4 analysis_opts = { 'cmi_calc_name': 'jidt_kraskov', 'n_perm_max_stat': 25, 'n_perm_min_stat': 25, 'n_perm_omnibus': 50, 'n_perm_max_seq': 50, } network_analysis = Multivariate_te(max_lag, min_lag, analysis_opts) res = network_analysis.analyse_network(dat, targets=[0, 1, 2]) vis.plot_network(res)
# Import classes from idtxl.multivariate_te import MultivariateTE from idtxl.data import Data from idtxl.visualise_graph import plot_network import matplotlib.pyplot as plt # a) Generate test data data = Data() data.generate_mute_data(n_samples=1000, n_replications=5) # b) Initialise analysis object and define settings network_analysis = MultivariateTE() settings = {'cmi_estimator': 'JidtGaussianCMI', 'max_lag_sources': 5, 'min_lag_sources': 1} # c) Run analysis results = network_analysis.analyse_network(settings=settings, data=data) # d) Plot inferred network to console and via matplotlib results.print_edge_list(weights='max_te_lag', fdr=False) plot_network(results=results, weights='max_te_lag', fdr=False) plt.show()
"""Plot graph output from multivariate TE estimation. author: patricia """ from idtxl.data import Data from idtxl.multivariate_te import MultivariateTE from idtxl import visualise_graph # Generate some example output data = Data() data.generate_mute_data(n_replications=2, n_samples=500) print('Demo data with {0} procs, {1} samples, {2} reps.'.format( data.n_processes, data.n_samples, data.n_replications)) settings = { 'cmi_estimator': 'JidtKraskovCMI', 'max_lag_sources': 3, 'max_lag_target': 3, 'min_lag_sources': 1 } mte = MultivariateTE() res_single = mte.analyse_single_target(settings=settings, data=data, target=3) res_full = mte.analyse_network(settings=settings, data=data) # generate graph plots g_single = visualise_graph.plot_selected_vars(res_single, mte) g_full = visualise_graph.plot_network(res_full)
# Import classes from idtxl.bivariate_te import BivariateTE from idtxl.data import Data from idtxl.visualise_graph import plot_network import matplotlib.pyplot as plt # a) Generate test data data = Data() data.generate_mute_data(n_samples=1000, n_replications=5) # b) Initialise analysis object and define settings network_analysis = BivariateTE() settings = { 'cmi_estimator': 'JidtGaussianCMI', 'max_lag_sources': 5, 'min_lag_sources': 1 } # c) Run analysis results = network_analysis.analyse_network(settings=settings, data=data) # d) Plot inferred network to console and via matplotlib results.print_edge_list(weights='max_te_lag', fdr=False) plot_network(results=results, weights='max_te_lag', fdr=False) plt.show()
"""Plot graph output from multivariate TE estimation. author: patricia """ from idtxl.data import Data from idtxl.multivariate_te import Multivariate_te from idtxl import visualise_graph # Generate some example output data = Data() data.generate_mute_data(n_replications=2, n_samples=500) print('Demo data with {0} procs, {1} samples, {2} reps.'.format( data.n_processes, data.n_samples, data.n_replications)) opts = {'cmi_calc_name': 'jidt_kraskov'} mte = Multivariate_te(max_lag_sources=3, max_lag_target=3, min_lag_sources=1, options=opts) res_single = mte.analyse_single_target(data=data, target=3) res_full = mte.analyse_network(data=data) # generate graph plots g_single = visualise_graph.plot_selected_vars(res_single, mte) g_full = visualise_graph.plot_network(res_full)
import pickle from idtxl.visualise_graph import plot_network import matplotlib.pyplot as plt with open('target_results/network_center_full.p', 'rb') as pkl_file: center_res = pickle.load(pkl_file) # d) Plot inferred network to console and via matplotlib center_res.print_edge_list(weights='max_te_lag', fdr=False) plot_network(results=center_res, weights='max_te_lag', fdr=False) # with open('network_preborder_full.p', 'rb') as pkl_file: # pre_border_res = pickle.load(pkl_file) # pre_border_res.print_edge_list(weights='max_te_lag', fdr=False) # plot_network(results=pre_border_res, weights='max_te_lag', fdr=False) plt.show()
def run(self): network_analysis = MultivariateTE() results = network_analysis.analyse_network(settings=self.settings, data=self.data) #results.print_edge_list(weights='max_te_lag', fdr=False) return plot_network(results=results, weights='max_te_lag', fdr=False)
'min_lag_sources': 1, 'add_conditionals': [(0, 1), (0, 2), (1, 1), (1, 2)] } # c) Run analysis center_res = network_analysis.analyse_network(settings=settings, data=data_center, targets=[6], sources=[2, 3, 4, 5]) pre_border_res = network_analysis.analyse_network(settings=settings, data=data_pre_border, targets=[6], sources=[2, 3, 4, 5]) # d) Plot inferred network to console and via matplotlib plot_network(res=center_res, n_nodes=data_center.n_processes) # print_res_to_console(data=data_pre_border, res=pre_border_res) # plot_network(res=pre_border_res, n_nodes=data_pre_border.n_processes) pickle.dump(center_res, open('network_center_b2m1.p', 'wb')) pickle.dump(pre_border_res, open('network_preborder_b2m1.p', 'wb')) # pickle.dump(res1, open('results_all_trials.p', 'wb')) # results = pickle.load(open('results.p', 'rb')) # compare # center_res = pickle.load(open('results_all_trials_center_smallsample.p', 'rb')) # pre_border_res = pickle.load(open('results_all_trials_pre_border_2rep.p', 'rb')) # # comparison_settings = { # 'stats_type': 'independent',