Remove activation on final layer of KeyNet and ICNN#702
Merged
Conversation
The output layer of both KeyNet.gradient and ICNN.__call__ previously applied the activation function (default ReLU) after the final layer. This forced the outputs to be non-negative: KeyNet's predicted vectors could not take signed values, and ICNN's scalar potential was clamped to be non-negative. Make the final layer linear in both networks. Convexity of the ICNN output is preserved (a non-negatively weighted combination of convex features remains convex). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Reformat the final-layer loop in ICNN/KeyNet to satisfy yapf (the CI "code" Lint check). Switch conditional_monge_gap_test to LinenPotentialMLP so it uses the linen init/apply API it was written for, matching monge_gap_test (the nnx PotentialMLP now requires input_dim/rngs). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #702 +/- ##
==========================================
+ Coverage 86.90% 86.97% +0.06%
==========================================
Files 83 85 +2
Lines 8670 8888 +218
Branches 596 616 +20
==========================================
+ Hits 7535 7730 +195
- Misses 983 998 +15
- Partials 152 160 +8
🚀 New features to boost your workflow:
|
marcocuturi
added a commit
that referenced
this pull request
Jun 14, 2026
* docs: fix ICNN architecture block (linear final layer + optional bias) Follow-up to #702. The ICNN docstring "Architecture" block still showed the activation applied at every layer and omitted bias terms entirely: - show the final layer is linear (no activation, per #702) and note that convexity is still preserved; - include the optional per-layer bias (gated by `use_bias`), and clarify that the W_x input-injection terms are always bias-free. Docstring-only change; no behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs: add KeyNet architecture block, unify math, cite olausson:26 - Give KeyNet an `Architecture::` block in the same style as ICNN, showing the linear final layer and optional bias. - Unify formula rendering across both docstrings: inline expressions (the function signature, the inner-product potential, the residual output) now use `:math:` LaTeX consistently instead of a mix of plain text and inline code. Docstrings are now raw strings so LaTeX backslashes are literal. - Add the KeyNet reference (Olausson et al., 2026, "Amortizing Maximum Inner Product Search with Learned Support Functions") to references.bib and cite it from the KeyNet docstring. Docstring/bib-only change; no behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The output layer of both
KeyNet.gradientandICNN.__call__previously applied the activation function (defaultjax.nn.relu) after the final layer. This is unusual and unwanted:Change
Make the final layer linear in both networks — activation is applied to every layer except the last (
if i != num_layers - 1).Convexity of the ICNN output is preserved: the final
PositiveDenselayer is a non-negatively weighted combination (plus bias) of the convex hidden features, which remains convex. The existing convexity (Jensen) and Hessian-PSD tests intests/neural/networks/icnn_test.pytest the convexity gap rather than output non-negativity, so they continue to hold.🤖 Generated with Claude Code