From 531d818da1d222944959b6670de2b89841881a27 Mon Sep 17 00:00:00 2001 From: jdcpni Date: Sat, 4 Nov 2023 14:56:50 -0400 Subject: [PATCH] =?UTF-8?q?=E2=80=A2=20test=5Flearning.py=20=20=20add=20te?= =?UTF-8?q?st=5Ftwo=5Foutput=5Fports=5Fon=5FOUTPUT=5FNode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/composition/test_autodiffcomposition.py | 1 - tests/composition/test_learning.py | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/composition/test_autodiffcomposition.py b/tests/composition/test_autodiffcomposition.py index 78794871de9..72338b52bfa 100644 --- a/tests/composition/test_autodiffcomposition.py +++ b/tests/composition/test_autodiffcomposition.py @@ -2655,7 +2655,6 @@ def test_two_output_ports_on_OUTPUT_Node(self): result_autodiff_nodes = autodiff.learn(inputs={input_A: [[0, 0], [0, 1], [1, 0], [1, 1]], input_B: [[1, 2], [1, 2], [1, 2], [1, 2]]}, learning_rate = .01, epochs=3) - for port, node in zip(result_autodiff_ports, result_autodiff_nodes): np.testing.assert_allclose(port, node) diff --git a/tests/composition/test_learning.py b/tests/composition/test_learning.py index 0962669615b..fc396726f03 100644 --- a/tests/composition/test_learning.py +++ b/tests/composition/test_learning.py @@ -2107,6 +2107,29 @@ def test_backprop_fct_with_3_inputs_to_linear_combination_product(self, test_var [[0.05755718, 0.06642539]], [[0.08571825, 0.10452682]]] np.testing.assert_allclose(actual=comp.results, desired=expected, atol=1e-8) + def test_two_output_ports_on_OUTPUT_Node(self): + + input_A = pnl.ProcessingMechanism(name='INPUT_A', size=2) + input_B = pnl.ProcessingMechanism(name='INPUT_B', size=2) + output = pnl.ProcessingMechanism(name='OUTPUT', size=(2,3)) + comp = Composition(name='comp') + + with pytest.raises(CompositionError) as error_text: + comp.add_backpropagation_learning_pathway([input_A, + pnl.MappingProjection(input_A, output.input_ports[0]), + output]) + error_msg = ("'OUTPUT', which is the terminal node of a learning pathway in 'comp', " + "has a more than one output_port (2), which is not currently supported for learning. " + "Trying using a different Mechanism for each output.") + assert error_msg in str(error_text.value) + # # FIX: Add these when/if learning is supported for multiple output_ports + # comp.add_backpropagation_learning_pathway([input_B, + # pnl.MappingProjection(input_B, output.input_ports[1]), + # output]) + # comp.learn(inputs={input_A: [[0, 0], [0, 1], [1, 0], [1, 1]], + # input_B: [[1, 2], [1, 2], [1, 2], [1, 2]]}, + # learning_rate = .01, epochs=3) + expected_quantities = [ (