Repository navigation
Open
Labels
bugSomething isn't working
Description
Found during the epic #324 Phase 1 review (PR #326). This is an existing divergence, not introduced by the epic, and it is not recorded in docs/guides/amica-differences.md.
Reference behavior
With do_sphere 0, the reference does not skip preprocessing: it normalizes each channel by its standard deviation and accumulates a log-determinant term (pamica/amica15.f90:516-526, the else branch of if (do_sphere)):
!--- just normalize by the channel variances (don't sphere)
call DCOPY(nx*nx,S,1,Stmp,1)
call DSCAL(nx*nx,dble(0.0),S,1)
sldet = dble(0.0)
do i = 1,nx
if (Stmp(i,i) .gt. dble(0.0)) then
S(i,i) = dble(1.0) / sqrt(Stmp(i,i))
sldet = sldet + dble(0.5)*log(S(i,i))
end if
end do
numeigs = nxStmp holds the data covariance at that point, so S = diag(1/sqrt(var_i)) for every channel with positive variance, and numeigs = nx (explicit pcakeep is ignored, which pamica already matches after PR #326).
pamica behavior
All three array backends (torch, NumPy, MLX) use an identity sphere with sldet = 0 when do_sphere=False, so the data are fitted unscaled.
Consequences
- The optimization runs on differently scaled data than the reference, so fits with
do_sphere=Falseare not trajectory-comparable to the binary (the natural-gradient EM is not scale-invariant through its initializationA = I + noiseand step sizes). - The reported log-likelihood differs by the Jacobian term.
- The reference's own term looks inconsistent:
log|det S|forS = diag(1/sqrt(var_i))issum_i log(1/sqrt(var_i)) = -0.5 * sum_i log(var_i), but the reference accumulates0.5*log(S(i,i)) = -0.25 * log(var_i)per channel, half of that. Because the term is a constant added to every model's per-sample log-likelihood, it cancels in model posteriors and does not affect the fitted parameters, only the reported likelihood.
Decision needed
- Port the reference's per-channel variance normalization for
do_sphere=Falseto torch, NumPy and MLX (a shared decision; cross-backend test against the binary withdo_sphere 0). - Decide the log-determinant term: reproduce the reference's
0.5*log(S(i,i))for likelihood parity, or use the correctlog(S(i,i))and record that divergence (with an escape hatch, per.rules/backend_parity.md). - Until then, record the current divergence in
docs/guides/amica-differences.md(epic Epic: make MLX a first-class, end-to-end backend #324 Phase 6 does this).
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
Phase 6: end-to-end validation across backends (#332)