Repository navigation
[ENH] Port Catch22 to the catch22 v1.0 feature definitions - #4052
MatthewMiddlehurst wants to merge 17 commits into
Conversation
feature_names_short mapped SP_Summaries_welch_rect_area_5_1 to centroid_freq and SP_Summaries_welch_rect_centroid to low_freq_power, the reverse of catch22's featureList.txt. Selecting either feature by short name returned the other one. The pycatch22 reference test listed low_freq_power, which under the old mapping checked the centroid feature; it now lists centroid_freq so it keeps checking the same feature.
catch22 v0.6.0 corrected four features whose C implementations differed from their hctsa definitions, and aeon's numba Catch22 reproduced the old C behaviour: - PD_PeriodicityWang_th0_01 and IN_AutoMutualInfoStats_40_gaussian_fmmi returned the lag minus one; they now return the lag. - SB_BinaryStats_mean_longstretch1 ignored the last point and counted runs not at the start one too long; it now returns the exact longest run. - SB_BinaryStats_diff_longstretch0 counted runs not at the start one too long and treated zero differences as increases; it now returns the exact longest run of non-increasing steps. Values of these features change. Regenerate the stored basic-motions arrays (only the four feature columns), the clustering test labels and two docstring examples, and require pycatch22>=0.6.0 so the reference comparisons use the corrected C code.
# Conflicts: # pyproject.toml
# Conflicts: # aeon/transformations/collection/feature_based/tests/test_catch22.py # pyproject.toml
# Conflicts: # aeon/transformations/collection/feature_based/tests/test_catch22.py # aeon/transformations/collection/feature_based/tests/test_catch22_optimisations.py
Parametrise the short-name selection test over all 22 catch22 short/full name pairs, written out from catch22's feature list rather than taken from the module, so a mismatch in the module's lists is caught.
catch22 v1.0 re-implements its features to reproduce their hctsa v3.0.0 definitions exactly. Port every kernel to the catch22 v1.2.0 C code, keeping aeon's feature order, batched FFT and autocorrelation caches and compiled dispatch: - histogram mode and ami2: hctsa bin edges and histcounts binning; ami2 adds the Panzeri-Treves bias correction - acf_timescale: interpolated crossing within the series' lags, n - 1 when none - low_freq_power and median_freq (replacing centroid_freq): the fft periodogram with a 1e-12 floor - whiten_timescale: interpolated zero crossings of both autocorrelations - entropy_pairs: Miller-Madow bias correction - transition_variance: tau from the first negative autocorrelation, with anti-aliased resampling of the mean-centred series - embedding_dist: hctsa's automatic binning and density normalisation - rs_range and dfa: hctsa's two-regime fit and minimum lengths - outlier timing: hctsa's trimming, and outlier_norm z-normalises with the sample standard deviation as catch22 - forecast_error, ami_timescale, trev, pnn40: catch22's guards for short series Features that cannot be estimated (e.g. any feature of a constant series) are masked to catch22's values unless mask_nans=False. Feature names follow catch22 v1.0; the v0.x names still select the same positions with a deprecation warning. catch24's standard deviation is the sample standard deviation, as in catch22. On z-normalised series every feature matches pycatch22 1.0.2 to 1e-6, except for rounding-level ties on degenerate series. A test compares against stored pycatch22 1.0.2 values. Kernels that can return NaN are compiled without fastmath, which makes the transform about 1.4x slower than before.
Regenerate the stored results that change with the new Catch22 features: Catch22Classifier, CanonicalIntervalForestClassifier, DrCIFClassifier and RISTClassifier on both datasets, and Catch22Regressor on CardanoSentiment. Generated on Linux (Python 3.12, CI's numba CPU settings) with the expected-results writer's data and parameters, in an environment where main's stored results all reproduce.
The classifier, regressor and clusterer docstrings still listed the catch22 v0.x feature names. Also rename the FFT cache from welch to spectrum, since the spectral features now use the fft periodogram.
…zero z_normalise_series, z_normalise_series_with_mean, z_normalise_series_2d and z_normalise_series_3d handle the two cases where the mean and standard deviation they compute are wrong: - beyond about 1e154 the sum of squares overflowed and every value came out 0; such series are now scaled by a power of two first; - when the standard deviation is within rounding of the mean, the mean's rounding error could exceed the series' variation, so a constant series far from zero normalised to ones and near-constant residuals were not centred; such series are now centred a second time, and constant series give zeros. Ordinary series take the same arithmetic as before.
- Use numba's fastmath without its no-NaN and no-inf assumptions, index slices in loops over offset windows, and build transition_variance's low-pass filters once per downsampling factor for a batch. - Add normalise, which z-normalises each series with the numba z-normalisation before computing the features, as catch22 recommends. outlier_norm uses the same function. Catch22Classifier, Catch22Regressor and Catch22Clusterer pass normalise through. - Scale each series by a power of two before the autocorrelation, so its sums of products do not under- or overflow at scales around 1e±200. - Return 0 for periodicity on series of length 2. - Regenerate the expected results that change. - Move the useful tests of test_catch22_optimisations.py into test_catch22.py and drop the ones of internals.
Revert "[BUG] Fix the numba z-normalisation for overflow and series far from zero" (7032a1d), which is fixed separately with Normalizer. Catch22 keeps its own copy of _pow2_scale for the autocorrelation, and the normalise scale-invariance test only checks ordinary scales.
|
Notebooks changed:
Review visual diffs and comment on any notebook cell. All comments sync back to this PR. Powered by ReviewNB |
Thank you for contributing to
|
What does this implement/fix? Explain your changes.
catch22 v1.0 re-implements every feature so that it reproduces its hctsa v3.0.0 definition exactly, and freezes the definitions there. pycatch22 1.0 ships it. aeon's numba
Catch22reproduced catch22 v0.5, including its off-by-one bugs, which catch22 v0.6.0 fixed. This PR ports every kernel to the catch22 v1.2.0 C code as one change, rather than moving to v0.6.0 first and then changing values again.aeon's structure is kept: the feature order, the batched FFT and autocorrelation caches, and the compiled dispatch loop.
Changes by feature:
mode_5,mode_10,ami2: hctsa's bin edges and histcounts binning.ami2adds the Panzeri-Treves bias correction.acf_timescale: interpolated crossing within the series' lags, and n − 1 when there is none.low_freq_power,median_freq: the fft periodogram.median_freq(SP_Summaries_fft_wq_50) replacescentroid_freq, as in catch22.whiten_timescale: interpolated zero crossings of both autocorrelations.entropy_pairs: Miller-Madow bias correction.transition_variance: tau from the first negative autocorrelation, and anti-aliased resampling.embedding_dist: hctsa's automatic binning and density normalisation.rs_range,dfa: hctsa's two-regime fit and minimum lengths.periodicity,ami_timescale,stretch_high,stretch_decreasing: the catch22 v0.6.0 corrections.API:
dfaon a series shorter than 79 values.mask_nans=Falsereturns NaN instead.CO_FirstCrossing_acf_1e_pointOfCrossingandtransition_variance. The v0.x names still select the same positions, with a FutureWarning, and are removed in v1.8.0. This also fixes aeon's swappedlow_freq_power/centroid_freqshort names.mean/stdare accepted as names.normalise=Falseoption z-normalises each series with aeon's numba z-normalisation (z_normalise_series_3d) before computing the features, as catch22 recommends.outlier_normuses the same function, as it did before, so the outlier features are the same with either option. aeon divides by the population standard deviation where catch22 uses the sample standard deviation, so the scale-dependent features differ slightly from catch22's on short series. Catch22Classifier, Catch22Regressor and Catch22Clusterer passnormalisethrough. catch24's mean and standard deviation stay those of the series as given. aeon's z-normalisation is wrong beyond about 1e154 and for constant series far from zero; that will be fixed in a separate PR.acf_timescaleraised a ZeroDivisionError.periodicityno longer fails on series of length 2.Values change for most features, so outputs change for every estimator built on Catch22: Catch22Classifier, Catch22Regressor, Catch22Clusterer, CanonicalIntervalForest, DrCIF, RIST, and HIVECOTEV2 through DrCIF.
Validation:
outlier_norm=False(the series are already normalised as catch22 does). The exceptions are 4 rounding-level ties on degenerate series: twostretch_highties at the mean on short ramps, and twowhiten_timescalevalues from near-constant residuals.normalise, and the autocorrelation features at extreme scales.Does your contribution introduce a new dependency? If yes, which one?
No.
Any other comments?
transition_variance's low-pass filter is built once per downsampling factor for a batch, rather than for every series.embedding_distis still about 1.4× slower: hctsa's automatic binning sorts the distances.outlier_norm, so existing pipelines keep their behaviour. catch22 defines every feature on z-normalised series.transition_varianceresamples the mean-centred series to stay offset-invariant; this is identical on z-normalised input.mode_5,mode_10,trev,high_fluctuation,periodicity,embedding_dist,low_freq_powerandforecast_error. Withnormalise=True, they differ only through the ratio of the two standard deviations, √(n/(n−1)): by 2.5% at length 20 and 0.13% at 400 for the features linear in scale, and 2–3 times that fortrevandlow_freq_power.high_fluctuationandperiodicitycompare against fixed thresholds, so they change on a few percent of series.normalise=Truethe default, here or in the interval forests, needs an accuracy comparison first.test_catch22_optimisations.pyis removed. Its checks that single features, channels, unequal-length input and_transform_featuresmasking agree with the full transform are now intest_catch22.py; its checks of the internal caches are dropped.PR checklist
For all contributions