Skip to content

Add categorical (softmax) root layers to the vectorised backend#400

Merged
LegrandNico merged 4 commits into
masterfrom
feat/categorical-layers
Jul 8, 2026
Merged

Add categorical (softmax) root layers to the vectorised backend#400
LegrandNico merged 4 commits into
masterfrom
feat/categorical-layers

Conversation

@LegrandNico

@LegrandNico LegrandNico commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

A categorical layer is one softmax choice across its nodes: the prediction normalises the coupled parent activations into class probabilities, and the prediction error is the zero-sum residual one_hot - p. The belief-propagation sweeps route a categorical leaf through the new update functions.

@LegrandNico LegrandNico force-pushed the feat/natural-gradient-learning-kinds branch 2 times, most recently from b8460e1 to 3abf70d Compare July 8, 2026 15:47
Base automatically changed from feat/natural-gradient-learning-kinds to master July 8, 2026 15:54
LegrandNico and others added 2 commits July 8, 2026 17:58
A frozen volatility level is never predicted or updated, so allocating its
six LayerState fields only carries dead arrays through every tree_map over
the state. LayerState.create(has_volatility_parent=False) now sets them to
None; _match_child_vol_structure reconciles pytree structure where such a
layer meets a LayerStack with a different volatility structure.

Also computes the value-coupling variance in the volatile prediction as a
matrix product with a per-parent vector instead of materialising a
weight-matrix-sized intermediate, which matters under vmap over a batch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Replaces the five weight-gradient modes with three on a single axis — which
geometry the update respects: "standard" (no metric), "precision_weighted"
(the backprop-parity mode), and "natural" (the exact natural gradient, whose
Sherman-Morrison shrinkage reaches the conjugate posterior mean in one step,
with Bernoulli and damped-multinomial-Fisher variants for binary and
categorical children). "precision_ratio", "map_natural", and "pure_natural"
are removed.

Every kind factorises into a child-side and a parent-side vector;
vectorized_weight_gradient_factors exposes the two factors so a batched
caller can average gradients over samples with one contraction instead of
materialising a weight-matrix-sized gradient per sample.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@LegrandNico LegrandNico force-pushed the feat/categorical-layers branch from d4b5af8 to bccd565 Compare July 8, 2026 15:59
@LegrandNico LegrandNico changed the title Add categorical (softmax) leaf layers to the vectorised backend Add categorical (softmax) root layers to the vectorised backend Jul 8, 2026
@LegrandNico LegrandNico force-pushed the feat/categorical-layers branch from bccd565 to 150205c Compare July 8, 2026 21:25
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pyhgf/updates/vectorized/categorical/prediction.py 92.30% 0 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ
pyhgf/model/deep_network.py 95.02% <100.00%> (+0.49%) ⬆️
pyhgf/typing/vectorised.py 80.70% <100.00%> (ø)
pyhgf/updates/vectorized/categorical/__init__.py 100.00% <100.00%> (ø)
...updates/vectorized/categorical/prediction_error.py 100.00% <100.00%> (ø)
pyhgf/updates/vectorized/learning.py 100.00% <100.00%> (ø)
pyhgf/utils/vectorized_belief_propagation.py 93.49% <100.00%> (+0.19%) ⬆️
pyhgf/updates/vectorized/categorical/prediction.py 92.30% <92.30%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LegrandNico LegrandNico merged commit 3a3c9a2 into master Jul 8, 2026
22 checks passed
@LegrandNico LegrandNico deleted the feat/categorical-layers branch July 8, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant