Skip to content

Commit 509e62d

Browse files
fix softmax masking
1 parent f3c335e commit 509e62d

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

psyneulink/core/components/functions/nonstateful/transferfunctions.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3162,7 +3162,8 @@ def apply_softmax(self, input_value, gain, mask_threshold, output_type):
31623162
v = np.where(np.abs(v) > mask_threshold, v, -np.inf)
31633163

31643164
# Make numerically stable by shifting by max value
3165-
v = v - np.max(v)
3165+
if np.any(v != -np.inf):
3166+
v = v - np.max(v)
31663167

31673168
# Exponentiate
31683169
v = np.exp(v)

tests/composition/test_emcomposition.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ def test_assign_field_weights_and_0_vs_None(self,
778778
# Note: field_weights favors A
779779
if softmax_choice == pnl.MAX_VAL:
780780
if operation == pnl.L0:
781-
expected = [[1.703812], [0.], [3.407624]]
781+
expected = [[1.467373], [0.], [2.934746]]
782782
else:
783783
expected = [[1.419423, 0.0], [0.0, 1.419423], [2.838846, 2.838846]]
784784
else:

0 commit comments

Comments
 (0)