Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

• patch_for_bias_nodes #3153

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions psyneulink/core/compositions/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,13 @@
^^^^^^^^^^^^

`BIAS` `NodeRole` can be used to implement BIAS Nodes, which add a bias (constant value) to the input of another
Node, that can also be modified by `learning <Composition_Learning>`. A bias Node is implemented by adding a
`ProcessingMechanism` to the Composition and requiring it to have the `BIAS` `NodeRole`. The ProcessingMechanims
cannot have any afferent Projections, and should project to the `InputPort` containing the values to be biased. If
the bias is to be learned, the `learnable <MappingProjection.learnable>` attribute of the MappingProjeciton
should be set to True. The value of the bias, and how it is applied to the values being biased are specified as
described below:
Node, that can also be modified by `learning <Composition_Learning>`. A BIAS Node is implemented by adding a
`ProcessingMechanism` to the Composition and requiring it to have the `BIAS` `NodeRole`. This can be done using
any of the methods described `above <Composition_Nodes>` for assigning `NodeRoles <NodeRole>` tp a Node. The
ProcessingMechanism cannot have any afferent Projections, and should project to the `InputPort` of the Node with
the values to be biased. If the bias is to be learned, the `learnable <MappingProjection.learnable>` attribute of
the MappingProjeciton should be set to True. The value of the bias, and how it is applied to the values being biased
are specified as described below:

*Single bias value*. To apply a single scalar bias value to all elements of the array being biased, the
`default_variable <Component_Variable>` of the BIAS Node should be specified as a scalar value, and the `matrix
Expand Down
6 changes: 4 additions & 2 deletions psyneulink/library/compositions/pytorchwrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,10 @@ def __init__(self,
self._composition._get_node_index(node),
device,
context=context)
pytorch_node._is_bias = any(input_port.default_input == DEFAULT_VARIABLE
for input_port in node.input_ports)
# pytorch_node._is_bias = all(input_port.default_input == DEFAULT_VARIABLE
# for input_port in node.input_ports)
pytorch_node._is_bias = node in self._composition.get_nodes_by_role(NodeRole.BIAS)

self.nodes_map[node] = pytorch_node
self.wrapped_nodes.append(pytorch_node)

Expand Down
10 changes: 5 additions & 5 deletions tests/composition/test_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -8139,11 +8139,11 @@ def test_danglingControlledMech(self):
@pytest.mark.parametrize(
'removed_nodes, expected_dependencies',
[
# (['A'], {'B': set(), 'C': set('B'), 'D': set('C'), 'E': set('C')}),
# (['C'], {'A': set(), 'B': set(), 'D': set(), 'E': set()}),
# (['E'], {'A': set(), 'B': set(), 'C': {'A', 'B'}, 'D': set('C')}),
# (['A', 'B'], {'C': set(), 'D': set('C'), 'E': set('C')}),
# (['D', 'E'], {'A': set(), 'B': set(), 'C': {'A', 'B'}}),
(['A'], {'B': set(), 'C': set('B'), 'D': set('C'), 'E': set('C')}),
(['C'], {'A': set(), 'B': set(), 'D': set(), 'E': set()}),
(['E'], {'A': set(), 'B': set(), 'C': {'A', 'B'}, 'D': set('C')}),
(['A', 'B'], {'C': set(), 'D': set('C'), 'E': set('C')}),
(['D', 'E'], {'A': set(), 'B': set(), 'C': {'A', 'B'}}),
(['A', 'B', 'C', 'D', 'E'], {}),
]
)
Expand Down
Loading