You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
numpy_impl: do_reject outlier rejection is non-functional (data_mask never initialized/consumed) #123
Found while fixing ty diagnostics (#122). `AMICA_NumPy._reject_outliers()`
(`pyAMICA/numpy_impl/core.py`) references `self.data_mask` at
`self.data_mask[outliers] = False`, but `data_mask` is never initialized
anywhere in `init`/`_initialize_parameters` -- `ty` correctly flags this
as `Object of type Self has no attribute data_mask`. If a user sets
`do_reject=True` with `maxrej > 0` and the iteration reaches the reject
schedule (`_optimize`'s do_reject block), this raises `AttributeError` at
runtime.
Separately, even once `data_mask` exists, nothing reads it:
`_get_updates_and_likelihood`/`_get_block_updates` iterate over
`self.data` directly with no reference to `data_mask` at all, unlike the
torch backend's `good_idx` mechanism (`AMICATorchNG`, which actually
restricts `X_use = X_t[:, self.good_idx]` each iteration). So the rejection
mask, even if computed without crashing, currently has zero effect on the
fit -- the feature is a no-op at best, a crash at worst.
No test exercises `do_reject` on the NumPy backend (only the torch backend's
`test_ng_backend.py`/`test_ng_pdf_families.py` do), which is presumably why
this has gone unnoticed.
Scope
Port the torch backend's `good_idx`-style filtering to the NumPy backend:
initialize a good-sample index/mask in `_initialize_parameters`, restrict the
per-iteration data to it in `_get_updates_and_likelihood`, and shrink it in
`_reject_outliers` (mirroring `AMICATorchNG._reject_outliers`). Add a
NumPy-backend test analogous to the torch `do_reject` tests.
Not fixed here: #122 only added a minimal `data_mask` initialization to stop
the immediate crash risk; it does not make the feature functional.
Correction to the root-cause scope (surfaced by the PR #124 type-safety review):
The crash is worse than this issue's title/body describe. It is not gated on do_rejectreaching the reject schedule -- _update_parameters divides by self.num_good_samples on every iteration once do_reject is set (numpy_impl/core.py, the if self.do_reject: branch), but num_good_samples is only ever assigned inside _reject_outliers (which fires later, on rejstart/rejint). So iteration 0 raises AttributeError immediately, independent of maxrej/rejstart/rejint. There are therefore two wired-up defects, not one:
num_good_samples used before it is ever assigned (immediate crash).
data_mask is computed by _reject_outliers but never consumed by the E-step to restrict the fit data (silent no-op even if (1) were fixed).
Interim state after PR #124: fit() now refuses do_reject=True on the NumPy backend with a clear NotImplementedError pointing here (rather than crashing cryptically), _reject_outliers is kept as dormant, self-contained scaffolding, and there is a regression test (test_do_reject_refused_on_numpy_backend). The real fix here is to port the PyTorch backend's good_idx-style filtering (E-step accumulates only over data_mask, and num_good_samples initialized to num_samples), then remove the gate and add a real-data parity test.
Activity
Fix ty diagnostics in numpy_impl/core.py (91 -> 0)
Address PR #124 review: gate numpy do_reject, guard write output
neuromechanist commentedon Jul 14, 2026
Correction to the root-cause scope (surfaced by the PR #124 type-safety review):
The crash is worse than this issue's title/body describe. It is not gated on
do_rejectreaching the reject schedule --_update_parametersdivides byself.num_good_sampleson every iteration oncedo_rejectis set (numpy_impl/core.py, theif self.do_reject:branch), butnum_good_samplesis only ever assigned inside_reject_outliers(which fires later, onrejstart/rejint). So iteration 0 raisesAttributeErrorimmediately, independent ofmaxrej/rejstart/rejint. There are therefore two wired-up defects, not one:num_good_samplesused before it is ever assigned (immediate crash).data_maskis computed by_reject_outliersbut never consumed by the E-step to restrict the fit data (silent no-op even if (1) were fixed).Interim state after PR #124:
fit()now refusesdo_reject=Trueon the NumPy backend with a clearNotImplementedErrorpointing here (rather than crashing cryptically),_reject_outliersis kept as dormant, self-contained scaffolding, and there is a regression test (test_do_reject_refused_on_numpy_backend). The real fix here is to port the PyTorch backend'sgood_idx-style filtering (E-step accumulates only overdata_mask, andnum_good_samplesinitialized tonum_samples), then remove the gate and add a real-data parity test.Fix ty type-check diagnostics repo-wide (496 -> 0) (#124)
Implement NumPy do_reject via good_idx (#123)
Docs: NumPy do_reject is now functional (#123)
Implement NumPy do_reject outlier rejection via good_idx (#123) (#126)
Bump version to 0.1.2 (#131)
Phase 3: MLX rejection, LLt, export, MIR (#311)