Skip to content

[BUG] HidalgoSegmenter raises IndexError when no samples pass burn-in filtering #3168

@samay2504

Description

@samay2504

Describe the bug

When HidalgoSegmenter is configured with a high burn_in value (e.g., 0.9) and low sampling_rate (default 10), the filtering condition it % sampling_rate == 0 and it >= n_iter * burn_in may result in an empty idx array. This causes bestsampling to remain uninitialized, leading to an IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed when attempting to slice it as bestsampling[:, :K].

Root Cause:
The code doesn't validate that at least one sample passes the filtering criteria before attempting to access the sampled data.

Steps to Reproduce:
import numpy as np
from aeon.segmentation import HidalgoSegmenter

X = np.random.rand(50, 3)
model = HidalgoSegmenter(K=2, n_iter=10, sampling_rate=10, burn_in=0.9, seed=42)
model.fit(X) # IndexError raised

Expected Behavior: Should either produce valid samples or raise a clear error message indicating invalid parameter configuration.

Steps/Code to reproduce the bug

import numpy as np
from aeon.segmentation import HidalgoSegmenter

np.random.seed(42)
X = np.random.rand(50, 3)
model = HidalgoSegmenter(K=2, n_iter=10, sampling_rate=10, burn_in=0.9, seed=42)
model.fit(X)

Expected results

No error is thrown, or a clear ValueError message indicating invalid parameter configuration.

Actual results

Traceback (most recent call last):
  File "example_code.py", line 5, in <module>
    model.fit(X)
  File "aeon/segmentation/_hidalgo.py", line 315, in _fit
    self._d = np.mean(bestsampling[:, :K], axis=0)
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

Versions

aeon: 1.3.0+
numpy: 1.24+

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsegmentationSegmentation package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions