本文整理汇总了Python中idtxl.data.Data.generate_mute_data方法的典型用法代码示例。如果您正苦于以下问题:Python Data.generate_mute_data方法的具体用法?Python Data.generate_mute_data怎么用?Python Data.generate_mute_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类idtxl.data.Data
的用法示例。
在下文中一共展示了Data.generate_mute_data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_data
# 需要导入模块: from idtxl.data import Data [as 别名]
# 或者: from idtxl.data.Data import generate_mute_data [as 别名]
def test_get_data():
"""Test low-level function for data retrieval."""
dat = Data()
dat.generate_mute_data()
idx_list = [(0, 4), (0, 6)]
current_value = (0, 3)
with pytest.raises(RuntimeError):
dat._get_data(idx_list, current_value)
# Test retrieved data for one/two replications in time (i.e., the current
# value is equal to the last sample)
n = 7
d = Data(np.arange(n + 1), 's', normalise=False)
current_value = (0, n)
dat = d._get_data([(0, 1)], current_value)[0]
assert (dat[0][0] == 1)
assert (dat.shape == (1, 1))
d = Data(np.arange(n + 2), 's', normalise=False)
current_value = (0, n)
dat = d._get_data([(0, 1)], current_value)[0]
assert (dat[0][0] == 1)
assert (dat[1][0] == 2)
assert (dat.shape == (2, 1))
# Test retrieval of realisations of the current value.
n = 7
d = Data(np.arange(n), 's', normalise=False)
current_value = (0, n)
dat = d._get_data([current_value], current_value)[0]
示例2: test_add_conditional_manually
# 需要导入模块: from idtxl.data import Data [as 别名]
# 或者: from idtxl.data.Data import generate_mute_data [as 别名]
def test_add_conditional_manually():
"""Enforce the conditioning on additional variables."""
settings = {'cmi_estimator': 'JidtKraskovCMI',
'max_lag': 5,
'n_perm_max_stat': 21,
'n_perm_min_stat': 21,
'n_perm_mi': 21}
data = Data()
data.generate_mute_data(10, 3)
ais = ActiveInformationStorage()
# Add a conditional with a lag bigger than the max_lag requested above
settings['add_conditionals'] = (8, 0)
with pytest.raises(IndexError):
ais.analyse_single_process(settings=settings, data=data, process=0)
# Add valid conditionals and test if they were added
settings['add_conditionals'] = [(0, 1), (1, 3)]
ais._initialise(settings, data, 0)
# Get list of conditionals after intialisation and convert absolute samples
# back to lags for comparison.
cond_list = ais._idx_to_lag(ais.selected_vars_full)
assert settings['add_conditionals'][0] in cond_list, (
'First enforced conditional is missing from results.')
assert settings['add_conditionals'][1] in cond_list, (
'Second enforced conditional is missing from results.')
示例3: test_ActiveInformationStorage_init
# 需要导入模块: from idtxl.data import Data [as 别名]
# 或者: from idtxl.data.Data import generate_mute_data [as 别名]
def test_ActiveInformationStorage_init():
"""Test instance creation for ActiveInformationStorage class."""
# Test error on missing estimator
settings = {'max_lag': 5}
data = Data()
data.generate_mute_data(10, 3)
ais = ActiveInformationStorage()
with pytest.raises(RuntimeError):
ais.analyse_single_process(settings, data, process=0)
# Test tau larger than maximum lag
settings['cmi_estimator'] = 'JidtKraskovCMI'
settings['tau'] = 10
with pytest.raises(RuntimeError):
ais.analyse_single_process(settings, data, process=0)
# Test negative tau and maximum lag
settings['tau'] = -10
with pytest.raises(RuntimeError):
ais.analyse_single_process(settings, data, process=0)
settings['tau'] = 1
settings['max_lag'] = -5
with pytest.raises(RuntimeError):
ais.analyse_single_process(settings, data, process=0)
# Invalid: process is not an int
settings['max_lag'] = 5
with pytest.raises(RuntimeError): # no int
ais.analyse_single_process(settings, data, process=1.5)
with pytest.raises(RuntimeError): # negative
ais.analyse_single_process(settings, data, process=-1)
with pytest.raises(RuntimeError): # not in data
ais.analyse_single_process(settings, data, process=10)
with pytest.raises(RuntimeError): # wrong type
ais.analyse_single_process(settings, data, process={})
示例4: test_return_local_values
# 需要导入模块: from idtxl.data import Data [as 别名]
# 或者: from idtxl.data.Data import generate_mute_data [as 别名]
def test_return_local_values():
"""Test estimation of local values."""
max_lag = 5
settings = {
'cmi_estimator': 'JidtKraskovCMI',
'local_values': True, # request calculation of local values
'n_perm_max_stat': 21,
'n_perm_min_stat': 21,
'n_perm_mi': 21,
'max_lag': max_lag,
'tau': 1}
data = Data()
data.generate_mute_data(100, 3)
ais = ActiveInformationStorage()
processes = [1, 2]
results = ais.analyse_network(settings, data, processes)
for p in processes:
lais = results.get_single_process(p, fdr=False)['ais']
if lais is np.nan:
continue
assert type(lais) is np.ndarray, (
'LAIS estimation did not return an array of values: {0}'.format(
lais))
assert lais.shape[0] == data.n_replications, (
'Wrong dim (no. replications) in LAIS estimate: {0}'.format(
lais.shape))
assert lais.shape[1] == data.n_realisations_samples((0, max_lag)), (
'Wrong dim (no. samples) in LAIS estimate: {0}'.format(lais.shape))
示例5: test_max_statistic_sequential
# 需要导入模块: from idtxl.data import Data [as 别名]
# 或者: from idtxl.data.Data import generate_mute_data [as 别名]
def test_max_statistic_sequential():
data = Data()
data.generate_mute_data(104, 10)
settings = {
'cmi_estimator': 'JidtKraskovCMI',
'n_perm_max_stat': 21,
'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
}
setup = MultivariateTE()
setup._initialise(settings, data, sources=[0, 1], target=2)
setup.current_value = (0, 4)
setup.selected_vars_sources = [(1, 1), (1, 2)]
setup.selected_vars_full = [(0, 1), (1, 1), (1, 2)]
setup._selected_vars_realisations = np.random.rand(
data.n_realisations(setup.current_value),
len(setup.selected_vars_full))
setup._current_value_realisations = np.random.rand(
data.n_realisations(setup.current_value),
1)
[sign, p, te] = stats.max_statistic_sequential(analysis_setup=setup,
data=data)
示例6: test_swap_blocks
# 需要导入模块: from idtxl.data import Data [as 别名]
# 或者: from idtxl.data.Data import generate_mute_data [as 别名]
def test_swap_blocks():
"""Test block-wise swapping of samples."""
d = Data()
d.generate_mute_data()
# block_size divides the length of the data to be permuted, swap_range
# leads to 2 remaining blocks
n = 50
block_size = 5
swap_range = 4
perm = d._swap_blocks(n, block_size, swap_range)
assert perm.shape[0] == n, 'Incorrect length of permuted indices.'
# block_size leads to one block of length 1, swap_range divides the no.
# blocks
n = 50
block_size = 7
swap_range = 4
perm = d._swap_blocks(n, block_size, swap_range)
assert perm.shape[0] == n, 'Incorrect length of permuted indices.'
n_blocks = np.ceil(n/7).astype(int)
assert n_blocks == 8, 'No. blocks is incorrect.'
assert sum(perm == n_blocks - 1) == 1, ('No. remaining samples in the last'
' block is incorrect.')
# no remaining samples or blocks
n = 30
block_size = 5
swap_range = 3
perm = d._swap_blocks(n, block_size, swap_range)
assert perm.shape[0] == n, 'Incorrect length of permuted indices.'
示例7: test_visualise_multivariate_te
# 需要导入模块: from idtxl.data import Data [as 别名]
# 或者: from idtxl.data.Data import generate_mute_data [as 别名]
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()
示例8: test_check_source_set
# 需要导入模块: from idtxl.data import Data [as 别名]
# 或者: from idtxl.data.Data import generate_mute_data [as 别名]
def test_check_source_set():
"""Test the method _check_source_set.
This method sets the list of source processes from which candidates are
taken for multivariate TE estimation.
"""
dat = Data()
dat.generate_mute_data(100, 5)
max_lag_sources = 7
min_lag_sources = 5
max_lag_target = 5
analysis_opts = {'cmi_calc_name': 'jidt_kraskov'}
nw_0 = Multivariate_te(max_lag_sources, min_lag_sources, max_lag_target,
analysis_opts)
sources = [1, 2, 3]
nw_0._check_source_set(sources, dat.n_processes)
# Assert that initialisation fails if the target is also in the source list
sources = [0, 1, 2, 3]
nw_0 = Multivariate_te(max_lag_sources, min_lag_sources, max_lag_target,
analysis_opts)
nw_0.target = 0
with pytest.raises(RuntimeError):
nw_0._check_source_set(sources, dat.n_processes)
sources = 1
nw_0 = Multivariate_te(max_lag_sources, min_lag_sources, max_lag_target,
analysis_opts)
nw_0._check_source_set(sources, dat.n_processes)
assert (type(nw_0.source_set) is list)
示例9: test_multivariate_te_init
# 需要导入模块: from idtxl.data import Data [as 别名]
# 或者: from idtxl.data.Data import generate_mute_data [as 别名]
def test_multivariate_te_init():
analysis_opts = {'cmi_calc_name': 'jidt_kraskov'}
max_lag_target = 5
max_lag_sources = 7
min_lag_sources = 4
target = 0
sources = [2, 3, 4]
dat = Data()
dat.generate_mute_data(100, 5)
nw_0 = Multivariate_te(max_lag_sources, min_lag_sources, max_lag_target,
analysis_opts)
nw_0.analyse_single_target(dat, target, sources)
# This should just run: Test what happens if the target max lag is bigger
# than the source max lag
max_lag_sources = 5
max_lag_target = 7
nw_1 = Multivariate_te(max_lag_sources, min_lag_sources, max_lag_target,
analysis_opts)
nw_1.analyse_single_target(dat, target, sources)
# The following should crash: min lag bigger than max lag
max_lag_sources = 5
min_lag_sources = 7
nw_2 = Multivariate_te(max_lag_sources, min_lag_sources, max_lag_target,
analysis_opts)
with pytest.raises(AssertionError):
nw_2.analyse_single_target(dat, target, sources)
示例10: test_multivariate_te_mute
# 需要导入模块: from idtxl.data import Data [as 别名]
# 或者: from idtxl.data.Data import generate_mute_data [as 别名]
def test_multivariate_te_mute():
"""Test multivariate TE estimation on the MUTE example network.
Test data comes from a network that is used as an example in the paper on
the MuTE toolbox (Montalto, PLOS ONE, 2014, eq. 14). The network has the
following (non-linear) couplings:
0 -> 1, u = 2
0 -> 2, u = 3
0 -> 3, u = 2 (non-linear)
3 -> 4, u = 1
4 -> 3, u = 1
The maximum order of any single AR process is never higher than 2.
"""
data = Data()
data.generate_mute_data(n_samples=1000, n_replications=10)
settings = {
'cmi_estimator': 'JidtKraskovCMI',
'max_lag_sources': 3,
'min_lag_sources': 1,
'max_lag_target': 3,
'n_perm_max_stat': 21,
'n_perm_min_stat': 21,
'n_perm_omnibus': 21,
'n_perm_max_seq': 21} # this should be equal to the min stats b/c we
# reuse the surrogate table from the min stats
network_analysis = MultivariateTE()
network_analysis.analyse_network(settings, data, targets=[1, 2])
示例11: test_add_conditional_manually
# 需要导入模块: from idtxl.data import Data [as 别名]
# 或者: from idtxl.data.Data import generate_mute_data [as 别名]
def test_add_conditional_manually():
"""Enforce the conditioning on additional variables."""
settings = {'cmi_estimator': 'JidtKraskovCMI',
'max_lag_sources': 5,
'min_lag_sources': 3,
'max_lag_target': 7}
nw = BivariateTE()
data = Data()
data.generate_mute_data()
# Add a conditional with a lag bigger than the max_lag requested above
settings['add_conditionals'] = (8, 0)
with pytest.raises(IndexError):
nw.analyse_single_target(settings=settings, data=data, target=0)
# Add valid conditionals and test if they were added
settings['add_conditionals'] = [(0, 1), (1, 3)]
nw._initialise(settings=settings, data=data, target=0, sources=[1, 2])
# Get list of conditionals after intialisation and convert absolute samples
# back to lags for comparison.
cond_list = nw._idx_to_lag(nw.selected_vars_full)
assert settings['add_conditionals'][0] in cond_list, (
'First enforced conditional is missing from results.')
assert settings['add_conditionals'][1] in cond_list, (
'Second enforced conditional is missing from results.')
示例12: test_multivariate_te_mute
# 需要导入模块: from idtxl.data import Data [as 别名]
# 或者: from idtxl.data.Data import generate_mute_data [as 别名]
def test_multivariate_te_mute():
"""Test multivariate TE estimation on the MUTE example network.
Test data comes from a network that is used as an example in the paper on
the MuTE toolbox (Montalto, PLOS ONE, 2014, eq. 14). The network has the
following (non-linear) couplings:
0 -> 1, u = 2
0 -> 2, u = 3
0 -> 3, u = 2 (non-linear)
3 -> 4, u = 1
4 -> 3, u = 1
The maximum order of any single AR process is never higher than 2.
"""
dat = Data()
dat.generate_mute_data(n_samples=1000, n_replications=10)
analysis_opts = {
'cmi_calc_name': 'jidt_kraskov',
'n_perm_max_stat': 21,
'n_perm_min_stat': 21,
'n_perm_omnibus': 21,
'n_perm_max_seq': 21, # this should be equal to the min stats b/c we
# reuse the surrogate table from the min stats
}
network_analysis = Multivariate_te(max_lag_sources=3, min_lag_sources=1,
max_lag_target=3, options=analysis_opts)
res = network_analysis.analyse_network(dat, targets=[1, 2])
示例13: test_compare_jidt_open_cl_estimator
# 需要导入模块: from idtxl.data import Data [as 别名]
# 或者: from idtxl.data.Data import generate_mute_data [as 别名]
def test_compare_jidt_open_cl_estimator():
"""Compare results from OpenCl and JIDT estimators for AIS calculation."""
dat = Data()
dat.generate_mute_data(100, 2)
max_lag = 5
analysis_opts = {
'cmi_calc_name': 'opencl_kraskov',
'n_perm_mi': 22,
'alpha_mi': 0.05,
'tail_mi': 'one',
}
processes = [2, 3]
network_analysis = Single_process_storage(max_lag, analysis_opts, tau=1)
res_opencl = network_analysis.analyse_network(dat, processes)
analysis_opts['cmi_calc_name'] = 'jidt_kraskov'
network_analysis = Single_process_storage(max_lag, analysis_opts, tau=1)
res_jidt = network_analysis.analyse_network(dat, processes)
# Note that I require equality up to three digits. Results become more exact for bigger
# data sizes, but this takes too long for a unit test.
np.testing.assert_approx_equal(res_opencl[2]['ais'], res_jidt[2]['ais'], significant=3,
err_msg='AIS results differ between OpenCl and JIDT estimator.')
np.testing.assert_approx_equal(res_opencl[3]['ais'], res_jidt[3]['ais'], significant=3,
err_msg='AIS results differ between OpenCl and JIDT estimator.')
print('AIS for MUTE data proc 2 - opencl: {0} and jidt: {1}'.format(res_opencl[2]['ais'], res_jidt[2]['ais']))
print('AIS for MUTE data proc 3 - opencl: {0} and jidt: {1}'.format(res_opencl[3]['ais'], res_jidt[3]['ais']))
示例14: test_calculate_mean
# 需要导入模块: from idtxl.data import Data [as 别名]
# 或者: from idtxl.data.Data import generate_mute_data [as 别名]
def test_calculate_mean():
"""Test if mean over CMI estimates is calculated correctly."""
data = Data()
data.generate_mute_data(100, 5)
res_0 = np.load(os.path.join(os.path.dirname(__file__),
'data/mute_results_0.p'))
comp_settings = {
'cmi_estimator': 'JidtKraskovCMI',
'n_perm_max_stat': 50,
'n_perm_min_stat': 50,
'n_perm_omnibus': 200,
'n_perm_max_seq': 50,
'tail': 'two',
'n_perm_comp': 6,
'alpha_comp': 0.2,
'stats_type': 'dependent'
}
comp = NetworkComparison()
comp._initialise(comp_settings)
comp._create_union(res_0)
cmi = comp._calculate_cmi_all_links(data)
cmi_mean = comp._calculate_mean([cmi, cmi])
for t in comp.union.targets_analysed:
assert (cmi_mean[t] == cmi[t]).all(), ('Error in mean of CMI for '
'target {0}'.format(t))
示例15: test_ais_fdr
# 需要导入模块: from idtxl.data import Data [as 别名]
# 或者: from idtxl.data.Data import generate_mute_data [as 别名]
def test_ais_fdr():
settings = {'n_perm_max_seq': 1000, 'n_perm_mi': 1000}
process_0 = {
'selected_vars': [(0, 1), (0, 2), (0, 3)],
'ais_pval': 0.0001,
'ais_sign': True}
process_1 = {
'selected_vars': [(1, 0), (1, 1), (1, 2)],
'ais_pval': 0.031,
'ais_sign': True}
process_2 = {
'selected_vars': [],
'ais_pval': 0.41,
'ais_sign': False}
res_1 = ResultsSingleProcessAnalysis(
n_nodes=3, n_realisations=1000, normalised=True)
res_1._add_single_result(process=0, settings=settings, results=process_0)
res_1._add_single_result(process=1, settings=settings, results=process_1)
res_2 = ResultsSingleProcessAnalysis(
n_nodes=3, n_realisations=1000, normalised=True)
res_2._add_single_result(process=2, settings=settings, results=process_2)
settings = {
'cmi_estimator': 'JidtKraskovCMI',
'alpha_fdr': 0.05,
'max_lag': 3}
data = Data()
data.generate_mute_data(n_samples=100, n_replications=3)
analysis_setup = ActiveInformationStorage()
analysis_setup._initialise(settings=settings, data=data, process=1)
res_pruned = stats.ais_fdr(settings, res_1, res_2)
assert (not res_pruned._single_process[2].selected_vars_sources), (
'Process 2 has not been pruned from results.')
alpha_fdr = res_pruned.settings.alpha_fdr
for k in res_pruned.processes_analysed:
if not res_pruned._single_process[k]['ais_sign']:
assert (res_pruned._single_process[k]['ais_pval'] > alpha_fdr), (
'P-value of non-sign. AIS is not 1.')
assert (not res_pruned._single_process[k]['selected_vars']), (
'List of significant past variables is not empty')
else:
assert (res_pruned._single_process[k]['ais_pval'] < 1), (
'P-value of sign. AIS is not smaller 1.')
assert (res_pruned._single_process[k]['selected_vars']), (
'List of significant past variables is empty')
# Test function call for single result
res_pruned = stats.ais_fdr(settings, res_1)
print('successful call on single result dict.')
# Test None result for insufficient no. permutations, no FDR-corrected
# results (the results class throws an error if no FDR-corrected results
# exist).
res_1.settings['n_perm_mi'] = 2
res_2.settings['n_perm_mi'] = 2
res_pruned = stats.ais_fdr(settings, res_1, res_2)
with pytest.raises(RuntimeError):
res_pruned.get_significant_processes(fdr=True)