Skip to content

Commit

Permalink
test/test_tpm.py: Test tpm.reconstitute_tpm()
Browse files Browse the repository at this point in the history
  • Loading branch information
wmayner committed Jun 21, 2019
1 parent adf6de6 commit 161369e
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion test/test_tpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

import numpy as np

from pyphi.tpm import expand_tpm, infer_cm, is_state_by_state, marginalize_out
from pyphi import Subsystem
from pyphi.tpm import (
expand_tpm, infer_cm, is_state_by_state, marginalize_out,
reconstitute_tpm
)


def test_is_state_by_state():
Expand Down Expand Up @@ -48,3 +52,31 @@ def test_marginalize_out(s):

def test_infer_cm(rule152):
assert np.array_equal(infer_cm(rule152.tpm), rule152.cm)

def test_reconstitute_tpm(standard, s_complete, rule152, noised):
# Check subsystem and network TPM are the same when the subsystem is the
# whole network
assert np.array_equal(reconstitute_tpm(s_complete), standard.tpm)

# Regression tests
answer = np.array([
[[[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 1.],
[0., 1., 0.]]],
[[[0., 1., 0.],
[0., 0., 0.]],
[[1., 0., 1.],
[1., 1., 0.]]]
])
subsystem = Subsystem(rule152, (0,)*5, (0, 1, 2))
assert np.array_equal(answer, reconstitute_tpm(subsystem))

subsystem = Subsystem(noised, (0, 0, 0), (0, 1))
answer = np.array([
[[0. , 0. ],
[0.7, 0. ]],
[[0. , 0. ],
[1. , 0. ]]
])
assert np.array_equal(answer, reconstitute_tpm(subsystem))

0 comments on commit 161369e

Please sign in to comment.