def test_recurrent_mech_with_learning(self): R = RecurrentTransferMechanism(size=4, function=Linear, matrix=np.full((4, 4), 0.1), enable_learning=True) # Test that all of these are the same: np.testing.assert_allclose( R.recurrent_projection.mod_matrix, [[0.1, 0.1, 0.1, 0.1], [0.1, 0.1, 0.1, 0.1], [0.1, 0.1, 0.1, 0.1], [0.1, 0.1, 0.1, 0.1]]) np.testing.assert_allclose(R.recurrent_projection.matrix, R.matrix) np.testing.assert_allclose(R.input_state.path_afferents[0].matrix, R.matrix) # Test that activity is properly computed prior to learning p = Process(pathway=[R]) R.learning_enabled = False p.execute([1, 1, 0, 0]) p.execute([1, 1, 0, 0]) np.testing.assert_allclose(R.value, [[1.2, 1.2, 0.2, 0.2]]) # Test that activity and weight changes are properly computed with learning R.learning_enabled = True p.execute([1, 1, 0, 0]) np.testing.assert_allclose(R.value, [[1.28, 1.28, 0.28, 0.28]]) np.testing.assert_allclose(R.recurrent_projection.mod_matrix, [[ 0.1, 0.18192000000000003, 0.11792000000000001, 0.11792000000000001 ], [ 0.18192000000000003, 0.1, 0.11792000000000001, 0.11792000000000001 ], [ 0.11792000000000001, 0.11792000000000001, 0.1, 0.10392000000000001 ], [ 0.11792000000000001, 0.11792000000000001, 0.10392000000000001, 0.1 ]]) p.execute([1, 1, 0, 0]) np.testing.assert_allclose( R.value, [[1.4268928, 1.4268928, 0.3589728, 0.3589728]]) np.testing.assert_allclose(R.recurrent_projection.mod_matrix, [[0.1, 0.28372115, 0.14353079, 0.14353079], [0.28372115, 0.1, 0.14353079, 0.14353079], [0.14353079, 0.14353079, 0.1, 0.11036307], [0.14353079, 0.14353079, 0.11036307, 0.1]])
def test_recurrent_mech_with_learning(self): R = RecurrentTransferMechanism(size=4, function=Linear, matrix=np.full((4, 4), 0.1), enable_learning=True) # Test that all of these are the same: np.testing.assert_allclose( R.matrix, [[0.1, 0.1, 0.1, 0.1], [0.1, 0.1, 0.1, 0.1], [0.1, 0.1, 0.1, 0.1], [0.1, 0.1, 0.1, 0.1]]) np.testing.assert_allclose(R.recurrent_projection.matrix, R.matrix) np.testing.assert_allclose(R.input_state.path_afferents[0].matrix, R.matrix) # Test that activity is properly computed prior to learning p = Process(pathway=[R]) R.learning_enabled = False p.execute([1, 1, 0, 0]) p.execute([1, 1, 0, 0]) np.testing.assert_allclose(R.value, [[1.2, 1.2, 0.2, 0.2]]) # Test that activity and weight changes are properly computed with learning R.learning_enabled = True p.execute([1, 1, 0, 0]) np.testing.assert_allclose(R.value, [[1.28, 1.28, 0.28, 0.28]]) np.testing.assert_allclose( R.matrix, [[ 0.18192000000000003, 0.18192000000000003, 0.11792000000000001, 0.11792000000000001 ], [ 0.18192000000000003, 0.18192000000000003, 0.11792000000000001, 0.11792000000000001 ], [ 0.11792000000000001, 0.11792000000000001, 0.10392000000000001, 0.10392000000000001 ], [ 0.11792000000000001, 0.11792000000000001, 0.10392000000000001, 0.10392000000000001 ]]) p.execute([1, 1, 0, 0]) np.testing.assert_allclose( R.value, [[1.5317504, 1.5317504, 0.3600704, 0.3600704]]) np.testing.assert_allclose( R.matrix, [[ 0.299232964395008, 0.299232964395008, 0.14549689896140802, 0.14549689896140802 ], [ 0.299232964395008, 0.299232964395008, 0.14549689896140802, 0.14549689896140802 ], [ 0.14549689896140802, 0.14549689896140802, 0.11040253464780801, 0.11040253464780801 ], [ 0.14549689896140802, 0.14549689896140802, 0.11040253464780801, 0.11040253464780801 ]])