feat(num_feat): add NumericalFeature.feature_matrix (#337)#347
Draft
breimanntools wants to merge 1 commit into
Draft
feat(num_feat): add NumericalFeature.feature_matrix (#337)#347breimanntools wants to merge 1 commit into
breimanntools wants to merge 1 commit into
Conversation
Add NumericalFeature.feature_matrix(features, dict_num_parts, df_scales=..., n_jobs=1), the numerical analog of SequenceFeature.feature_matrix: it turns CPP.run_num-selected features back into a model matrix X while preserving the per-residue context that per-AA-averaged sequence features discard. Values are reconstructed exactly the way CPP.run_num does — the SPLIT in each feature id is re-applied to the part's 0-based residue axis (arange(L_part)), the SCALE selects the D column, and the selected residues are nanmean-averaged (round 5). The df_feat 'positions' column is a JMD-offset display numbering (e.g. 21..30 for a TMD), NOT a tensor index, so it is deliberately not used for value lookup; this is documented in the method Notes. Output is byte-identical to run_num's recompute_feature_matrix (verified for uniform and variable-length parts). Per-part real lengths are inferred from the NaN padding get_parts emits. Heavy lifting lives in NumericalFeature's own _backend/num_feat/feature_matrix.py (reusing the shared cpp split/parse helpers). Ripple: numpydoc docstring with named Returns / Raises / Examples include; executed examples notebook nf_feature_matrix.ipynb (every public parameter, display_df tables); 27 unit tests (per-parameter positive+negative, golden hand-computed means, run_num consistency, ragged parts); release-notes Unreleased entry. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
840b3af to
a2d28f9
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #347 +/- ##
========================================
Coverage 94.83% 94.83%
========================================
Files 196 197 +1
Lines 18767 18870 +103
Branches 3175 3196 +21
========================================
+ Hits 17797 17895 +98
- Misses 633 637 +4
- Partials 337 338 +1
... and 9 files with indirect coverage changes
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #337.
Summary
Adds
NumericalFeature.feature_matrix(features, dict_num_parts, df_scales=..., n_jobs=1), thenumerical analog of
SequenceFeature.feature_matrix: it turnsCPP.run_num-selected features backinto a model matrix
X, preserving the per-residue context that per-AA-averaged sequence featuresdiscard.
Details
CPP.run_numdoes — the SPLIT in each feature id isre-applied to the part's 0-based residue axis (
arange(L_part)), the SCALE selects the column, andthe selected residues are nanmean-averaged (round 5).
df_featpositionscolumn is a JMD-offset display numbering (e.g. 21..30 for a TMD), not atensor index, so it is deliberately not used for value lookup (documented in the method Notes).
Output is byte-identical to
run_num'srecompute_feature_matrix(verified for uniform andvariable-length parts); per-part real lengths are inferred from the NaN padding
get_partsemits.NumericalFeature's own_backend/num_feat/feature_matrix.py(reusing theshared CPP split/parse helpers).
@staticmethod, consistent with the class.__init__.pychange (method on an already-exported class).Ripple
examples/nf_feature_matrix.ipynb(every public parameter,display_dftables)run_numconsistency, ragged parts)Part of epic #336.
🤖 Generated with Claude Code