def test_discrete_ais():
    """Test results for discrete AIS estimation against other estimators."""

    settings = {'discretise_method': 'none',
                'alph': 2,
                'history': 2,
                'local_values': False}

    proc1, proc2 = _get_mem_binary_data()

    # Compare discrete to Gaussian estimator
    ais_estimator = JidtDiscreteAIS(settings=settings)
    mi_d = ais_estimator.estimate(proc1)

    ais_estimator = JidtGaussianAIS(settings=settings)
    mi_g = ais_estimator.estimate(proc1.astype(np.float))
    _compare_result(np.mean(mi_d), np.mean(mi_g), 'JidtDiscreteAIS',
                    'JidtGaussianAIS', 'AIS (AR process)', tol=0.07)

    # Compare discrete to Gaussian estimator on memoryless data
    ais_estimator = JidtDiscreteAIS(settings=settings)
    mi_d = ais_estimator.estimate(proc2)

    ais_estimator = JidtGaussianAIS(settings=settings)
    mi_g = ais_estimator.estimate(proc2.astype(np.float))
    _compare_result(np.mean(mi_d), np.mean(mi_g), 'JidtDiscreteAIS',
                    'JidtGaussianAIS', 'AIS (AR process, no mem.)', tol=0.05)
    _assert_result(mi_d, 0, 'JidtDiscreteAIS', 'MI (no memory)')
    _assert_result(mi_g, 0, 'JidtGaussianAIS', 'MI (no memory)')
Example #2
0
def test_discrete_ais():
    """Test results for discrete AIS estimation against other estimators."""

    settings = {
        'discretise_method': 'none',
        'alph': 2,
        'history': 2,
        'local_values': False
    }

    proc1, proc2 = _get_mem_binary_data()

    # Compare discrete to Gaussian estimator
    ais_estimator = JidtDiscreteAIS(settings=settings)
    mi_d = ais_estimator.estimate(proc1)

    ais_estimator = JidtGaussianAIS(settings=settings)
    mi_g = ais_estimator.estimate(proc1.astype(np.float))
    _compare_result(np.mean(mi_d),
                    np.mean(mi_g),
                    'JidtDiscreteAIS',
                    'JidtGaussianAIS',
                    'AIS (AR process)',
                    tol=0.07)

    # Compare discrete to Gaussian estimator on memoryless data
    ais_estimator = JidtDiscreteAIS(settings=settings)
    mi_d = ais_estimator.estimate(proc2)

    ais_estimator = JidtGaussianAIS(settings=settings)
    mi_g = ais_estimator.estimate(proc2.astype(np.float))
    _compare_result(np.mean(mi_d),
                    np.mean(mi_g),
                    'JidtDiscreteAIS',
                    'JidtGaussianAIS',
                    'AIS (AR process, no mem.)',
                    tol=0.05)
    _assert_result(mi_d, 0, 'JidtDiscreteAIS', 'MI (no memory)')
    _assert_result(mi_g, 0, 'JidtGaussianAIS', 'MI (no memory)')
Example #3
0
def test_one_two_dim_input_discrete():
    """Test one- and two-dimensional input for discrete estimators."""
    expected_mi, src_one, s, target_one = _get_gauss_data(expand=False,
                                                          seed=SEED)
    src_two = np.expand_dims(src_one, axis=1)
    target_two = np.expand_dims(target_one, axis=1)
    ar_src_one, s = _get_ar_data(expand=False, seed=SEED)
    ar_src_two = np.expand_dims(ar_src_one, axis=1)

    settings = {
        'discretise_method': 'equal',
        'n_discrete_bins': 4,
        'history_target': 1,
        'history': 2
    }
    # MI
    mi_estimator = JidtDiscreteMI(settings=settings)
    mi_cor_one = mi_estimator.estimate(src_one, target_one)
    _assert_result(mi_cor_one, expected_mi, 'JidtDiscreteMI', 'MI',
                   0.08)  # More variability here
    mi_cor_two = mi_estimator.estimate(src_two, target_two)
    _assert_result(mi_cor_two, expected_mi, 'JidtDiscreteMI', 'MI',
                   0.08)  # More variability here
    _compare_result(mi_cor_one, mi_cor_two, 'JidtDiscreteMI one dim',
                    'JidtDiscreteMI two dim', 'MI')
    # CMI
    cmi_estimator = JidtDiscreteCMI(settings=settings)
    mi_cor_one = cmi_estimator.estimate(src_one, target_one)
    _assert_result(mi_cor_one, expected_mi, 'JidtDiscreteCMI', 'CMI',
                   0.08)  # More variability here
    mi_cor_two = cmi_estimator.estimate(src_two, target_two)
    _assert_result(mi_cor_two, expected_mi, 'JidtDiscreteCMI', 'CMI',
                   0.08)  # More variability here
    _compare_result(mi_cor_one, mi_cor_two, 'JidtDiscreteMI one dim',
                    'JidtDiscreteMI two dim', 'CMI')
    # TE
    te_estimator = JidtDiscreteTE(settings=settings)
    mi_cor_one = te_estimator.estimate(src_one[1:], target_one[:-1])
    _assert_result(mi_cor_one, expected_mi, 'JidtDiscreteTE', 'TE',
                   0.08)  # More variability here
    mi_cor_two = te_estimator.estimate(src_one[1:], target_one[:-1])
    _assert_result(mi_cor_two, expected_mi, 'JidtDiscreteTE', 'TE',
                   0.08)  # More variability here
    _compare_result(mi_cor_one, mi_cor_two, 'JidtDiscreteMI one dim',
                    'JidtDiscreteMI two dim', 'TE')
    # AIS
    ais_estimator = JidtDiscreteAIS(settings=settings)
    mi_cor_one = ais_estimator.estimate(ar_src_one)
    mi_cor_two = ais_estimator.estimate(ar_src_two)
    _compare_result(mi_cor_one, mi_cor_two, 'JidtDiscreteAIS one dim',
                    'JidtDiscreteAIS two dim', 'AIS (AR process)')
def test_one_two_dim_input_discrete():
    """Test one- and two-dimensional input for discrete estimators."""
    expected_mi, src_one, s, target_one = _get_gauss_data(expand=False)
    src_two = np.expand_dims(src_one, axis=1)
    target_two = np.expand_dims(target_one, axis=1)
    ar_src_one, s = _get_ar_data(expand=False)
    ar_src_two = np.expand_dims(ar_src_one, axis=1)

    settings = {'discretise_method': 'equal',
                'n_discrete_bins': 4,
                'history_target': 1,
                'history': 2}
    # MI
    mi_estimator = JidtDiscreteMI(settings=settings)
    mi_cor_one = mi_estimator.estimate(src_one, target_one)
    _assert_result(mi_cor_one, expected_mi, 'JidtDiscreteMI', 'MI')
    mi_cor_two = mi_estimator.estimate(src_two, target_two)
    _assert_result(mi_cor_two, expected_mi, 'JidtDiscreteMI', 'MI')
    _compare_result(mi_cor_one, mi_cor_two,
                    'JidtDiscreteMI one dim', 'JidtDiscreteMI two dim', 'MI')
    # CMI
    cmi_estimator = JidtDiscreteCMI(settings=settings)
    mi_cor_one = cmi_estimator.estimate(src_one, target_one)
    _assert_result(mi_cor_one, expected_mi, 'JidtDiscreteCMI', 'CMI')
    mi_cor_two = cmi_estimator.estimate(src_two, target_two)
    _assert_result(mi_cor_two, expected_mi, 'JidtDiscreteCMI', 'CMI')
    _compare_result(mi_cor_one, mi_cor_two,
                    'JidtDiscreteMI one dim', 'JidtDiscreteMI two dim', 'CMI')
    # TE
    te_estimator = JidtDiscreteTE(settings=settings)
    mi_cor_one = te_estimator.estimate(src_one[1:], target_one[:-1])
    _assert_result(mi_cor_one, expected_mi, 'JidtDiscreteTE', 'TE')
    mi_cor_two = te_estimator.estimate(src_one[1:], target_one[:-1])
    _assert_result(mi_cor_two, expected_mi, 'JidtDiscreteTE', 'TE')
    _compare_result(mi_cor_one, mi_cor_two,
                    'JidtDiscreteMI one dim', 'JidtDiscreteMI two dim', 'TE')
    # AIS
    ais_estimator = JidtDiscreteAIS(settings=settings)
    mi_cor_one = ais_estimator.estimate(ar_src_one)
    mi_cor_two = ais_estimator.estimate(ar_src_two)
    _compare_result(mi_cor_one, mi_cor_two,
                    'JidtDiscreteAIS one dim', 'JidtDiscreteAIS two dim',
                    'AIS (AR process)')