Skip to content

feat: configurable initial t for the adaptive GAH batch norm - #13

Merged
Matthieu-Gallet merged 1 commit into
mainfrom
feat/adaptive-gah-t-init
Sep 30, 2026
Merged

Matthieu-Gallet merged 1 commit into
mainfrom
feat/adaptive-gah-t-init

Conversation

@Matthieu-Gallet

@Matthieu-Gallet Matthieu-Gallet commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Why

BatchNormSPDMean(mean_type="adaptive_geometric_arithmetic_harmonic") always started its learnable t at 0.5. mean_options was ignored for this mean. As a result, spdnet-training's batchnorm_t_gah_init option has never had any effect: its forwarding is also wrong, see the companion spdnet-training PR.

What

  • mean_options={"t_init": t} sets the initial t. The value is validated in [0, 1], where 0 is harmonic and 1 is arithmetic. The sigmoid parametrization's right_inverse maps it to the unconstrained parameter.
  • The default stays 0.5, so no existing result changes.
  • Both constructors' docstrings now list adaptive_geometric_arithmetic_harmonic and document the option.
  • Tests: the default is 0.5; 0.2 and 0.9 are honored; the gradient reaches the unconstrained parameter; an out-of-range value raises ValueError.

Not in scope, pre-existing

BatchNormSPDMeanScalarVariance has no dispersion function for the adaptive GAH mean: _init_std has no branch for it, and the forward raises AttributeError: ... no attribute 'std_fun'. This is unchanged here.

Test

  • pytest tests/nn/test_batchnorm.py tests/test_model.py: 3209 passed.
  • ruff format --check / ruff check (0.16.7): clean.

The learnable t of the adaptive GAH mean was hard-coded to 0.5, so the
t_init options of downstream configs (spdnet-training
batchnorm_t_gah_init) had no effect. mean_options={"t_init": t} now sets
it (validated in [0, 1]; default 0.5 unchanged). Docstrings list the
adaptive GAH mean type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PQdVCDbXCd8gvf1Y4TufJR
Copilot AI balanced review requested due to automatic review settings September 29, 2026 09:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Endpoint initialization is inaccurate, and unsupported scalar-variance behavior is documented as available.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds configurable initialization for adaptive GAH batch normalization.

Changes:

  • Reads and validates mean_options["t_init"].
  • Documents the option and adds initialization/gradient tests.
File Description
src/​yetanotherspdnet/​nn/​batchnorm.py Configures adaptive GAH initialization and updates docstrings.
tests/​nn/​test_batchnorm.py Tests initialization, gradients, and validation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +359 to +360
if not 0.0 <= t_init <= 1.0:
raise ValueError(f"t_init must lie in [0, 1], got {t_init}")
@Matthieu-Gallet
Matthieu-Gallet merged commit 5b25c30 into main Sep 30, 2026
8 checks passed
@Matthieu-Gallet
Matthieu-Gallet deleted the feat/adaptive-gah-t-init branch September 30, 2026 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants