Skip to content

numpy_impl share_comps applies a shared column's A-update twice #242

Closed

Description

@neuromechanist

Found during the #241 review. Distinct from #240 (NaN mu/beta), same area: numpy_impl's share_comps path is structurally further from Fortran than the nd ordering issue #219 addressed.

Fortran

A single dAk is built as a gm-weighted average across contributing models, divided by zeta = sum_h gm[h], then applied once (amica15.f90:1749-1761 build, DAXPY at :1807/:1814). A column shared by two models receives one averaged update.

numpy_impl

The A-update is a separate per-model loop (numpy_impl/core.py:1377-1381):

for h in range(self.num_models):
    idx = self.comp_list[:, h]
    self.A[:, idx] = self.A[:, idx] - self.lrate * np.dot(directions[h].T, self.A[:, idx])

No gm weighting, no zeta division, and no A-freeze guard — grep finds no _a_frozen equivalent in the file. identify_shared_components (numpy_impl/utils.py:103-166) genuinely can place one column index in comp_list[:, h] for two different h, so that column is updated twice in sequence, the second time against an already-updated self.A.

That is a different operation from Fortran's single weighted average, not a rounding difference.

Contrast with the PyTorch backend

AMICATorchNG builds the gm-weighted dAk, divides by zeta, applies it once, and freezes A for ~6 iterations after a merge (issue #60). The two backends therefore do not implement the same algorithm under share_comps.

Scope

  • Default (disjoint comp_list) is unaffected: each column belongs to one model, so the loop applies exactly one update and there is nothing to average.
  • Only reachable with share_comps=True and an actual merge.

Work

  • Port the gm-weighted single-application A-update to numpy_impl, matching Fortran and the PyTorch backend
  • Port the post-merge A-freeze, or state why it is unnecessary here
  • Cross-backend test that a shared column receives the same update in both (.rules/backend_parity.md)

Related: #240 (NaN mixture parameters on the same path), #219 (the nd ordering, fixed in #241). Part of #231.

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