Esempio n. 1
0
def test_analyse_network():
    """Test method for full network analysis."""
    n_processes = 5  # the MuTE network has 5 nodes
    dat = Data()
    dat.generate_mute_data(10, 5)
    nw_0 = Multivariate_te(max_lag_sources=5,
                           min_lag_sources=4,
                           options={'cmi_calc_name': 'jidt_kraskov'},
                           max_lag_target=5)

    # Test all to all analysis
    r = nw_0.analyse_network(dat, targets='all', sources='all')
    try:
        del r['fdr']
    except:
        pass
    k = list(r.keys())
    sources = np.arange(n_processes)
    assert all(np.array(k) == np.arange(n_processes)), (
        'Network analysis did not run on all targets.')
    for t in r.keys():
        s = np.array(list(set(sources) - set([t])))
        assert all(np.array(r[t]['sources_tested']) == s), (
            'Network analysis did not run on all sources for target '
            '{0}'.format(t))
    # Test analysis for subset of targets
    target_list = [1, 2, 3]
    r = nw_0.analyse_network(dat, targets=target_list, sources='all')
    try:
        del r['fdr']
    except:
        pass
    k = list(r.keys())
    assert all(np.array(k) == np.array(target_list)), (
        'Network analysis did not run on correct subset of targets.')
    for t in r.keys():
        s = np.array(list(set(sources) - set([t])))
        assert all(np.array(r[t]['sources_tested']) == s), (
            'Network analysis did not run on all sources for target '
            '{0}'.format(t))

    # Test analysis for subset of sources
    source_list = [1, 2, 3]
    target_list = [0, 4]
    r = nw_0.analyse_network(dat, targets=target_list, sources=source_list)
    try:
        del r['fdr']
    except:
        pass
    k = list(r.keys())
    assert all(np.array(k) == np.array(target_list)), (
        'Network analysis did not run for all targets.')
    for t in r.keys():
        assert all(r[t]['sources_tested'] == np.array(source_list)), (
            'Network analysis did not run on the correct subset of sources '
            'for target {0}'.format(t))
Esempio n. 2
0
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])
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])
Esempio n. 4
0
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_discrete',
        'discretise_method': 'max_ent',
        '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_me = network_analysis.analyse_network(dat, targets=[1, 2])
    analysis_opts = {'discretise_method': 'equal'}
    res_eq = network_analysis.analyse_network(dat, targets=[1, 2])

    assert (np.isclose(
        res_eq[1]['omnibus_te'], res_me[1]['omnibus_te'],
        rtol=0.05)), ('TE into first target is not equal for both binning'
                      ' methods.')
    assert (np.isclose(
        res_eq[2]['omnibus_te'], res_me[2]['omnibus_te'],
        rtol=0.05)), ('TE into second target is not equal for both binning'
                      ' methods.')
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_discrete',
        'discretise_method': 'max_ent',
        '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_me = network_analysis.analyse_network(dat, targets=[1, 2])
    analysis_opts = {'discretise_method': 'equal'}
    res_eq = network_analysis.analyse_network(dat, targets=[1, 2])

    assert (np.isclose(res_eq[1]['omnibus_te'], res_me[1]['omnibus_te'],
            rtol=0.05)), ('TE into first target is not equal for both binning'
                          ' methods.')
    assert (np.isclose(res_eq[2]['omnibus_te'], res_me[2]['omnibus_te'],
            rtol=0.05)), ('TE into second target is not equal for both binning'
                          ' methods.')
Esempio n. 6
0
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)
def test_multivariate_te_multiple_runs():
    """Test TE estimation using multiple runs on the GPU.

    Test if data is correctly split over multiple runs, if the problem size exceeds
    the GPU global memory and thus requires multiple runs. Using a number of
    permutations of 7000 requires two runs on a GPU with global memory of about
    6 GB.
    """
    dat = Data()
    dat.generate_mute_data(n_samples=1000, n_replications=10)
    analysis_opts = {
        'cmi_calc_name': 'opencl_kraskov',
        'n_perm_max_stat': 7000,
        'n_perm_min_stat': 7000,
        '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])
Esempio n. 8
0
def test_multivariate_te_multiple_runs():
    """Test TE estimation using multiple runs on the GPU.

    Test if data is correctly split over multiple runs, if the problem size exceeds
    the GPU global memory and thus requires multiple runs. Using a number of
    permutations of 7000 requires two runs on a GPU with global memory of about
    6 GB.
    """
    dat = Data()
    dat.generate_mute_data(n_samples=1000, n_replications=10)
    analysis_opts = {
        'cmi_calc_name': 'opencl_kraskov',
        'n_perm_max_stat': 7000,
        'n_perm_min_stat': 7000,
        '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])
Esempio n. 9
0
import os
import time
import numpy as np
from idtxl.multivariate_te import Multivariate_te
from idtxl.data import Data

start_time = time.time()
dat = Data()  # initialise an empty data object
dat.generate_mute_data(n_samples=1000, n_replications=10)
analysis_opts = {
    'cmi_calc_name': 'jidt_kraskov',
    'n_perm_max_stat': 200,
    'n_perm_min_stat': 200,
    'n_perm_omnibus': 500,
    'n_perm_max_seq': 500,
}

network_analysis = Multivariate_te(max_lag_sources=5,
                                   min_lag_sources=1,
                                   options=analysis_opts)
res = network_analysis.analyse_network(dat)
runtime = time.time() - start_time
print("---- {0} minutes".format(runtime / 60))

path = os.path.dirname(__file__) + 'output/'
np.save(path + 'test', res)
np.save(path + 'test_time', runtime)
Esempio n. 10
0
import time
import numpy as np
from idtxl.multivariate_te import Multivariate_te 
from idtxl.data import Data

start_time = time.time()
dat = Data()  # initialise an empty data object
dat.generate_mute_data(n_samples=1000, n_replications=10)
max_lag = 5
analysis_opts = {
        'cmi_calc_name': 'jidt_kraskov',
        'n_perm_max_stat': 200,
        'n_perm_min_stat': 200,
        'n_perm_omnibus': 500,
        'n_perm_max_seq': 500,
        }

network_analysis = Multivariate_te(max_lag, analysis_opts)
res = network_analysis.analyse_network(dat)
runtime = time.time() - start_time
print("---- {0} minutes".format(runtime / 60))

np.save('/home/patriciaw/Dropbox/BIC/#idtxl/test/test', res)
np.save('/home/patriciaw/Dropbox/BIC/#idtxl/test/test_time', runtime)
Esempio n. 11
0
"""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)