fix(lda): address review follow-ups from #456 - #457
Conversation
- Singularity threshold: T::epsilon() → relative tolerance (1e-4 * l_max), matching sklearn - PartialEq: T::epsilon() → fixed 1e-10 tolerance for float comparison - Rename field scalings → projection_matrix to avoid shadowing the public getter - Add missing test coverage: X/y mismatch, zero n_components, wrong transform features - Remove polyfill.io script tag (supply-chain concerns) - Add blank line between lda and pca module declarations in mod.rs - Bump version to 0.6.14 and move CHANGELOG entry accordingly
|
Great follow-up PR — the review comments from #456 are addressed cleanly and consistently. Here are my observations, a mix of approvals and a few minor suggestions. ✅ What looks goodSingularity threshold (
Field rename
New tests 🔍 Minor observations / suggestions1. let tol = T::from(1e-10).unwrap();This is fine for let tol = T::from(1e-6).unwrap(); // safe floor for both f32 and f64Alternatively, document that 2. let l_max = l.iter().cloned().fold(T::zero(), |a, b| if b > a { b } else { a });Functionally correct. One note: if all eigenvalues of 3. CHANGELOG version bump ordering The PR moves the LDA entry from SummaryThe core fixes (singularity guard, |
1e-10 rounds to 0.0 in f32 (min positive normal ~1.2e-7), making (a - b).abs() > 0.0 almost always true for distinct values. The 1e-6 floor works correctly for both f32 and f64. Addresses review feedback on #457.
Addresses all review comments from #456:
Bug fixes:
T::epsilon()(~2.2e-16) with a relative tolerance (1e-4 * l_max), matching sklearn's approach. Near-singular Sw matrices no longer pass the guard and produce garbage whitening.PartialEq: replacedT::epsilon()with a fixed1e-10tolerance for float comparison.Refactoring:
scalings→projection_matrixto avoid shadowing the publicscalings()getter (consistent with PCA'scomponentsnaming).Test coverage (33 previously uncovered lines):
mismatched_x_y_is_rejected— X/y dimension mismatchzero_n_components_is_rejected— n_components < 1 validationtransform_wrong_features_is_rejected— wrong feature count on transformCleanup:
polyfill.ioscript tag (supply-chain concerns, inconsistent with PCA module)pub mod ldaandpub mod pcainmod.rs0.6.14and moved CHANGELOG entry from[0.6.13]to[0.6.14]