Esempio n. 1
0
def test_sia_cache_key_includes_config_dependencies(s):
    with config.override(MEASURE='EMD'):
        emd_big_phi = compute.phi(s)

    with config.override(MEASURE='L1'):
        l1_big_phi = compute.phi(s)

    assert l1_big_phi != emd_big_phi
Esempio n. 2
0
def to_calculate_mean_phi(tpm, spin_mean,t):
    N = tpm.shape[-1]

    setting_int = np.linspace(0, np.power(2, N) - 1, num=np.power(2, N)).astype(int)

    M = list(map(lambda x: list(np.binary_repr(x, width=N)), setting_int))
    M = np.flipud(np.fliplr(np.asarray(M).astype(np.int)))

    num_states = M.shape[0]
    phi_values = []

    network = pyphi.Network(tpm)
    for state in range(num_states):
        if spin_mean[state] != 0:
            phi_values.append(phi(pyphi.Subsystem(network, M[state, :], range(network.size))))
            #phi_values_sum = phi_values*spin_mean[state]

    phi_values_sqr = [phi_ * phi_ for phi_ in phi_values]

    weigth = spin_mean[np.where(spin_mean != 0)]

    phiSum = np.sum(phi_values*weigth)
    phiSus = (np.sum(phi_values_sqr*weigth) - (phiSum * phiSum)) / (N*t)

    return np.mean(phi_values), phiSum, phiSus
Esempio n. 3
0
def test_sia_wrappers(reducible):
    assert (compute.sia(reducible) ==
            models.SystemIrreducibilityAnalysis(subsystem=reducible,
                                                cut_subsystem=reducible,
                                                phi=0.0,
                                                ces=[],
                                                partitioned_ces=[]))
    assert compute.phi(reducible) == 0.0
Esempio n. 4
0
def to_calculate_mean_phi(tpm, spin_mean, eps=None):
    import numpy as np
    import pyphi
    from pyphi.compute import phi

    rows, columns = tpm.shape

    setting_int = np.linspace(0, rows - 1, num=rows).astype(int)

    M = list(map(lambda x: list(np.binary_repr(x, width=columns)),
                 setting_int))
    #M = np.flipud(np.fliplr(np.asarray(M).astype(np.int)))
    M = np.asarray(M).astype(np.int)

    #num_states = np.log2(N)
    phi_values = []

    network = pyphi.Network(tpm)
    for state in range(rows):
        if eps == None:
            if spin_mean[state] != 0:
                phi_values.append(
                    phi(
                        pyphi.Subsystem(network, M[state, :],
                                        range(network.size))))
        else:
            if spin_mean[state] < eps:
                phi_values.append(
                    phi(
                        pyphi.Subsystem(network, M[state, :],
                                        range(network.size))))

    weigth = spin_mean[np.where(spin_mean != 0)]

    phiSum = np.sum(phi_values * weigth)

    return np.mean(phi_values), phiSum
Esempio n. 5
0
def test_concept_style_phi(s):
    assert compute.phi(s) == 0.6875
Esempio n. 6
0
def test_concept_style_phi(s):
    assert compute.phi(s) == 0.6875
Esempio n. 7
0
def test_system_cut_styles(s):
    with config.override(SYSTEM_CUTS='3.0_STYLE'):
        assert compute.phi(s) == 2.3125

    with config.override(SYSTEM_CUTS='CONCEPT_STYLE'):
        assert compute.phi(s) == 0.6875
Esempio n. 8
0
def test_soup():
    # An first example attempting to capture the "soup" metaphor
    #
    # The system will consist of 6 elements 2 COPY elements (A, B) input to an
    # AND element (C) AND element (C) inputs to two COPY elements (D, E) 2 COPY
    # elements (D, E) input to an AND element (F) AND element (F) inputs to two
    # COPY elements (A, B)
    #
    # For the soup example, element B receives an additional input from D, and
    # implements AND logic instead of COPY

    nodes = 6
    tpm = np.zeros((2**nodes, nodes))

    for psi, ps in enumerate(utils.all_states(nodes)):
        cs = [0 for i in range(nodes)]
        if ps[5] == 1:
            cs[0] = 1
        if ps[3] == 1 and ps[5] == 1:
            cs[1] = 1
        if ps[0] == 1 and ps[1]:
            cs[2] = 1
        if ps[2] == 1:
            cs[3] = 1
            cs[4] = 1
        if ps[3] == 1 and ps[4] == 1:
            cs[5] = 1
        tpm[psi, :] = cs

    cm = np.array([[0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 1, 0],
                   [0, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1], [1, 1, 0, 0, 0, 0]])

    network = Network(tpm, cm)

    # State all OFF
    state = (0, 0, 0, 0, 0, 0)
    assert compute.major_complex(network, state).phi == 0.125

    # With D ON (E must also be ON otherwise the state is unreachable)
    state = (0, 0, 0, 1, 1, 0)
    assert compute.major_complex(network, state).phi == 0.215278

    # Once the connection from D to B is frozen (with D in the ON state), we
    # recover the degeneracy example
    state = (0, 0, 0, 1, 1, 0)
    partition = ((0, 1, 2), (3, 4, 5))
    output_indices = (2, 5)
    blackbox = macro.Blackbox(partition, output_indices)
    time = 2
    sub = macro.MacroSubsystem(network,
                               state, (0, 1, 2, 3, 4, 5),
                               blackbox=blackbox,
                               time_scale=time)
    assert compute.phi(sub) == 0.638888

    # When the connection from D to B is frozen (with D in the OFF state),
    # element B is inactivated and integration is compromised.
    state = (0, 0, 0, 0, 0, 0)
    partition = ((0, 1, 2), (3, 4, 5))
    output_indices = (2, 5)
    blackbox = macro.Blackbox(partition, output_indices)
    time = 2
    sub = macro.MacroSubsystem(network,
                               state, (0, 1, 2, 3, 4, 5),
                               blackbox=blackbox,
                               time_scale=time)
    assert compute.phi(sub) == 0
Esempio n. 9
0
def test_soup():
    # An first example attempting to capture the "soup" metaphor
    #
    # The system will consist of 6 elements 2 COPY elements (A, B) input to an
    # AND element (C) AND element (C) inputs to two COPY elements (D, E) 2 COPY
    # elements (D, E) input to an AND element (F) AND element (F) inputs to two
    # COPY elements (A, B)
    #
    # For the soup example, element B receives an additional input from D, and
    # implements AND logic instead of COPY

    nodes = 6
    tpm = np.zeros((2 ** nodes, nodes))

    for psi, ps in enumerate(utils.all_states(nodes)):
        cs = [0 for i in range(nodes)]
        if ps[5] == 1:
            cs[0] = 1
        if ps[3] == 1 and ps[5] == 1:
            cs[1] = 1
        if ps[0] == 1 and ps[1]:
            cs[2] = 1
        if ps[2] == 1:
            cs[3] = 1
            cs[4] = 1
        if ps[3] == 1 and ps[4] == 1:
            cs[5] = 1
        tpm[psi, :] = cs

    cm = np.array([
        [0, 0, 1, 0, 0, 0],
        [0, 0, 1, 0, 0, 0],
        [0, 0, 0, 1, 1, 0],
        [0, 1, 0, 0, 0, 1],
        [0, 0, 0, 0, 0, 1],
        [1, 1, 0, 0, 0, 0]
    ])

    network = Network(tpm, cm)

    # State all OFF
    state = (0, 0, 0, 0, 0, 0)
    assert compute.major_complex(network, state).phi == 0.125

    # With D ON (E must also be ON otherwise the state is unreachable)
    state = (0, 0, 0, 1, 1, 0)
    assert compute.major_complex(network, state).phi == 0.215278

    # Once the connection from D to B is frozen (with D in the ON state), we
    # recover the degeneracy example
    state = (0, 0, 0, 1, 1, 0)
    partition = ((0, 1, 2), (3, 4, 5))
    output_indices = (2, 5)
    blackbox = macro.Blackbox(partition, output_indices)
    time = 2
    sub = macro.MacroSubsystem(network, state, (0, 1, 2, 3, 4, 5),
                               blackbox=blackbox, time_scale=time)
    assert compute.phi(sub) == 0.638888

    # When the connection from D to B is frozen (with D in the OFF state),
    # element B is inactivated and integration is compromised.
    state = (0, 0, 0, 0, 0, 0)
    partition = ((0, 1, 2), (3, 4, 5))
    output_indices = (2, 5)
    blackbox = macro.Blackbox(partition, output_indices)
    time = 2
    sub = macro.MacroSubsystem(network, state, (0, 1, 2, 3, 4, 5),
                               blackbox=blackbox, time_scale=time)
    assert compute.phi(sub) == 0
Esempio n. 10
0
def test_concept_style_phi(s, flushcache, restore_fs_cache):
    assert compute.phi(s) == 0.6875