Esempio n. 1
0
def test_pid_and_imposed():
    """Test PID estimator on logical AND with imposed probabilities."""
    alph_x = 2
    alph_y = 2
    alph_z = 2

    x = np.array([0, 0, 1, 1])
    y = np.array([1, 0, 1, 0])
    z = np.logical_and(x, y).astype(int)

    cfg = {
        "alph_s1": alph_x,
        "alph_s2": alph_y,
        "alph_t": alph_z,
        "max_unsuc_swaps_row_parm": 3,
        "num_reps": 63,
        "max_iters": 10000,
    }

    tic = tm.time()
    est = epid.pid(x, y, z, cfg)
    toc = tm.time()

    print("\nPID evaluation       {:.3f} seconds\n".format(toc - tic))
    print("Uni s1              ", est["unq_s1"])
    print("Uni s2              ", est["unq_s2"])
    print("Shared s1_s2        ", est["shd_s1_s2"])
    print("Synergy s1_s2       ", est["syn_s1_s2"])
Esempio n. 2
0
def test_pid_xor_imposed():
    """Test PID estimator on logical XOR with imposed probabilities."""
    alph_x = 2
    alph_y = 2
    alph_z = 2

    x = np.array([0, 0, 1, 1])
    y = np.array([1, 0, 1, 0])
    z = np.logical_xor(x, y).astype(int)

    cfg = {
        'alph_s1': alph_x,
        'alph_s2': alph_y,
        'alph_t': alph_z,
        'max_unsuc_swaps_row_parm': 3,
        'num_reps': 63,
        'max_iters': 10000
    }

    tic = tm.time()
    est = epid.pid(x, y, z, cfg)
    toc = tm.time()

    print('\nPID evaluation       {:.3f} seconds\n'.format(toc - tic))
    print('Uni s1              ', est ['unq_s1'])
    print('Uni s2              ', est ['unq_s2'])
    print('Shared s1_s2        ', est ['shd_s1_s2'])
    print('Synergy s1_s2       ', est ['syn_s1_s2'])
def test_pid_and():
    """Test PID estimator on logical AND."""
    z = np.logical_and(X, Y).astype(int)
    tic = tm.time()
    est = epid.pid(X, Y, z, CFG)
    toc = tm.time()
    print('\nLogical AND')
    print('PID evaluation       {:.3f} seconds\n'.format(toc - tic))
    print('Uni s1              ', est['unq_s1'])
    print('Uni s2              ', est['unq_s2'])
    print('Shared s1_s2        ', est['shd_s1_s2'])
    print('Synergy s1_s2       ', est['syn_s1_s2'])
    assert np.isclose(0.5, est['syn_s1_s2'][0], rtol=0.05), 'Synergy is not 0.5.'
def test_pip_source_copy():
    """Test PID estimator on copied source."""
    z = X
    tic = tm.time()
    est = epid.pid(X, Y, z, CFG)
    toc = tm.time()

    print('\nCopied source')
    print('PID evaluation       {:.3f} seconds\n'.format(toc - tic))
    print('Uni s1              ', est['unq_s1'])
    print('Uni s2              ', est['unq_s2'])
    print('Shared s1_s2        ', est['shd_s1_s2'])
    print('Synergy s1_s2       ', est['syn_s1_s2'])
    assert np.isclose(1, est['unq_s1'][0], rtol=0.05), 'Unique information 1 is not 0.'
    assert np.isclose(0, est['unq_s2'][0], atol=0.05), 'Unique information 2 is not 0.'
    assert np.isclose(0, est['shd_s1_s2'][0], atol=0.05), 'Shared information is not 0.'
    assert np.isclose(0, est['syn_s1_s2'][0], atol=0.05), 'Synergy is not 0.'