Skip to content

Verify NG init-basin vs Newton bit-parity via Fortran load_* init-matching #24

Closed

Description

@neuromechanist

Goal

Definitively separate "different random-init basin" from "residual Newton/M-step bit-parity
gap" for the NG backend, by starting both implementations from the same initial
parameters and comparing trajectories.

Background

Per the #21 investigation (see .context/issue-21/root_cause.md), the corrected NG M-step is
faithful (Fortran's converged solution is a stable fixed point of it), but a full fit from the
Python numpy init converges to a worse local optimum (LL ~ -3.46, corr ~0.5) than Fortran's
(-3.40, corr 0.9997). The remaining blocker is the Newton phase: at lrate=1.0 the Python Newton
amplifies a ~0.005 residual via near-marginal positive-definite pairs and diverges, where
Fortran takes a small stable step and breaks through. It is not yet proven whether the -3.46
basin is (i) purely init-driven or (ii) a residual Newton curvature bit-parity gap.

Approach

Fortran seeds its RNG deterministically from the seed param (amica17.f90:222) and supports
load_W/load_A/load_sphere/load_mu/load_beta/load_rho/load_alpha/load_gm/load_c
(reads from indirparam, same float64 column-major format as the output files).

  1. Generate the Python model's exact init (A/mu/beta/rho/alpha/gm/c, seed=42).
  2. Write them to Fortran's load files (mind the W/A transpose: Fortran W = inv(A_python).T;
    sources match index-for-index because _forward uses X.T @ W).
  3. Set load_*=1, fix_init=1, run Fortran; compare its trajectory/endpoint to the Python
    model started from the identical init.

Outcome

  • If both reach the same solution -> the -3.46 gap is init-basin; the fix is init/Newton, not a
    formula bug.
  • If Fortran reaches -3.40 and Python -3.46 from the same init -> a residual M-step/Newton
    bit-parity bug remains; localize it per-iteration.

Part of epic #9; follow-up to #21 (chosen path: implement the proven fixes first, track this
verification separately).

Activity

  1. added
    bug
    on Jul 3, 2026
  2. added a commit that references this issue on Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions