Skip to content

numpy_impl share_comps produces NaN mu/beta and reports success #240

Closed

Description

@neuromechanist

numpy_impl + share_comps produces NaN mixture parameters and reports success.

Reproduction

m = AMICA_NumPy(num_models=2, num_mix=3, max_iter=5, seed=7,
                share_comps=True, share_start=1, share_int=2)
m.fit(data)   # real sample EEG, 32ch x 4096
A:    nan=0/2048
mu:   nan=96/192      <-- half
beta: nan=96/192      <-- half
comp_used sum: 64 of 64

Two RuntimeWarning: invalid value encountered in divide fire during the fit, at numpy_impl/core.py:1225 (dmu_n/dmu_d) and :1231 (dbeta_n/dbeta_d). The fit then returns normally: A is clean, gm is clean, and nothing surfaces the NaNs.

Why

Merging a column across models leaves the merged-away column with no responsibility mass, so its mixture denominators go to zero and the update is 0/0.

The PyTorch backend already handles exactly this: merged-away columns are frozen, "avoiding 0/0 NaN that Fortran tolerates behind its comp_used mask" (AGENTS.md, issue #60). Fortran survives it because comp_used masks the dead columns. In numpy_impl neither guard is present, and comp_used stays all-True, so nothing masks them and nothing reports them.

Why it matters

This is a silent failure of the kind the project rules single out: a degenerate result presented as a successful fit. The AMICA wrapper's degenerate-fit contract (#50) is torch-only, so AMICA_NumPy has no equivalent refusal.

Not a regression. Found while adding share_comps coverage for #219; the gm-ordering change there touches dAk only and cannot affect mu/beta.

Work

  • Freeze merged-away columns in numpy_impl as the PyTorch backend does, or mask them via comp_used as Fortran does. Pick one and match a reference rather than inventing a third behavior.
  • Whichever is chosen, a fit that ends with non-finite mixture parameters must not report success.
  • Cross-backend test that share_comps leaves finite parameters in both backends (.rules/backend_parity.md).

Part of #231.

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