def test_recurrent_mech_process_proj_matrix_change(self): R = RecurrentTransferMechanism(size=4, auto=1, hetero=-1) T = TransferMechanism(size=4, function=Linear) p = Process(size=4, pathway=[T, R], prefs=TestRecurrentTransferMechanismInSystem.simple_prefs) R.recurrent_projection.matrix = [[2, 0, 1, 3]] * 4 p.run(inputs={T: [[1, 2, 3, 4]]}) np.testing.assert_allclose(T.value, [[1, 2, 3, 4]]) np.testing.assert_allclose(R.value, [[1, 2, 3, 4]]) p.run(inputs={T: [[1, 3, 2, 5]]}) np.testing.assert_allclose(R.recurrent_projection.matrix, [[2, 0, 1, 3]] * 4) np.testing.assert_allclose(T.value, [[1, 3, 2, 5]]) np.testing.assert_allclose(R.value, [[21, 3, 12, 35]])
def test_transfer_mech_process_matrix_change(self): from psyneulink.components.projections.pathway.mappingprojection import MappingProjection T1 = TransferMechanism(size=4, function=Linear) proj = MappingProjection( matrix=[[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) T2 = TransferMechanism(size=4, function=Linear) p = Process(size=4, pathway=[T1, proj, T2]) p.run(inputs={T1: [[1, 2, 3, 4]]}) proj.matrix = [[2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2]] assert np.allclose( proj.matrix, [[2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2]]) # p.run(inputs={T1: [[1, 2, 3, 4]]}) T1.execute([[1, 2, 3, 4]]) proj.execute(context="EXECUTING testing projection") assert np.allclose( proj.matrix, np.array([[2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2]]))
def test_recurrent_mech_transfer_mech_process_three_runs(self): # this test ASSUMES that the parameter state for auto and hetero is updated one run-cycle AFTER they are set by # lines by `R.auto = 0`. If this (potentially buggy) behavior is changed, then change these values R = RecurrentTransferMechanism(size=4, auto=0, hetero=-1) T = TransferMechanism(size=3, function=Linear) p = Process(size=4, pathway=[R, T], prefs=TestRecurrentTransferMechanismInSystem.simple_prefs) p.run(inputs={R: [[1, 2, 3, 4]]}) np.testing.assert_allclose(R.value, [[1., 2., 3., 4.]]) np.testing.assert_allclose(T.value, [[10., 10., 10.]]) p.run(inputs={R: [[5, 6, 7, 8]]}) np.testing.assert_allclose(R.value, [[-4, -2, 0, 2]]) np.testing.assert_allclose(T.value, [[-4, -4, -4]]) p.run(inputs={R: [[-1, 2, -2, 5.5]]}) np.testing.assert_allclose(R.value, [[-1.0, 4.0, 2.0, 11.5]]) np.testing.assert_allclose(T.value, [[16.5, 16.5, 16.5]])