예제 #1
0
파일: test_convert.py 프로젝트: roijo/pyphi
def test_nondet_state_by_node2state_by_state():
    # Test for nondeterministic TPM.
    result = convert.state_by_node2state_by_state(state_by_node_nondet)
    expected = state_by_state_nondet
    print("Result:")
    print(result)
    print("Expected:")
    print(expected)
    assert np.array_equal(result, expected)
예제 #2
0
파일: test_convert.py 프로젝트: roijo/pyphi
def test_2_d_state_by_node2state_by_state():
    # Check with 2-D form.
    result = convert.state_by_node2state_by_state(state_by_node)
    expected = state_by_state
    print("Result:")
    print(result)
    print("Expected:")
    print(expected)
    assert np.array_equal(result, expected)
예제 #3
0
def test_nondet_state_by_node2state_by_state():
    # Test for nondeterministic TPM.
    result = convert.state_by_node2state_by_state(state_by_node_nondet)
    expected = state_by_state_nondet
    print("Result:")
    print(result)
    print("Expected:")
    print(expected)
    assert np.array_equal(result, expected)
예제 #4
0
def test_2_d_state_by_node2state_by_state():
    # Check with 2-D form.
    result = convert.state_by_node2state_by_state(state_by_node)
    expected = state_by_state
    print("Result:")
    print(result)
    print("Expected:")
    print(expected)
    assert np.array_equal(result, expected)
예제 #5
0
파일: test_convert.py 프로젝트: roijo/pyphi
def test_n_d_state_by_node2state_by_state():
    # Check with N-D form.
    sbn = convert.to_n_dimensional(state_by_node)
    result = convert.state_by_node2state_by_state(sbn)
    expected = state_by_state
    print("Result:")
    print(result)
    print("Expected:")
    print(expected)
    assert np.array_equal(result, expected)
예제 #6
0
def test_state_by_node2state_by_state():
    sbn_tpm = np.array([[0, 0], [1, 0], [0, 1], [1, 1]])
    expected = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0],
                         [0, 0, 0, 1]]).astype(float)
    result = convert.state_by_node2state_by_state(sbn_tpm)
    print("Result:")
    print(result)
    print("Expected:")
    print(expected)
    assert np.array_equal(result, expected)
예제 #7
0
def test_n_d_state_by_node2state_by_state():
    # Check with N-D form.
    sbn = convert.to_multidimensional(state_by_node)
    result = convert.state_by_node2state_by_state(sbn)
    expected = state_by_state
    print("Result:")
    print(result)
    print("Expected:")
    print(expected)
    assert np.array_equal(result, expected)
예제 #8
0
def test_nonsquare_nondeterministic_1_state_by_node2state_by_state():
    result = convert.state_by_node2state_by_state(nonsquare_nondeterministic_1)
    # fmt: off
    answer = np.array([
        [0.126, 0.504, 0.014, 0.056, 0.054, 0.216, 0.006, 0.024],
        [0.035, 0.315, 0.035, 0.315, 0.015, 0.135, 0.015, 0.135],
        [0.016, 0.004, 0.064, 0.016, 0.144, 0.036, 0.576, 0.144],
        [0.378, 0.162, 0.252, 0.108, 0.042, 0.018, 0.028, 0.012],
    ])
    # fmt: on
    assert np.allclose(result, answer)
예제 #9
0
def test_nonsquare_deterministic_1_state_by_node2state_by_state():
    result = convert.state_by_node2state_by_state(nonsquare_deterministic_1)
    # fmt: off
    answer = np.array([
        [0., 1., 0., 0., 0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 1., 0.],
        [0., 0., 0., 1., 0., 0., 0., 0.],
        [0., 0., 0., 0., 1., 0., 0., 0.],
    ])
    # fmt: on
    assert np.array_equal(result, answer)
예제 #10
0
def test_nonsquare_nondeterministic_2_state_by_node2state_by_state():
    result = convert.state_by_node2state_by_state(nonsquare_nondeterministic_2)
    # fmt: off
    answer = np.array([
        [1.  , 0.  , 0.  , 0.  ],
        [0.09, 0.81, 0.01, 0.09],
        [0.14, 0.06, 0.56, 0.24],
        [0.63, 0.27, 0.07, 0.03],
        [0.28, 0.42, 0.12, 0.18],
        [0.2 , 0.2 , 0.3 , 0.3 ],
        [0.08, 0.72, 0.02, 0.18],
        [0.18, 0.72, 0.02, 0.08],
    ])
    # fmt: on
    assert np.allclose(result, answer)
예제 #11
0
def test_state_by_node2state_by_state():
    sbn_tpm = np.array([
        [0, 0],
        [1, 0],
        [0, 1],
        [1, 1]
    ])
    expected = np.array([
        [1, 0, 0, 0],
        [0, 1, 0, 0],
        [0, 0, 1, 0],
        [0, 0, 0, 1]
    ]).astype(float)
    result = convert.state_by_node2state_by_state(sbn_tpm)
    print("Result:")
    print(result)
    print("Expected:")
    print(expected)
    assert np.array_equal(result, expected)