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

Initialization of Dense with all-zero weights #585

Merged
merged 2 commits into from
Jan 27, 2023
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
4 changes: 4 additions & 0 deletions src/lava/utils/weightutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ def _determine_weight_exp(weights: np.ndarray,

scale = 0

if max_weight == min_weight == 0:
weight_exp = -0
return weight_exp

if sign_mode == SignMode.MIXED:
pos_scale = 127 / max_weight if max_weight > 0 else np.inf
neg_scale = -128 / min_weight if min_weight < 0 else np.inf
Expand Down
12 changes: 12 additions & 0 deletions tests/lava/utils/test_weightutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ def test_optimize_weight_bits_weight_exp(self) -> None:
self.assertEqual(optimized.weight_exp, -4)
self.assertEqual(optimized.num_weight_bits, 3)

def test_optimize_weight_bits_wgts_all_zero(self) -> None:
weights = np.array([0, 0, 0])
sign_mode = SignMode.EXCITATORY

optimized = optimize_weight_bits(weights=weights,
sign_mode=sign_mode,
loihi2=True)

np.testing.assert_array_equal(optimized.weights, np.array([0, 0, 0]))
self.assertEqual(optimized.weight_exp, -0)
self.assertEqual(optimized.num_weight_bits, 0)

def test_determine_weight_exp_inhibitory_0(self) -> None:
weight_exp = _determine_weight_exp(weights=np.array([-255, -128, -1]),
sign_mode=SignMode.INHIBITORY)
Expand Down