aeon-toolkit / aeon

A toolkit for machine learning from time series
https://aeon-toolkit.org/
BSD 3-Clause "New" or "Revised" License
890 stars 93 forks source link

[BUG] PaddingTransformer is not correctly resetting fill values #1749

Closed TonyBagnall closed 2 days ago

TonyBagnall commented 3 days ago

Describe the bug

repeated calls to fit will fail if the number of channels increases. I think fill_value is not properly reset on fit. Wait until #1737 is in before fixing

Steps/Code to reproduce the bug

This crashes

from aeon.testing.data_generation import make_example_3d_numpy
from aeon.transformations.collection import PaddingTransformer
X, y = make_example_3d_numpy(n_cases=10, n_channels=3, n_timepoints=30)
t = PaddingTransformer.create_test_instance()
t.fit(X, y)
t.transform(X)
X2 = t.fit_transform(X, y)
X, y = make_example_3d_numpy(n_cases=10, n_channels=4, n_timepoints=30)
t.fit(X, y)
t.transform(X)
X2 = t.fit_transform(X, y)

this does not

from aeon.testing.data_generation import make_example_3d_numpy
from aeon.transformations.collection import PaddingTransformer
X, y = make_example_3d_numpy(n_cases=10, n_channels=4, n_timepoints=30)
t = PaddingTransformer.create_test_instance()
t.fit(X, y)
t.transform(X)
X2 = t.fit_transform(X, y)
X, y = make_example_3d_numpy(n_cases=10, n_channels=3, n_timepoints=30)
t.fit(X, y)
t.transform(X)
X2 = t.fit_transform(X, y)

Expected results

not crash

Actual results

Traceback (most recent call last):
  File "C:\Code\aeon\aeon\local\transform_debug.py", line 39, in <module>
    t.transform(X)
  File "C:\Code\aeon\aeon\transformations\collection\base.py", line 156, in transform
    Xt = self._transform(X=X_inner, y=y_inner)
  File "C:\Code\aeon\aeon\transformations\collection\pad.py", line 168, in _transform
    constant_values=self.fill_value[i][j],
IndexError: index 3 is out of bounds for axis 0 with size 3

Versions

No response

TonyBagnall commented 2 days ago

this is because the constructor attribute is overwritten in fit, rather than stored in fitvalues. This means reset does not change self.fit_values, which also should not be changed in fit