Skip to content

[BUG] Initialise ERP boundary with cumulative gap cost - #4036

Open
sohailshk wants to merge 3 commits into
aeon-toolkit:mainfrom
sohailshk:fix/erp-boundary-cumsum
Open

sohailshk wants to merge 3 commits into
aeon-toolkit:mainfrom
sohailshk:fix/erp-boundary-cumsum

Conversation

@sohailshk

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Fixes #4003

What does this implement/fix? Explain your changes.

The first row and column of the ERP cost matrix held the total of |x_k - g| over the whole series. In ERP (Chen and Ng, 2004) D[i, 0] is the cost of deleting the first i points, i.e. the cumulative sum. Alignments that start with a run of gaps were over-charged, so erp_distance, erp_pairwise_distance, erp_cost_matrix and erp_alignment_path disagreed with the recursive definition (103 of 200 random pairs in the new test) and the triangle inequality failed.

The boundary now uses the cumulative sum in the cost matrix and in both rolling-row versions. test_erp.py gains a comparison against the recursive definition (univariate, multichannel, array g) and the example from the issue. The expected ERP values in test_distance_correctness.py change (102.0979 becomes 101.448661 for two of the three entries).

Run on current main, pytest aeon/distances/elastic/tests/test_erp.py aeon/distances/elastic/tests/test_distance_correctness.py -k erp: 2 failed without the change, 18 passed with it.

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

No.

The implementation and tests were written with AI assistance.

The first row and column of the ERP cost matrix held the total distance to g of the whole series instead of the cumulative cost of the leading points, so aligning after a prefix of gaps was over-charged and results disagreed with the recursive ERP definition (103 of 200 random pairs).
@aeon-actions-bot aeon-actions-bot Bot added bug Something isn't working distances Distances package labels Nov 20, 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: distances. 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

@TonyBagnall TonyBagnall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good find, @sohailshk this must have been here for a long time! You will have to rebase #4037 after this goes in

@TonyBagnall
TonyBagnall self-requested a review November 28, 2026 21:13
@sohailshk

Copy link
Copy Markdown
Contributor Author

The failing checks are limited to Windows 3.11 and 3.13.
The ERP tests fail with the pre-fix behaviour. For example, test_erp_matches_definition returns 3.0 instead of 0.0.
The same code passes on Linux, macOS and Windows 3.15 in the same CI run.
Possible cause
A stale Numba cache on Windows is a likely explanation, although this is not confirmed. The CI cache loader splits paths using /, and I didn't have access to a Windows machine to investigate further.
Could a maintainer re-run these jobs with the no numba cache label, or simply re-run the failed jobs?

@TonyBagnall

Copy link
Copy Markdown
Contributor

The failing checks are limited to Windows 3.11 and 3.13. The ERP tests fail with the pre-fix behaviour. For example, test_erp_matches_definition returns 3.0 instead of 0.0. The same code passes on Linux, macOS and Windows 3.15 in the same CI run. Possible cause A stale Numba cache on Windows is a likely explanation, although this is not confirmed. The CI cache loader splits paths using /, and I didn't have access to a Windows machine to investigate further. Could a maintainer re-run these jobs with the no numba cache label, or simply re-run the failed jobs?

yeah made an issue for it #4056

@TonyBagnall

Copy link
Copy Markdown
Contributor

need to tresolve the conflict though

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 distances Distances package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ERP initialises the first row and column with the total gap cost instead of the cumulative one

2 participants