Skip to content

fix(alignment): correct gauss_model midpoint anchor (GH #34) - #35

Merged
sipemu merged 1 commit into
mainfrom
fix/gh-34-gauss-model-offset
Aug 7, 2026
Merged

fix(alignment): correct gauss_model midpoint anchor (GH #34)#35
sipemu merged 1 commit into
mainfrom
fix/gh-34-gauss-model-offset

Conversation

@sipemu

@sipemu sipemu commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Fixes #34.

Problem

gauss_model (and joint_gauss_model) produced samples whose mean was offset by a constant (~+1.0) from the data mean, and whose curves left the data range.

Root cause

build_augmented_srsfs (elastic_fpca.rs:717) encodes the curve level at the domain midpoint m/2:

let id = m / 2;
q_aug[(i, m)] = fid.signum() * fid.abs().sqrt();   // level at the MIDPOINT

But the generative reconstruction recovered that value and passed it to srsf_inverse as f0, which srsf_inverse treats as f(argvals[0]) — the start. So each reconstructed curve was pinned at its start to the midpoint level, shifting the whole curve by a constant (≈ the midpoint value, ~1.0 for the reporter's peak‑1 bumps).

Fix

Reconstruct from a zero start and shift so the midpoint matches the recovered level (generative.rs, both gauss_model and joint_gauss_model):

let f_mid = aug_val.signum() * aug_val * aug_val;
let mut f_new = srsf_inverse(&q_new[..m], argvals, 0.0);
let shift = f_mid - f_new[m / 2];
for val in f_new.iter_mut() { *val += shift; }

Tests

New regression gauss_model_sample_mean_no_constant_offset asserts the average sample‑mean offset from the data mean stays < 0.3 (it was ~+1.0). Full alignment (244) + elastic_fpca (15) + R‑validation (173) suites pass; clippy clean.

Note (not changed here)

The same midpoint‑vs‑start anchor mismatch also exists in the elastic_fpca.rs eigenfunctions_f reconstruction (two sites). Those feed a display output (the generative samples use eigenfunctions_q, not _f) and are R‑validated, so I've left them for a separate, carefully‑validated change rather than bundle them here.

🤖 Generated with Claude Code

gauss_model and joint_gauss_model reconstructed sampled curves by passing
the augmented level coordinate to srsf_inverse as f0 (the value at
argvals[0]). But build_augmented_srsfs encodes the curve level at the domain
MIDPOINT (m/2), so every generated curve was shifted by a constant equal to
its midpoint level (~+1 for the reporter's peak-1 bumps), and the sample mean
did not match the data mean.

Fix: reconstruct from a zero start, then shift the curve so its midpoint
equals the recovered level. Added a regression test asserting the sample-mean
offset from the data mean stays near zero (fails at the old ~+1.0).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sipemu
sipemu merged commit 6ed6239 into main Aug 7, 2026
8 checks passed
@sipemu
sipemu deleted the fix/gh-34-gauss-model-offset branch August 7, 2026 10:37
@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.02%. Comparing base (fca0a0e) to head (71ef10c).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #35   +/-   ##
=======================================
  Coverage   89.01%   89.02%           
=======================================
  Files         200      200           
  Lines       44099    44131   +32     
=======================================
+ Hits        39255    39287   +32     
  Misses       4844     4844           
Flag Coverage Δ
rust 89.02% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
fdars-core/src/alignment/generative.rs 87.03% <100.00%> (+1.59%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gauss_model: generated samples have a constant mean offset (~+1) from the input data

1 participant