Skip to content

numpy_impl ndtmpsum uses current-iteration gm; Fortran uses the previous iteration's #219

Closed

Description

@neuromechanist

Found in review of #217. Diagnostic-only, does not affect fitted parameters.

The divergence

Fortran's gm is a module-level array that is not reassigned until update_params (amica15.f90:1789+), which runs after accum_updates_and_likelihood builds dAk (:1731-1743). So Fortran's ndtmpsum is computed with the previous iteration's gm.

In numpy_impl, self.gm is reassigned at core.py:1124/1126, before the nd block at :1271-1288. So ours uses the current iteration's gm.

When it matters

Not for num_models=1, where gm == 1.

Not for the default disjoint comp_list multi-model case either: each column belongs to exactly one model, so the gm[h] numerator cancels exactly against zeta[idx] = gm[h].

It matters only under share_comps with a genuinely shared column across two models, where the weighted average of directions is taken with different weights than Fortran would use.

Scope

self.nd is a diagnostic and a convergence-check input; it is not used to update A, mu, or beta. So this cannot change a fitted decomposition. It can change when use_grad_norm fires, though min_nd is separately unreachable on small data (#218).

There is currently no test covering numpy_impl + share_comps + nd; the sharing tests are torch-only (tests/torch_tests/test_ng_sharing.py).

Work

  • Decide whether to snapshot gm before the mixture update in numpy_impl so the ordering matches Fortran, or to accept the deviation and document it as a known diagnostic-only difference.
  • Add a numpy_impl + share_comps test that exercises nd, whichever way the above goes.
  • Check whether AMICATorchNG has the same ordering question, since it computes ndtmpsum in the same region.

Activity

  1. neuromechanist commented on Aug 16, 2026

    @neuromechanist
    MemberAuthor

    Fixed in #241. Both backends now snapshot gm before the mixture update, matching Fortran's ordering (dAk built at amica15.f90:1753, gm reassigned at :1788).

    One correction to this issue's framing, surfaced by review: the change is diagnostic-only in numpy_impl, but not in AMICATorchNG, where the same dAk is the A-update, so the ordering reaches fitted parameters there. Single-model stays bit-identical (gm == 1); multi-model shifts ~1e-6, which is floating-point association rather than semantics, since gm cancels against zeta for a disjoint comp_list.

    Both backends have discriminating tests, each verified to fail when its own fix is reverted.

    Two deeper share_comps gaps in numpy_impl came out of the same work and are tracked separately: #240 (NaN mu/beta reported as a successful fit) and #242 (a shared column's A-update applied twice instead of once as a weighted average).

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions