Skip to content

[ENH] Add ShapeleterTransform and ShapeleterClassifier (#3888) - #3890

Open
shivamkumxr wants to merge 15 commits into
aeon-toolkit:mainfrom
shivamkumxr:enh-shapeleter-transform
Open

shivamkumxr wants to merge 15 commits into
aeon-toolkit:mainfrom
shivamkumxr:enh-shapeleter-transform

Conversation

@shivamkumxr

@shivamkumxr shivamkumxr commented Oct 6, 2026 •

Copy link
Copy Markdown

Reference Issues/PRs

Fixes #3888

What does this implement/fix? Explain your changes.

This PR implements the Shapeleter method following the phased roadmap proposed in #3888:

  1. ShapeleterTransformer (aeon/transformations/collection/shapelet_based/_shapeleter.py):

    • Uses RandomDilatedShapeletTransform as the candidate shapelet extraction backbone.
    • Implements multi-scale hypergraph pruning grouped by shapelet length, dilation, and normalization. Purity and Jaccard-based diversity filtering are implemented purely via NumPy and scipy.sparse incidence matrices (avoiding external graph libraries like hypergraphx).
    • Slices candidate subseries to actual shapelet lengths during distance calculations to handle variable length/inf padding cleanly.
    • Incorporates dual sinusoidal positional encodings (absolute positions and tie-aware ordinal ranks).
    • Fuses multi-view representations using paired Linear Discriminant Analysis (_CombinationFusion).
  2. ShapeleterClassifier (aeon/classification/shapelet_based/_shapeleter.py):

    • Combines ShapeleterTransformer with a pipeline of StandardScaler(with_mean=False) and RidgeClassifierCV.
    • Properly aligns with aeon estimator tags.
  3. Packaging & Testing:

    • Exported both classes in their respective package __init__.py files.
    • Added unit tests under aeon/transformations/collection/shapelet_based/tests/test_shapeleter.py and aeon/classification/shapelet_based/tests/test_shapeleter.py.
    • Verified estimator contract compliance with aeon.testing.estimator_checking.check_estimator (19/19 checks passed for transformer, 21/21 checks passed for classifier).

Does your contribution introduce a new dependency? If yes, which one?

No. The original implementation relied on PyTorch (for Adam scalar tuning) and hypergraphx. Both were eliminated in favor of existing core dependencies (numpy, scipy.sparse, and scikit-learn).

Any other comments?

Opened as a draft PR for initial maintainer review on class structure and integration.

PR checklist

For all contributions
  • I've added myself to the list of contributors. Alternatively, you can use the @all-contributors bot to do this for you after the PR has been merged.
  • The PR title starts with either [ENH], [MNT], [DOC], [BUG], [REF], [DEP] or [GOV] indicating whether the PR topic is related to enhancement, maintenance, documentation, bugs, refactoring, deprecation or governance.
For new estimators and functions
  • I've added the estimator/function to the online API documentation.
  • (OPTIONAL) I've added myself as a __maintainer__ at the top of relevant files and want to be contacted regarding its maintenance. Unmaintained files may be removed. This is for the full file, and you should not add yourself if you are just making minor changes or do not want to help maintain its contents.

@shivamkumxr shivamkumxr closed this Oct 6, 2026
@aeon-actions-bot aeon-actions-bot Bot added classification Classification package enhancement New feature, improvement request or other non-bug code enhancement transformations Transformations package labels Oct 6, 2026
@aeon-actions-bot

Copy link
Copy Markdown
Contributor

Thank you for contributing to aeon

I have added the following labels to this PR based on the title: enhancement.
I have added the following labels to this PR based on the changes made: classification transformations. Feel free to change these if they do not properly represent the PR.

The Checks tab will show the status of our automated tests. You can click on individual test runs in the tab or "Details" in the panel below to see more information if there is a failure.

If our pre-commit code quality check fails, please run pre-commit locally and push the fixes to your PR branch.

Don't hesitate to ask questions on the aeon Discord channel if you have any.

PR CI actions

These checkboxes will add labels to enable or disable CI functionality for this PR. This may not take effect immediately, and a new commit may be required to run the new configuration.

  • Run pre-commit checks for all files
  • Run mypy typecheck tests
  • Run all pytest tests and configurations
  • Run all notebook example tests
  • Run numba-disabled codecov tests
  • Disable numba cache loading
  • Regenerate expected results for testing
  • Push an empty commit to re-run CI checks

@shivamkumxr
shivamkumxr deleted the enh-shapeleter-transform branch October 6, 2026 12:09
@shivamkumxr
shivamkumxr restored the enh-shapeleter-transform branch October 6, 2026 12:16
@shivamkumxr shivamkumxr reopened this Oct 6, 2026
@baraline

baraline commented Oct 7, 2026

Copy link
Copy Markdown
Member

Hi, thanks for taking this. For this to go in, we are going to need a few things:

  • @CCHe64 review on the code, to confirm it conforms to his implementation
  • a benchmark against published results to validate we have the same level of performance.
  • Most of the computationally heavy code should be made as numba function, we may be able to re-use some of RDST functions for that ? To confirm.

@shivamkumxr

Copy link
Copy Markdown
Author

Hi @baraline, thank you for the feedback and review!

  1. Author Review: Looking forward to @CCHe64's review and feedback on the implementation and algorithmic parity.
  2. Benchmarking: I will run benchmarks on a few UCR benchmark datasets comparing against the published baseline results and share the accuracy comparison table here.
  3. Numba Acceleration: I will inspect the computational bottlenecks (especially around candidate subseries distances and hypergraph incidence computations) and look into reusing existing RDST Numba functions or adding dedicated @njit kernels.

I will work on the benchmark setup and profiling next.

@shivamkumxr

shivamkumxr commented Oct 7, 2026 •

Copy link
Copy Markdown
Author

Benchmark Parity & Numba Optimization Update

  1. Benchmark Parity Check:
    Evaluated ShapeleterClassifier(random_state=42) on standard baseline datasets:
Dataset Train Time Accuracy
UnitTest 4.19s 90.91%
ItalyPowerDemand 3.29s 93.97%
GunPoint 4.35s 100.00%

The classification accuracies match expected shapelet baseline performance (e.g. 100% on GunPoint, ~94% on ItalyPowerDemand).

  1. Numba Acceleration:
  • Pushed commit 85a26fa4e accelerating _assign_order with @njit(fastmath=True, cache=True) alongside a parallel batch kernel _assign_order_batch across cases.
  • Tested locally on feature matrices: reduced per-batch runtime from ~0.17s to ~0.0026s (~66x speedup) with 100% identical numerical output.
  • Next, checking the hypergraph pruning / Jaccard calculation and candidate distance routines to see where additional RDST compiled utilities can be directly reused.

@CCHe64

CCHe64 commented Oct 8, 2026

Copy link
Copy Markdown

I apologize for only seeing the message today.

@CCHe64

CCHe64 commented Oct 8, 2026

Copy link
Copy Markdown
  1. Is the name "ShapeleterTransformer" potentially ambiguous, given the immense renown of the "Transformer" architecture? Is it analogous to naming "RandomDilatedShapeletTransform" simply "ShapeleterTransform"?

@CCHe64

CCHe64 commented Oct 8, 2026

Copy link
Copy Markdown
  1. I agree with replacing the hypergraphx package with general-purpose functions like those in numpy. Fundamentally, it involves nothing more than set and matrix operations.

@CCHe64

CCHe64 commented Oct 8, 2026

Copy link
Copy Markdown
  1. The three existing examples demonstrate the consistency of the reproduction. If possible, could you conduct experiments using the standard splits of the 85 classic UCR datasets to make the results more convincing?

@CCHe64

CCHe64 commented Oct 8, 2026

Copy link
Copy Markdown
  1. I also recommend reusing RDST-related functions, if possible.

@shivamkumxr

Copy link
Copy Markdown
Author

Hi @CCHe64, thank you very much for reviewing the code and confirming the reproduction consistency!

Addressing your specific points:

  1. Naming (ShapeleterTransformer vs ShapeleterTransform):
    That is an excellent point regarding avoiding confusion with attention-based Transformers. In aeon, collection transformers generally follow the Transform suffix (e.g., RandomDilatedShapeletTransform, ShapeletTransform). I propose renaming ShapeleterTransformer to ShapeleterTransform (and keeping ShapeleterClassifier).
    @baraline @MatthewMiddlehurst - does ShapeleterTransform align with aeon's naming conventions for this PR?

  2. Hypergraph Pruning via NumPy/SciPy:
    Glad you agree! Formulating the hypergraph incidence and pruning via NumPy and sparse matrices keeps aeon lightweight with zero extra dependencies while retaining full parity.

  3. Benchmarking across 85 UCR Datasets:
    Running all 85 datasets sequentially on a local machine would take considerable time. As a practical first step, I can evaluate a diverse subset of 10–12 representative UCR datasets across various domains and lengths (e.g., Coffee, ECGFiveDays, Trace, ArrowHead, Plane, SonyAIBORobotSurface1, Beef, OliveOil) and compare test accuracy directly against your published results.
    If aeon has internal cluster benchmarking scripts or runners available for full-suite verification, I would also be happy to configure the run.

  4. RDST Function Reuse:
    Agreed. Following the _assign_order Numba batch acceleration (commit 85a26fa4e), I am inspecting how candidate extraction and distance calculations can directly reuse RDST's compiled Numba routines (compute_shapelet_features / dilated_shapelet_transform) to avoid code duplication and maximize runtime speed.

@CCHe64

CCHe64 commented Oct 8, 2026

Copy link
Copy Markdown

It is feasible to start with a small-scale UCR setup. It is recommended to run the experiments on the full set of 85 UCR datasets only after all code improvements have been completed. @shivamkumxr @baraline

@shivamkumxr

Copy link
Copy Markdown
Author

Hi @CCHe64 and @baraline,

Thank you for the guidance and feedback! Here are the updates and benchmark numbers:

1. Multi-Dataset Benchmark Validation (Representative 10-Dataset UCR Subset)

Following the small-scale benchmark suggestion, I evaluated standard train/test splits across 10 diverse UCR datasets using ShapeleterClassifier(random_state=42):

Dataset Train Time Test Accuracy
UnitTest ~17s 90.91%
ItalyPowerDemand ~7.8s 93.97%
GunPoint ~7.0s 100.00%
ArrowHead ~8.0s 86.29%
Coffee ~7.2s 100.00%
BeetleFly ~11.1s 95.00%
BirdChicken ~7.5s 90.00%
Plane ~8.0s 100.00%
Trace ~8.0s 100.00%
Beef ~7.4s 86.67%

The results show strong consistency with reported reproduction baselines (achieving 100% on GunPoint, Coffee, Plane, and Trace, and 90%+ across most remaining benchmarks). We can run the full 85-dataset suite once all refactorings are finalized.

2. Recent Fixes & Optimizations

  • Numba parallel rank ordering: In commit 85a26fa4e, _assign_order was replaced with a parallel @njit batch kernel (_assign_order_batch), achieving an ~66x speedup on position ordering.
  • Robust LDA projection guard: In commit 53d1cb0, added an output shape check (trans.shape[1] == 1) in _CombinationFusion to prevent broadcast dimension mismatches when collinear or constant positional encodings cause LDA to drop components (which resolved the failure observed on Coffee).

3. Next Steps

  1. Awaiting core maintainer confirmation on renaming ShapeleterTransformer -> ShapeleterTransform.
  2. Inspecting candidate extraction and subseries distance routines to reuse RDST's compiled Numba kernels (compute_shapelet_features / dilated_shapelet_transform).

@baraline

baraline commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Yes, please follow any naming convention already in place in the package.

As most of this seems AI generated (which I have no issue with if you understand what you are doing), I'll expect an in depth review and benchmark once the code is in a stable state to compare on the full UCR. I'll use my own computing resources to run that and compare against @CCHe64 results.

This is going to take a bit of time to review and benchmark, so no rush !

@shivamkumxr shivamkumxr changed the title [ENH] Add ShapeleterTransformer and ShapeleterClassifier (#3888) [ENH] Add ShapeleterTransform and ShapeleterClassifier (#3888) Oct 8, 2026
@shivamkumxr

Copy link
Copy Markdown
Author

Hi @baraline and @CCHe64,

Quick update:

  • Renamed ShapeleterTransformer to ShapeleterTransform across code, tests, and API docs to follow aeon naming conventions.
  • Kept the alias in the module for backward compatibility, but excluded it from __all__ to keep all_estimators discovery and doc tests clean.
  • All CI checks (18/18) are green across all OS environments and Python 3.12–3.14.

Code is stable and ready for your review and the full UCR benchmark whenever you have time!

This branch has not been deployed

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

Labels

classification Classification package enhancement New feature, improvement request or other non-bug code enhancement transformations Transformations package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH] Add Shapeleter transform + classifier

3 participants