Skip to content

[BUG] Normalize multichannel shapelet distance plots - #4022

Open
austinchennn wants to merge 1 commit into
aeon-toolkit:mainfrom
austinchennn:fix/multivariate-shapelet-distance-20261115
Open

austinchennn wants to merge 1 commit into
aeon-toolkit:mainfrom
austinchennn:fix/multivariate-shapelet-distance-20261115

Conversation

@austinchennn

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Addresses the normalization/broadcasting error reported in #3028. The broader shapelet interpretation/documentation questions in that issue remain open.

What does this implement/fix? Explain your changes.

ShapeletVisualizer.plot_distance_vector accepts channel-by-time arrays but drops the channel axis when computing the shapelet's mean and standard deviation. For a normalized two-channel, four-point shapelet it raises a broadcasting error. When the channel count equals the shapelet length, broadcasting instead succeeds along the wrong axis and the plotted distances are incorrect.

Keep the reduced time axis in both statistics, matching the per-channel normalization already used by plot_on_X. The subsequence/distance helpers and classifier visualizer's explicit univariate restriction are unchanged.

Add numerical regression coverage for one, two and four channels; normalized and raw distances; and newly created figures versus supplied axes. The reference distances use independent row-wise normalization and NumPy norms of dilated windows, and validate the actual plotted line rather than only the return type.

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

No. Matplotlib remains the existing optional plotting dependency; the tests follow the module's Agg backend and optional-dependency guard.

Any other comments?

Validation on macOS arm64, Python 3.11.15:

  • On the original source, the new cases give 4 failed, 8 passed: the unequal channel/length cases raise, and the square cases produce wrong distances. Raw/univariate controls pass.
  • After the fix, the complete shapelet plotting module gives 26 passed, 4 warnings.
  • All applicable configured pre-commit checks and git diff --check pass.
  • No full aeon suite, physical GPU execution or cross-platform local run is claimed.

I checked all 86 open PR file lists. #3842 touches the same production module only to relocate helper imports; it does not change this normalization or test file.

PR checklist

For all contributions
  • I've added myself to the list of contributors. I will use the contributor bot after merge, as the template permits.
  • The PR title starts with [BUG].

This pull request includes code written with the assistance of AI.
The code has not yet been reviewed by a human.

@aeon-actions-bot aeon-actions-bot Bot added bug Something isn't working visualisation Visualisation package labels Nov 15, 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: bug.
I have added the following labels to this PR based on the changes made: visualisation. 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

@austinchennn

Copy link
Copy Markdown
Contributor Author

CI note for the current head e89bf1b: the Ubuntu/Python 3.13 job 132747774575 failed in the swap-space setup step with fallocate: fallocate failed: No space left on device, before pytest ran. The replacement pre-commit run and multiple other matrix jobs have passed; some jobs are still running. Local plotting tests remain 26 passed. Could a maintainer rerun the failed infrastructure job when appropriate? I have left the source unchanged because this log does not indicate a code/test failure.

@baraline

Copy link
Copy Markdown
Member

Hey, thanks for looking into this, could you provide some example plots so we can visualize the changes on the output ?

From memory at the time of the original issue the multivariate plots were messy and not very informative, would just like to see how the PR improves on this with the new normalization you introduce.

@austinchennn

Copy link
Copy Markdown
Contributor Author

Thanks for taking a look! I'll add example plots here — a two-channel, four-point shapelet case (where the old code raised the broadcasting error) and a square case where channels == shapelet length (where it silently plotted wrong distances), plus the univariate control for comparison. Give me a bit to generate them and I'll post them on this PR.

@austinchennn

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Here are actual before/after calls to ShapeletVisualizer.plot_distance_vector, using baseline 776b887 and PR head e89bf1b. These synthetic cases isolate the normalization defect; they are not evidence that all multivariate visualizations become more informative.

  • 2 channels x 4 values: the old method raises a broadcasting ValueError before plotting. The patched method plots the distance vector.
  • 4 channels x 4 values: broadcasting succeeds on the old method but normalizes along the wrong axis. At the deliberately inserted scaled/offset match (window start 1), the old distance is 6.072625185, while the corrected per-channel distance is effectively zero (3.82e-15). Patched output matches an independent row-wise NumPy normalization/window-distance oracle to maximum absolute error 2.23e-15.

Both cases use RandomState(42), length4, dilation2, and a channel-wise scaled/offset copy inserted at X[:, 1:9:2]. Plot panels share the same distance scale in the 4-channel comparison. Blue is the actual public plotting method output; dashed orange is the independent oracle.

2 channels before/after
4 channels before/after

Exact numeric results. Reproduction data for either channel count:

rng = np.random.RandomState(42)
values = rng.normal(size=(n_channels, 4))
X = rng.normal(size=(n_channels, 10))
X[:, 1:9:2] = values * (np.arange(1, n_channels + 1)[:, None] + 1) + (np.arange(n_channels)[:, None] + 3)
ShapeletVisualizer(values, normalise=True, dilation=2).plot_distance_vector(X, show_legend=False, show_threshold=False)

This remains a narrow runtime fix for ShapeletVisualizer; the classifier visualizer's intentional univariate restriction is unchanged. Broader interpretability/layout concerns from #3028 remain open. The implementation branch is unchanged; these images/results are on a separate contributor evidence branch. AI-assisted code and evidence, not yet independently human-reviewed.

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

bug Something isn't working visualisation Visualisation package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants