Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Added IDK² and s-IDK² Anomaly Detector To Aeon #2465

Open
wants to merge 51 commits into
base: main
Choose a base branch
from

Conversation

Ramana-Raja
Copy link

closes #2114

@aeon-actions-bot
Copy link
Contributor

Thank you for contributing to aeon

I did not find any labels to add based on the title. Please add the [ENH], [MNT], [BUG], [DOC], [REF], [DEP] and/or [GOV] tags to your pull requests titles. For now you can add the labels manually.
I have added the following labels to this PR based on the changes made: [ $\color{#6F6E8D}{\textsf{anomaly detection}}$ ]. 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, any trivial fixes will automatically be pushed to your PR unless it is a draft.

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

PR CI actions

These checkboxes will add labels to enable/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
  • Stop automatic pre-commit fixes (always disabled for drafts)
  • Disable numba cache loading
  • Push an empty commit to re-run CI checks

@Ramana-Raja Ramana-Raja changed the title Added IDK² and s-IDK² Anomaly Detector To Aeon [ENH]Added IDK² and s-IDK² Anomaly Detector To Aeon Dec 19, 2024
@Ramana-Raja Ramana-Raja changed the title [ENH]Added IDK² and s-IDK² Anomaly Detector To Aeon [ENH] Added IDK² and s-IDK² Anomaly Detector To Aeon Dec 19, 2024
@MatthewMiddlehurst MatthewMiddlehurst added the enhancement New feature, improvement request or other non-bug code enhancement label Dec 19, 2024
Copy link
Member

@SebastianSchmidl SebastianSchmidl left a comment

Choose a reason for hiding this comment

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

I just had a very brief look at the code because I am short on time. I will have another look next year after the Christmas break. Meanwhile, the code quality can be improved and tests need to be added.

  • The tests are missing! Please add reasonable tests for the new algorithm. How do you make sure that it produces the same results as the original implementation?
  • The code mixes standard python (e.g. random, range, ...) with numpy (e.g. np.random, np.arange, ...). Please mostly rely on numpy for better code quality and performance.
  • Why are most methods in capital letters and start with dunders (__)? If this is a reference to the original implementation, please add the original name as a comment and use our coding standard.

Thank you for taking the time and contributing to aeon!

aeon/anomaly_detection/_idk.py Outdated Show resolved Hide resolved
aeon/anomaly_detection/_idk.py Outdated Show resolved Hide resolved
aeon/anomaly_detection/_idk.py Outdated Show resolved Hide resolved
@Ramana-Raja
Copy link
Author

Ramana-Raja commented Jan 5, 2025

I just had a very brief look at the code because I am short on time. I will have another look next year after the Christmas break. Meanwhile, the code quality can be improved and tests need to be added.

  • The tests are missing! Please add reasonable tests for the new algorithm. How do you make sure that it produces the same results as the original implementation?
  • The code mixes standard python (e.g. random, range, ...) with numpy (e.g. np.random, np.arange, ...). Please mostly rely on numpy for better code quality and performance.
  • Why are most methods in capital letters and start with dunders (__)? If this is a reference to the original implementation, please add the original name as a comment and use our coding standard.

Thank you for taking the time and contributing to aeon!

Hello, I recently added a test case, but it seems to be causing errors. The test case runs successfully in my local environment, so I'm unsure why the issue arises. Could you assist me in identifying the cause?

aeon/anomaly_detection/_idk.py Outdated Show resolved Hide resolved
aeon/anomaly_detection/_idk.py Outdated Show resolved Hide resolved
aeon/anomaly_detection/_idk.py Outdated Show resolved Hide resolved
aeon/anomaly_detection/_idk.py Outdated Show resolved Hide resolved
from aeon.anomaly_detection import IDK


def test_idk_univariate():
Copy link
Member

Choose a reason for hiding this comment

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

We want to make sure that our implementation is correct. Can you add tests that compare your implementation to the original authors' one?

You already linked to the reference implementation: https://github.com/IsolationKernel/Codes/tree/main/IDK/TS
You can execute the reference implementation on some sample data and store the results. Then, you could test this implementation on the same input data to produce the same results up to a certain precision.

Copy link
Author

Choose a reason for hiding this comment

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

Added new case for this.

Copy link
Member

Choose a reason for hiding this comment

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

Please put the test case in a new function.

Copy link
Author

Choose a reason for hiding this comment

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

Done

aeon/anomaly_detection/_idk.py Outdated Show resolved Hide resolved
aeon/anomaly_detection/_idk.py Outdated Show resolved Hide resolved
aeon/anomaly_detection/_idk.py Outdated Show resolved Hide resolved
assert pred.shape == (100,)
assert pred.dtype == np.float64
assert 50 <= np.argmax(pred) <= 58
assert pred_sliding.shape == (91,)
Copy link
Member

Choose a reason for hiding this comment

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

The result should have the same shape as the input in both cases!

Copy link
Author

Choose a reason for hiding this comment

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

The width parameter changes the way the model generates its output, since its 10 the output length 91(91 windows - each size of 10)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I get that, but there must be a way to calculate, which points of the original time series contributed to the score at a certain position. All existing aeon anomaly detectors adhere to this contract.

In the other ADs of this module that use sliding windows, we use aeon.utils.windowing.reverse_windowing to attribute the anomaly score to the original points of the time series. For IDK, I guess this does not work, but maybe for IDK². We need to figure out a way to do this for IDK and IDK² even if it is not part of the original code.

Copy link
Author

@Ramana-Raja Ramana-Raja Jan 17, 2025

Choose a reason for hiding this comment

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

I utilized the aeon.utils.windowing.reverse_windowing function to ensure the output shape aligns with the input shape when sliding is enabled. Could you please review it to confirm that my implementation is correct?

Copy link
Member

@SebastianSchmidl SebastianSchmidl left a comment

Choose a reason for hiding this comment

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

The testing is still too weak.
TBH, I cannot follow the details of the code, so I think that we need a second person to check whether this implementation produces the same results as the implementation by the original authors of IDK.

aeon/anomaly_detection/_idk.py Outdated Show resolved Hide resolved
assert pred.shape == (100,)
assert pred.dtype == np.float64
assert 50 <= np.argmax(pred) <= 58
assert pred_sliding.shape == (91,)
Copy link
Member

Choose a reason for hiding this comment

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

Yes, I get that, but there must be a way to calculate, which points of the original time series contributed to the score at a certain position. All existing aeon anomaly detectors adhere to this contract.

In the other ADs of this module that use sliding windows, we use aeon.utils.windowing.reverse_windowing to attribute the anomaly score to the original points of the time series. For IDK, I guess this does not work, but maybe for IDK². We need to figure out a way to do this for IDK and IDK² even if it is not part of the original code.

aeon/anomaly_detection/tests/test_idk.py Outdated Show resolved Hide resolved
from aeon.anomaly_detection import IDK


def test_idk_univariate():
Copy link
Member

Choose a reason for hiding this comment

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

Please put the test case in a new function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
anomaly detection Anomaly detection package enhancement New feature, improvement request or other non-bug code enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ENH] Implement (s-)IDK² anomaly detector
3 participants