def test_state_by_state2state_by_node(): result = convert.state_by_state2state_by_node(state_by_state) expected = convert.to_n_dimensional(state_by_node) print("Result:") print(result) print("Expected:") print(expected) assert np.array_equal(result, expected)
def test_state_by_state2state_by_node(): result = convert.state_by_state2state_by_node(state_by_state) expected = convert.to_multidimensional(state_by_node) print("Result:") print(result) print("Expected:") print(expected) assert np.array_equal(result, expected)
def test_blackbox_timescale(): # System is an OR gate and a COPY gate; the OR gate is connected with a # self loop. # fmt: off tpm = convert.to_multidimensional( np.array([ [0, 0], [1, 1], [1, 0], [1, 1], ])) cm = np.array([ [1, 1], [1, 0], ]) # fmt: on indices = (0, 1) blackbox = macro.Blackbox(((0, ), (1, )), (0, 1)) steps = 2 state = (1, 0) system = macro.SystemAttrs(tpm, cm, indices, state) result = macro.run_tpm(system, steps, blackbox) # fmt: off answer = convert.state_by_state2state_by_node( np.array([ [1, 3, 1, 3], [0, 4, 0, 4], [1, 3, 1, 3], [0, 4, 0, 4], ]) / 8) # fmt: on np.testing.assert_array_equal(result, answer) result = macro.run_tpm(system, steps, blackbox) # fmt: off answer = convert.state_by_state2state_by_node( np.array([ [1, 1, 1, 1], [0, 2, 0, 2], [1, 1, 1, 1], [0, 2, 0, 2], ]) / 4) # fmt: on np.testing.assert_array_equal(result, answer)
def test_nondet_state_by_state2state_by_node(): # Test for nondeterministic TPM. result = convert.state_by_state2state_by_node(state_by_state_nondet) expected = convert.to_n_dimensional(state_by_node_nondet) print("Result:") print(result) print("Expected:") print(expected) assert np.array_equal(result, expected)
def test_nondet_state_by_state2state_by_node(): # Test for nondeterministic TPM. result = convert.state_by_state2state_by_node(state_by_state_nondet) expected = convert.to_multidimensional(state_by_node_nondet) print("Result:") print(result) print("Expected:") print(expected) assert np.array_equal(result, expected)
def test_blackbox_timescale(): # System is an OR gate and a COPY gate; the OR gate is connected with a # self loop. tpm = convert.to_multidimensional(np.array([ [0, 0], [1, 1], [1, 0], [1, 1], ])) cm = np.array([ [1, 1], [1, 0], ]) indices = (0, 1) blackbox = macro.Blackbox(((0,), (1,)), (0, 1)) steps = 2 state = (1, 0) system = macro.SystemAttrs(tpm, cm, indices, state) result = macro.run_tpm(system, steps, blackbox) answer = convert.state_by_state2state_by_node(np.array([ [1, 3, 1, 3], [0, 4, 0, 4], [1, 3, 1, 3], [0, 4, 0, 4], ]) / 8) np.testing.assert_array_equal(result, answer) result = macro.run_tpm(system, steps, blackbox) answer = convert.state_by_state2state_by_node(np.array([ [1, 1, 1, 1], [0, 2, 0, 2], [1, 1, 1, 1], [0, 2, 0, 2], ]) / 4) np.testing.assert_array_equal(result, answer)
def test_make_macro_tpm(): answer_tpm = convert.state_by_state2state_by_node(np.array([ [0.375, 0.375, 0.125, 0.125], [0.375, 0.375, 0.125, 0.125], [0.375, 0.375, 0.125, 0.125], [0.375, 0.375, 0.125, 0.125], ])) partition = ((0,), (1, 2)) grouping = (((0,), (1,)), ((0, 1), (2,))) coarse_grain = macro.CoarseGrain(partition, grouping) assert np.array_equal(coarse_grain.make_mapping(), [0, 1, 0, 1, 0, 1, 2, 3]) micro_tpm = np.zeros((8, 3)) + 0.5 macro_tpm = coarse_grain.macro_tpm(micro_tpm) assert np.array_equal(answer_tpm, macro_tpm) micro_tpm = np.zeros((8, 8)) + 0.125 macro_tpm = coarse_grain.macro_tpm(micro_tpm) assert np.array_equal(answer_tpm, macro_tpm)
def test_make_macro_tpm(): answer_tpm = convert.state_by_state2state_by_node( np.array([ [0.375, 0.375, 0.125, 0.125], [0.375, 0.375, 0.125, 0.125], [0.375, 0.375, 0.125, 0.125], [0.375, 0.375, 0.125, 0.125], ])) partition = ((0, ), (1, 2)) grouping = (((0, ), (1, )), ((0, 1), (2, ))) coarse_grain = macro.CoarseGrain(partition, grouping) assert np.array_equal(coarse_grain.make_mapping(), [0, 1, 0, 1, 0, 1, 2, 3]) micro_tpm = np.zeros((8, 3)) + 0.5 macro_tpm = coarse_grain.macro_tpm(micro_tpm) assert np.array_equal(answer_tpm, macro_tpm) micro_tpm = np.zeros((8, 8)) + 0.125 macro_tpm = coarse_grain.macro_tpm(micro_tpm) assert np.array_equal(answer_tpm, macro_tpm)