def test_multivariate_te_one_realisation_per_replication(): """Test boundary case of one realisation per replication.""" # Create a data set where one pattern fits into the time series exactly # once, this way, we get one realisation per replication for each variable. # This is easyer to assert/verify later. We also test data.get_realisations # this way. analysis_opts = {'cmi_calc_name': 'jidt_kraskov'} max_lag_target = 5 max_lag_sources = max_lag_target min_lag_sources = 4 target = 0 dat = Data(normalise=False) n_repl = 10 n_procs = 2 n_points = n_procs * (max_lag_sources + 1) * n_repl dat.set_data( np.arange(n_points).reshape(n_procs, max_lag_sources + 1, n_repl), 'psr') nw_0 = Multivariate_te(max_lag_sources, min_lag_sources, analysis_opts, max_lag_target) nw_0._initialise(dat, 'all', target) assert (not nw_0.selected_vars_full) assert (not nw_0.selected_vars_sources) assert (not nw_0.selected_vars_target) assert ((nw_0._replication_index == np.arange(n_repl)).all()) assert (nw_0._current_value == (target, max(max_lag_sources, max_lag_target))) assert (nw_0._current_value_realisations[:, 0] == dat.data[target, -1, :]).all()
def test_add_conditional_manually(): """Adda variable that is not in the data set.""" analysis_opts = { 'cmi_calc_name': 'jidt_kraskov', 'add_conditionals': (8, 0) } nw_1 = Multivariate_te(max_lag_sources=5, min_lag_sources=3, options=analysis_opts, max_lag_target=7) dat = Data() dat.generate_mute_data() sources = [1, 2, 3] target = 0 with pytest.raises(IndexError): nw_1._initialise(dat, sources, target)
def test_faes_method(): """Check if the Faes method is working.""" analysis_opts = { 'cmi_calc_name': 'jidt_kraskov', 'add_conditionals': 'faes' } nw_1 = Multivariate_te(max_lag_sources=5, min_lag_sources=3, max_lag_target=7, options=analysis_opts) dat = Data() dat.generate_mute_data() sources = [1, 2, 3] target = 0 nw_1._initialise(dat, sources, target) assert (nw_1._selected_vars_sources == [ i for i in it.product(sources, [nw_1.current_value[1]]) ]), ('Did not add correct additional conditioning vars.')
def test_multivariate_te_initialise(): """Test if all values are set correctly in _initialise().""" # Create a data set where one pattern fits into the time series exactly # once, this way, we get one realisation per replication for each variable. # This is easyer to assert/verify later. We also test data.get_realisations # this way. analysis_opts = {'cmi_calc_name': 'jidt_kraskov'} max_lag_target = 5 max_lag_sources = max_lag_target min_lag_sources = 4 target = 1 dat = Data(normalise=False) n_repl = 30 n_procs = 2 n_points = n_procs * (max_lag_sources + 1) * n_repl dat.set_data(np.arange(n_points).reshape(n_procs, max_lag_sources + 1, n_repl), 'psr') nw_0 = Multivariate_te(max_lag_sources, min_lag_sources, max_lag_target, analysis_opts) nw_0._initialise(dat, 'all', target) assert (not nw_0.selected_vars_full) assert (not nw_0.selected_vars_sources) assert (not nw_0.selected_vars_target) assert ((nw_0._replication_index == np.arange(n_repl)).all()) assert (nw_0._current_value == (target, max(max_lag_sources, max_lag_target))) assert ((nw_0._current_value_realisations == np.arange(n_points - n_repl, n_points).reshape(n_repl, 1)).all()) # Check if the Faes method is working analysis_opts['add_conditionals'] = 'faes' nw_1 = Multivariate_te(max_lag_sources, min_lag_sources, max_lag_target, analysis_opts) dat.generate_mute_data() sources = [1, 2, 3] target = [0] nw_1._initialise(dat, sources, target) assert (nw_1._selected_vars_sources == [i for i in it.product(sources, [nw_1.current_value[1]])]), ( 'Did not add correct additional conditioning vars.') # Adding a variable that is not in the data set. analysis_opts['add_conditionals'] = (8, 0) nw_1 = Multivariate_te(max_lag_sources, min_lag_sources, max_lag_target, analysis_opts) dat.generate_mute_data() sources = [1, 2, 3] target = [0] with pytest.raises(IndexError): nw_1._initialise(dat, sources, target)