Example #1
0
def test_background_3_node(before_state, purview, alpha, background_3_node):
    """Looking at transition (AB = 11) -> (AC = 11)"""
    after_state = (1, 1, 1)
    transition = actual.Transition(background_3_node, before_state,
                                   after_state, (0, 1), (0, 2))
    causal_link = transition.find_causal_link(Direction.EFFECT, (0, 1))
    assert causal_link.purview == purview
    assert causal_link.alpha == alpha
Example #2
0
def test_background_noised():
    tpm = np.array([[0, 0], [1, 1], [1, 1], [1, 1]])
    network = Network(tpm)
    state = (1, 1)
    transition = actual.Transition(network,
                                   state,
                                   state, (0, ), (1, ),
                                   noise_background=True)

    assert transition._ratio(Direction.EFFECT, (0, ), (1, )) == 0.415037
    assert transition._ratio(Direction.CAUSE, (1, ), (0, )) == 0.415037

    # Elements outside the transition are also frozen
    transition = actual.Transition(network,
                                   state,
                                   state, (0, ), (0, ),
                                   noise_background=True)
    assert np.array_equal(transition.cause_system.tpm, network.tpm)
    assert np.array_equal(transition.effect_system.tpm, network.tpm)
Example #3
0
def background_all_on():
    """Two OR gates, both ON.

    If we look at the transition A -> B, then B should be frozen at t-1, and
    A should have no effect on B.
    """
    tpm = np.array([[0, 0], [1, 1], [1, 1], [1, 1]])
    network = Network(tpm)
    state = (1, 1)
    return actual.Transition(network, state, state, (0, ), (1, ))
Example #4
0
def transition():
    """An OR gate with two inputs. The OR gate is ON, others are OFF."""
    tpm = np.array([[0, 0.5, 0.5], [0, 0.5, 0.5], [1, 0.5, 0.5], [1, 0.5, 0.5],
                    [1, 0.5, 0.5], [1, 0.5, 0.5], [1, 0.5, 0.5], [1, 0.5,
                                                                  0.5]])
    cm = np.array([[0, 0, 0], [1, 0, 0], [1, 0, 0]])
    network = Network(tpm, cm)
    before_state = (0, 1, 1)
    after_state = (1, 0, 0)
    return actual.Transition(network, before_state, after_state, (1, 2), (0, ))
Example #5
0
def test_potential_purviews(background_3_node):
    """Purviews must be a subset of the corresponding cause/effect system."""
    transition = actual.Transition(background_3_node, (1, 1, 1), (1, 1, 1),
                                   (0, 1), (0, 2))
    assert transition.potential_purviews(Direction.CAUSE, (0, 2)) == [(0, ),
                                                                      (1, ),
                                                                      (0, 1)]
    assert transition.potential_purviews(Direction.EFFECT, (0, 1)) == [(0, ),
                                                                       (2, ),
                                                                       (0, 2)]
Example #6
0
def background_all_off():
    """Two OR gates, both OFF."""
    # fmt: off
    tpm = np.array([
        [0, 0],
        [1, 1],
        [1, 1],
        [1, 1],
    ])
    # fmt: on
    network = Network(tpm)
    state = (0, 0)
    return actual.Transition(network, state, state, (0,), (1,))
Example #7
0
def empty_transition(transition):
    return actual.Transition(transition.network, transition.before_state,
                             transition.after_state, (), ())