def generate_gauss_data(n_replications=1, discrete=False): settings = {'discretise_method': 'equal', 'n_discrete_bins': 5} est = JidtDiscreteCMI(settings) covariance_1 = 0.4 covariance_2 = 0.3 n = 10000 delay = 1 if discrete: d = np.zeros((3, n - 2*delay, n_replications), dtype=int) else: d = np.zeros((3, n - 2*delay, n_replications)) for r in range(n_replications): proc_1 = np.random.normal(0, 1, size=n) proc_2 = (covariance_1 * proc_1 + (1 - covariance_1) * np.random.normal(0, 1, size=n)) proc_3 = (covariance_2 * proc_2 + (1 - covariance_2) * np.random.normal(0, 1, size=n)) proc_1 = proc_1[(2*delay):] proc_2 = proc_2[delay:-delay] proc_3 = proc_3[:-(2*delay)] if discrete: # discretise data proc_1_dis, proc_2_dis = est._discretise_vars( var1=proc_1, var2=proc_2) proc_1_dis, proc_3_dis = est._discretise_vars( var1=proc_1, var2=proc_3) d[0, :, r] = proc_1_dis d[1, :, r] = proc_2_dis d[2, :, r] = proc_3_dis else: d[0, :, r] = proc_1 d[1, :, r] = proc_2 d[2, :, r] = proc_3 return d
def generate_gauss_data(n_replications=1, discrete=False): settings = {'discretise_method': 'equal', 'n_discrete_bins': 5} est = JidtDiscreteCMI(settings) covariance_1 = 0.4 covariance_2 = 0.3 n = 10000 delay = 1 if discrete: d = np.zeros((3, n - 2 * delay, n_replications), dtype=int) else: d = np.zeros((3, n - 2 * delay, n_replications)) for r in range(n_replications): proc_1 = np.random.normal(0, 1, size=n) proc_2 = (covariance_1 * proc_1 + (1 - covariance_1) * np.random.normal(0, 1, size=n)) proc_3 = (covariance_2 * proc_2 + (1 - covariance_2) * np.random.normal(0, 1, size=n)) proc_1 = proc_1[(2 * delay):] proc_2 = proc_2[delay:-delay] proc_3 = proc_3[:-(2 * delay)] if discrete: # discretise data proc_1_dis, proc_2_dis = est._discretise_vars(var1=proc_1, var2=proc_2) proc_1_dis, proc_3_dis = est._discretise_vars(var1=proc_1, var2=proc_3) d[0, :, r] = proc_1_dis d[1, :, r] = proc_2_dis d[2, :, r] = proc_3_dis else: d[0, :, r] = proc_1 d[1, :, r] = proc_2 d[2, :, r] = proc_3 return d
def test_analytical_surrogates(): # Generate discrete test data. covariance = 0.4 n = 10000 delay = 1 source = np.random.normal(0, 1, size=n) target = (covariance * source + (1 - covariance) * np.random.normal(0, 1, size=n)) source = source[delay:] target = target[:-delay] settings = {'discretise_method': 'equal', 'n_discrete_bins': 5} est = JidtDiscreteCMI(settings) source_dis, target_dis = est._discretise_vars(var1=source, var2=target) data = Data(np.vstack((source_dis, target_dis)), dim_order='ps', normalise=False) settings = { 'cmi_estimator': 'JidtDiscreteCMI', 'n_discrete_bins': 5, # alphabet size of the variables analysed 'n_perm_max_stat': 100, 'n_perm_min_stat': 21, 'n_perm_omnibus': 21, 'n_perm_max_seq': 21, 'max_lag_sources': 5, 'min_lag_sources': 1, 'max_lag_target': 5 } nw = MultivariateTE() res = nw.analyse_single_target(settings, data, target=1) assert res.settings.analytical_surrogates, ( 'Surrogates were not created analytically.')
def test_analytical_surrogates(): # Test generation of analytical surrogates. # Generate data and discretise it such that we can use analytical # surrogates. expected_mi, source1, source2, target = _get_gauss_data(covariance=0.4) settings = {'discretise_method': 'equal', 'n_discrete_bins': 5} est = JidtDiscreteCMI(settings) source_dis, target_dis = est._discretise_vars(var1=source1, var2=target) data = Data(np.hstack((source_dis, target_dis)), dim_order='sp', normalise=False) settings = { 'cmi_estimator': 'JidtDiscreteCMI', 'n_discrete_bins': 5, # alphabet size of the variables analysed 'n_perm_max_stat': 100, 'n_perm_min_stat': 21, 'n_perm_omnibus': 21, 'n_perm_max_seq': 21, 'max_lag_sources': 5, 'min_lag_sources': 1, 'max_lag_target': 5 } nw = MultivariateTE() res = nw.analyse_single_target(settings, data, target=1) # Check if generation of analytical surrogates is documented in the # settings. assert res.settings.analytical_surrogates, ( 'Surrogates were not created analytically.')
def test_discrete_input(): """Test AIS estimation from discrete data.""" # Generate AR data order = 1 n = 10000 - order self_coupling = 0.5 process = np.zeros(n + order) process[0:order] = np.random.normal(size=(order)) for n in range(order, n + order): process[n] = self_coupling * process[n - 1] + np.random.normal() # Discretise data settings = {'discretise_method': 'equal', 'n_discrete_bins': 5} est = JidtDiscreteCMI(settings) process_dis, temp = est._discretise_vars(var1=process, var2=process) data = Data(process_dis, dim_order='s', normalise=False) settings = { 'cmi_estimator': 'JidtDiscreteCMI', 'discretise_method': 'none', 'n_discrete_bins': 5, # alphabet size of the variables 'n_perm_max_stat': 21, 'n_perm_min_stat': 21, 'n_perm_mi': 21, 'max_lag': 2 } nw = ActiveInformationStorage() nw.analyse_single_process(settings=settings, data=data, process=0)
def test_discrete_input(): """Test AIS estimation from discrete data.""" # Generate AR data order = 1 n = 10000 - order self_coupling = 0.5 process = np.zeros(n + order) process[0:order] = np.random.normal(size=(order)) for n in range(order, n + order): process[n] = self_coupling * process[n - 1] + np.random.normal() # Discretise data settings = {'discretise_method': 'equal', 'n_discrete_bins': 5} est = JidtDiscreteCMI(settings) process_dis, temp = est._discretise_vars(var1=process, var2=process) data = Data(process_dis, dim_order='s', normalise=False) settings = { 'cmi_estimator': 'JidtDiscreteCMI', 'discretise_method': 'none', 'n_discrete_bins': 5, # alphabet size of the variables 'n_perm_max_stat': 21, 'n_perm_min_stat': 21, 'n_perm_mi': 21, 'max_lag': 2} nw = ActiveInformationStorage() nw.analyse_single_process(settings=settings, data=data, process=0)
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 _generate_gauss_data(covariance=0.4, n=10000, delay=1, normalise=False): # Generate two coupled Gaussian time series source = np.random.normal(0, 1, size=n) target = (covariance * source + (1 - covariance) * np.random.normal(0, 1, size=n)) source = source[delay:] target = target[:-delay] # Discretise data for speed settings = {'discretise_method': 'equal', 'n_discrete_bins': 5} est = JidtDiscreteCMI(settings) source_dis, target_dis = est._discretise_vars(var1=source, var2=target) return Data(np.vstack((source_dis, target_dis)), dim_order='ps', normalise=normalise)
def _generate_gauss_data(covariance=0.4, n=10000, delay=1, normalise=False): # Generate two coupled Gaussian time series source = np.random.normal(0, 1, size=n) target = (covariance * source + (1 - covariance) * np.random.normal(0, 1, size=n)) source = source[delay:] target = target[:-delay] # Discretise data for speed settings = {'discretise_method': 'equal', 'n_discrete_bins': 5} est = JidtDiscreteCMI(settings) source_dis, target_dis = est._discretise_vars(var1=source, var2=target) return Data(np.vstack((source_dis, target_dis)), dim_order='ps', normalise=normalise)
def test_discrete_input(): """Test bivariate TE estimation from discrete data.""" # Generate Gaussian test data covariance = 0.4 n = 10000 delay = 1 source = np.random.normal(0, 1, size=n) target = (covariance * source + (1 - covariance) * np.random.normal(0, 1, size=n)) corr_expected = covariance / (1 * np.sqrt(covariance**2 + (1 - covariance)**2)) expected_mi = calculate_mi(corr_expected) source = source[delay:] target = target[:-delay] # Discretise data settings = {'discretise_method': 'equal', 'n_discrete_bins': 5} est = JidtDiscreteCMI(settings) source_dis, target_dis = est._discretise_vars(var1=source, var2=target) data = Data(np.vstack((source_dis, target_dis)), dim_order='ps', normalise=False) 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 } nw = BivariateTE() res = nw.analyse_single_target(settings=settings, data=data, target=1) assert np.isclose( res._single_target[1].omnibus_te, expected_mi, atol=0.05), ( 'Estimated TE for discrete variables is not correct. Expected: ' '{0}, Actual results: {1}.'.format( expected_mi, res._single_target[1].omnibus_te))
def test_discrete_input(): """Test bivariate TE estimation from discrete data.""" # Generate Gaussian test data covariance = 0.4 n = 10000 delay = 1 source = np.random.normal(0, 1, size=n) target = (covariance * source + (1 - covariance) * np.random.normal(0, 1, size=n)) corr_expected = covariance / ( 1 * np.sqrt(covariance**2 + (1-covariance)**2)) expected_mi = calculate_mi(corr_expected) source = source[delay:] target = target[:-delay] # Discretise data settings = {'discretise_method': 'equal', 'n_discrete_bins': 5} est = JidtDiscreteCMI(settings) source_dis, target_dis = est._discretise_vars(var1=source, var2=target) data = Data(np.vstack((source_dis, target_dis)), dim_order='ps', normalise=False) 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} nw = BivariateTE() res = nw.analyse_single_target(settings=settings, data=data, target=1) assert np.isclose( res._single_target[1].omnibus_te, expected_mi, atol=0.05), ( 'Estimated TE for discrete variables is not correct. Expected: ' '{0}, Actual results: {1}.'.format( expected_mi, res._single_target[1].omnibus_te))
def test_results_network_inference(): """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)) corr_expected = covariance / ( 1 * np.sqrt(covariance**2 + (1-covariance)**2)) expected_mi = calculate_mi(corr_expected) 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) nw = MultivariateTE() # TE - single target res_single_multi_te = nw.analyse_single_target( settings=settings, data=data, target=1) # TE whole network res_network_multi_te = nw.analyse_network(settings=settings, data=data) nw = BivariateTE() # TE - single target res_single_biv_te = nw.analyse_single_target( settings=settings, data=data, target=1) # TE whole network res_network_biv_te = nw.analyse_network(settings=settings, data=data) nw = MultivariateMI() # TE - single target res_single_multi_mi = nw.analyse_single_target( settings=settings, data=data, target=1) # TE whole network res_network_multi_mi = nw.analyse_network(settings=settings, data=data) nw = BivariateMI() # TE - single target res_single_biv_mi = nw.analyse_single_target( settings=settings, data=data, target=1) # TE whole network res_network_biv_mi = nw.analyse_network(settings=settings, data=data) res_te = [res_single_multi_te, res_network_multi_te, res_single_biv_te, res_network_biv_te] res_mi = [res_single_multi_mi, res_network_multi_mi, res_single_biv_mi, res_network_biv_mi] res_all = res_te + res_mi # Check estimated values for res in res_te: est_te = res._single_target[1].omnibus_te assert np.isclose(est_te, expected_mi, atol=0.05), ( 'Estimated TE for discrete variables is not correct. Expected: ' '{0}, Actual results: {1}.'.format(expected_mi, est_te)) for res in res_mi: est_mi = res._single_target[1].omnibus_mi assert np.isclose(est_mi, expected_mi, atol=0.05), ( 'Estimated TE for discrete variables is not correct. Expected: ' '{0}, Actual results: {1}.'.format(expected_mi, est_mi)) est_te = res_network_multi_te._single_target[2].omnibus_te assert np.isclose(est_te, expected_mi, atol=0.05), ( 'Estimated TE for discrete variables is not correct. Expected: {0}, ' 'Actual results: {1}.'.format(expected_mi, est_te)) est_mi = res_network_multi_mi._single_target[2].omnibus_mi assert np.isclose(est_mi, expected_mi, atol=0.05), ( 'Estimated TE for discrete variables is not correct. Expected: {0}, ' 'Actual results: {1}.'.format(expected_mi, est_mi)) # Check data parameters in results objects n_nodes = 3 n_realisations = n - delay - max( settings['max_lag_sources'], settings['max_lag_target']) for res in res_all: assert res.data_properties.n_nodes == n_nodes, 'Incorrect no. nodes.' assert res.data_properties.n_nodes == n_nodes, 'Incorrect no. nodes.' assert res.data_properties.n_realisations == n_realisations, ( 'Incorrect no. realisations.') assert res.data_properties.n_realisations == n_realisations, ( 'Incorrect no. realisations.') assert res.data_properties.normalised == normalisation, ( 'Incorrect value for data normalisation.') assert res.data_properties.normalised == normalisation, ( 'Incorrect value for data normalisation.') adj_matrix = res.get_adjacency_matrix('binary', fdr=False) assert adj_matrix.shape[0] == n_nodes, ( 'Incorrect number of rows in adjacency matrix.') assert adj_matrix.shape[1] == n_nodes, ( 'Incorrect number of columns in adjacency matrix.') assert adj_matrix.shape[0] == n_nodes, ( 'Incorrect number of rows in adjacency matrix.') assert adj_matrix.shape[1] == n_nodes, ( 'Incorrect number of columns in adjacency matrix.')
def test_delay_reconstruction(): """Test the reconstruction of information transfer delays from results.""" covariance = 0.4 corr_expected = covariance / ( 1 * np.sqrt(covariance**2 + (1-covariance)**2)) expected_mi = calculate_mi(corr_expected) n = 10000 delay_1 = 1 delay_2 = 3 delay_3 = 5 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)) target_3 = (covariance * source + (1 - covariance) * np.random.normal(0, 1, size=n)) source = source[delay_3:] target_1 = target_1[(delay_3-delay_1):-delay_1] target_2 = target_2[(delay_3-delay_2):-delay_2] target_3 = target_3[:-delay_3] # 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) source_dis, target_3_dis = est._discretise_vars(var1=source, var2=target_3) data = Data( np.vstack((source_dis, target_1_dis, target_2_dis, target_3_dis)), dim_order='ps', normalise=normalisation) nw = MultivariateTE() 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': delay_3 + 1, 'max_lag_target': 1} res_network = nw.analyse_single_target( settings=settings, data=data, target=1) res_network.combine_results(nw.analyse_single_target( settings=settings, data=data, target=2)) res_network.combine_results(nw.analyse_single_target( settings=settings, data=data, target=3)) adj_mat = res_network.get_adjacency_matrix('max_te_lag', fdr=False) print(adj_mat) assert adj_mat[0, 1] == delay_1, ('Estimate for delay 1 is not correct.') assert adj_mat[0, 2] == delay_2, ('Estimate for delay 2 is not correct.') assert adj_mat[0, 3] == delay_3, ('Estimate for delay 3 is not correct.') for target in range(1, 4): est_mi = res_network._single_target[target].omnibus_te assert np.isclose(est_mi, expected_mi, atol=0.05), ( 'Estimated TE for target {0} is not correct. Expected: {1}, ' 'Actual results: {2}.'.format(target, expected_mi, est_mi))
def test_results_network_inference(): """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)) corr_expected = covariance / (1 * np.sqrt(covariance**2 + (1 - covariance)**2)) expected_mi = calculate_mi(corr_expected) 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) nw = MultivariateTE() # TE - single target res_single_multi_te = nw.analyse_single_target(settings=settings, data=data, target=1) # TE whole network res_network_multi_te = nw.analyse_network(settings=settings, data=data) nw = BivariateTE() # TE - single target res_single_biv_te = nw.analyse_single_target(settings=settings, data=data, target=1) # TE whole network res_network_biv_te = nw.analyse_network(settings=settings, data=data) nw = MultivariateMI() # TE - single target res_single_multi_mi = nw.analyse_single_target(settings=settings, data=data, target=1) # TE whole network res_network_multi_mi = nw.analyse_network(settings=settings, data=data) nw = BivariateMI() # TE - single target res_single_biv_mi = nw.analyse_single_target(settings=settings, data=data, target=1) # TE whole network res_network_biv_mi = nw.analyse_network(settings=settings, data=data) res_te = [ res_single_multi_te, res_network_multi_te, res_single_biv_te, res_network_biv_te ] res_mi = [ res_single_multi_mi, res_network_multi_mi, res_single_biv_mi, res_network_biv_mi ] res_all = res_te + res_mi # Check estimated values for res in res_te: est_te = res._single_target[1].omnibus_te assert np.isclose(est_te, expected_mi, atol=0.05), ( 'Estimated TE for discrete variables is not correct. Expected: ' '{0}, Actual results: {1}.'.format(expected_mi, est_te)) for res in res_mi: est_mi = res._single_target[1].omnibus_mi assert np.isclose(est_mi, expected_mi, atol=0.05), ( 'Estimated TE for discrete variables is not correct. Expected: ' '{0}, Actual results: {1}.'.format(expected_mi, est_mi)) est_te = res_network_multi_te._single_target[2].omnibus_te assert np.isclose(est_te, expected_mi, atol=0.05), ( 'Estimated TE for discrete variables is not correct. Expected: {0}, ' 'Actual results: {1}.'.format(expected_mi, est_te)) est_mi = res_network_multi_mi._single_target[2].omnibus_mi assert np.isclose(est_mi, expected_mi, atol=0.05), ( 'Estimated TE for discrete variables is not correct. Expected: {0}, ' 'Actual results: {1}.'.format(expected_mi, est_mi)) # Check data parameters in results objects n_nodes = 3 n_realisations = n - delay - max(settings['max_lag_sources'], settings['max_lag_target']) for res in res_all: assert res.data_properties.n_nodes == n_nodes, 'Incorrect no. nodes.' assert res.data_properties.n_nodes == n_nodes, 'Incorrect no. nodes.' assert res.data_properties.n_realisations == n_realisations, ( 'Incorrect no. realisations.') assert res.data_properties.n_realisations == n_realisations, ( 'Incorrect no. realisations.') assert res.data_properties.normalised == normalisation, ( 'Incorrect value for data normalisation.') assert res.data_properties.normalised == normalisation, ( 'Incorrect value for data normalisation.') adj_matrix = res.get_adjacency_matrix('binary', fdr=False) assert adj_matrix._edge_matrix.shape[0] == n_nodes, ( 'Incorrect number of rows in adjacency matrix.') assert adj_matrix._edge_matrix.shape[1] == n_nodes, ( 'Incorrect number of columns in adjacency matrix.') assert adj_matrix._edge_matrix.shape[0] == n_nodes, ( 'Incorrect number of rows in adjacency matrix.') assert adj_matrix._edge_matrix.shape[1] == n_nodes, ( 'Incorrect number of columns in adjacency matrix.')
def test_delay_reconstruction(): """Test the reconstruction of information transfer delays from results.""" covariance = 0.4 corr_expected = covariance / (1 * np.sqrt(covariance**2 + (1 - covariance)**2)) expected_mi = calculate_mi(corr_expected) n = 10000 delay_1 = 1 delay_2 = 3 delay_3 = 5 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)) target_3 = (covariance * source + (1 - covariance) * np.random.normal(0, 1, size=n)) source = source[delay_3:] target_1 = target_1[(delay_3 - delay_1):-delay_1] target_2 = target_2[(delay_3 - delay_2):-delay_2] target_3 = target_3[:-delay_3] # 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) source_dis, target_3_dis = est._discretise_vars(var1=source, var2=target_3) data = Data(np.vstack( (source_dis, target_1_dis, target_2_dis, target_3_dis)), dim_order='ps', normalise=normalisation) nw = MultivariateTE() 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': delay_3 + 1, 'max_lag_target': 1 } res_network = nw.analyse_single_target(settings=settings, data=data, target=1) res_network.combine_results( nw.analyse_single_target(settings=settings, data=data, target=2)) res_network.combine_results( nw.analyse_single_target(settings=settings, data=data, target=3)) adj_mat = res_network.get_adjacency_matrix('max_te_lag', fdr=False) adj_mat.print_matrix() assert adj_mat._weight_matrix[0, 1] == delay_1, ( 'Estimate for delay 1 is not correct.') assert adj_mat._weight_matrix[0, 2] == delay_2, ( 'Estimate for delay 2 is not correct.') assert adj_mat._weight_matrix[0, 3] == delay_3, ( 'Estimate for delay 3 is not correct.') for target in range(1, 4): est_mi = res_network._single_target[target].omnibus_te assert np.isclose(est_mi, expected_mi, atol=0.05), ( 'Estimated TE for target {0} is not correct. Expected: {1}, ' 'Actual results: {2}.'.format(target, expected_mi, est_mi))