TimeEval / GutenTAG

GutenTAG is an extensible tool to generate time series datasets with and without anomalies; integrated with TimeEval.
MIT License
71 stars 13 forks source link

Amplitude anomaly fails with `amplitude_bell` size offset #49

Closed arrrrrmin closed 6 months ago

arrrrrmin commented 6 months ago

Hi there 👋

first of all, thanks for the great repository. I came across this example which seems to fail:

timeseries:
  - name: test-amp
    length: 1000
    base-oscillations:
      - kind: sine
    anomalies:
      - position: end
        length: 47
        channel: 0
        kinds:
          - kind: amplitude
            amplitude_factor: 2.0

Running with: python -m gutenTAG --config-yaml tests/configs/config-amp.yaml --seed 42 --no-save --plot this fails to create the anomaly

Generating datasets:   0%|                                                                                      | 0/1 [00:00<?, ?it/s]
Traceback (most recent call last):
  File ".../.venv/lib/python3.11/site-packages/gutenTAG/gutenTAG.py", line 132, in generate
    results: List[Tuple[Dict, Dict[str, Any], Optional[List[ExtTimeSeries]]]] = Parallel(n_jobs=n_jobs)(
                                                                                ^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.11/site-packages/joblib/parallel.py", line 1863, in __call__
    return output if self.return_generator else list(output)
                                                ^^^^^^^^^^^^
  File ".../.venv/lib/python3.11/site-packages/joblib/parallel.py", line 1792, in _get_sequential_output
    res = func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.11/site-packages/gutenTAG/gutenTAG.py", line 157, in internal_generate
    ts.generate(ctx.seed)
  File ".../.venv/lib/python3.11/site-packages/gutenTAG/generator/timeseries.py", line 37, in generate
    self.timeseries, self.labels = consolidator.generate(GenerationContext(seed=self._create_new_seed(random_seed)))
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.11/site-packages/gutenTAG/consolidator.py", line 43, in generate
    self.generate_anomalies(ctx)
  File ".../.venv/lib/python3.11/site-packages/gutenTAG/consolidator.py", line 67, in generate_anomalies
    anomaly_protocol = anomaly.generate(ctx.to_anomaly(current_base_oscillation, positions))
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.11/site-packages/gutenTAG/anomalies/__init__.py", line 65, in generate
    protocol = anomaly.generate(protocol)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.11/site-packages/gutenTAG/anomalies/types/amplitude.py", line 55, in generate
    subsequence = anomaly_protocol.base_oscillation.timeseries[anomaly_protocol.start:anomaly_protocol.end] * amplitude_bell
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
ValueError: operands could not be broadcast together with shapes (47,) (46,) 

Maybe I'm wrong but as it looks the error corresponds to As far as I can see the error originates in:

https://github.com/TimeEval/GutenTAG/blob/b6e9e87c02c418f0603e9e91828f4fa5217e738a/gutenTAG/anomalies/types/amplitude.py#L35 and with creeping-length passed in https://github.com/TimeEval/GutenTAG/blob/b6e9e87c02c418f0603e9e91828f4fa5217e738a/gutenTAG/anomalies/types/amplitude.py#L51

I'll open a PR soon, if this is fine for you. Thanks again for the repo 👍

CodeLionX commented 6 months ago

Hi @arrrrrmin,

Good catch, and thanks for the elaborate issue with MWE! 👍🏼

You are right. That sounds like a rounding error in those code lines.

We very much appreciate a PR fixing this issue. Please also add a new test to our test suite so that we can catch this error in the future. If you need help with preparing the PR, please let me know.

CodeLionX commented 6 months ago

🚀 I released a new version with your fix: https://pypi.org/project/timeeval-gutenTAG/1.4.1/

Thank you very much!