Skip to content

Commit

Permalink
• test_learning.py
Browse files Browse the repository at this point in the history
  add test_two_output_ports_on_OUTPUT_Node
  • Loading branch information
jdcpni committed Nov 4, 2023
1 parent fc7b12a commit 531d818
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 0 additions & 1 deletion tests/composition/test_autodiffcomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
23 changes: 23 additions & 0 deletions tests/composition/test_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
(
Expand Down

0 comments on commit 531d818

Please sign in to comment.