[ENH] Skip redundant per-slice input validation in interval feature extraction - #3665
[ENH] Skip redundant per-slice input validation in interval feature extraction#3665TonyBagnall wants to merge 5 commits into
Conversation
Thank you for contributing to
|
|
as an extension, I looked if this slow pattern was repeated elswhere. tl;dr: there are small further gains for interval based, possible larger gains for dictionary based. Might be worth a follow up PR, especially for WEASEL and MUSE, but requires further investigation, I'll make two issues later.
|
|
further exploring, number of calls
|
MatthewMiddlehurst
left a comment
There was a problem hiding this comment.
Looks fine, but is there a need to do it differently got both transforms? I would other go with the inline or function for both if possible.
yes fair enough, Ive gone with functions rather than inlining and generalised to a shared helpers, _fit_feature, One thing worth flagging, since a shared helper would otherwise have quietly decided it: the two transforms already differed in how they call a feature that isn't a collection transformer. RandomIntervals passes the expanded 3D slice and y; SupervisedIntervals passes the 2D slice and no y. That predates this PR — both did it before I touched them. I've preserved both exactly via an expand_fallback argument rather than silently unifying them, since that would be a behaviour change on a path this PR isn't otherwise about. Output is unchanged: my bot diffed 36 output arrays across both transforms plus DrCIF and RSTSF — univariate and multivariate, n_jobs 1 and 2, callable and transformer features, dilation, normalise_for_search=False — against the previous commit, and they're bit-identical. |
closes #3599
This came about because of a test for flat series triggering multiple warnings in DrCIF.
This lead us to look at RandomIntervals and SupervisedIntervals. These extract features on interval slices of data already validated at the top-level fit. They called the features public fit_transform/transform, paying a full _check_X (missing-value and variance scans) on every slice - thousands of times per DrCIF fit/predict.
Had to adjust SupervisedIntervals to stick with Numpy 3D. Then its simply a matter of using the private _fit_transform/_transform functions which assume pre-validated inner-type input, eliminating the per-slice checks. SupervisedIntervals expands its 2D per-channel slices to the numpy3D inner type first. Non-collection transformer features keep the public path. Neither RandomIntervals and SupervisedIntervals can work with unequal length, so will always deal correctly with numpy3D.
Output is bit-identical (DrCIF, RSTSF, SupervisedIntervals) and n_jobs invariant is preserved.
As well as removing annoying warnings, the real pay off is the speed up. DrCIF is 12% faster fit and 18% predict. to 1.2, supervised is about 3x faster when a transformer feature is used. The DrCIF gain scales with the validation share: more channels or longer series means more/larger slices thus larger gain; this univariate case is a conservative point. Multivariate DrCIF would benefit more.
Now off to look to see if this happens elsewhere