Skip to content

Commit

Permalink
[ENH] Make transformer files private (#2072)
Browse files Browse the repository at this point in the history
* remove Theta

* take some private

* import

* revert Interpolator

* softdep

* hog1D

* API

* Revert "API"

This reverts commit 428900b.

* API

* API

* API

* take collection transformers private

* docstring

* tidy

* remove unused function

* remove unused function

* examples

* docstrings

* revert things
  • Loading branch information
TonyBagnall authored Sep 25, 2024
1 parent 0dd8eee commit a15250e
Show file tree
Hide file tree
Showing 28 changed files with 199 additions and 350 deletions.
311 changes: 52 additions & 259 deletions aeon/transformations/base.py

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions aeon/transformations/collection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@
"Normalise",
]

from aeon.transformations.collection._acf import AutocorrelationFunctionTransformer
from aeon.transformations.collection._ar_coefficient import ARCoefficientTransformer
from aeon.transformations.collection._downsample import DownsampleTransformer
from aeon.transformations.collection._dwt import DWTTransformer
from aeon.transformations.collection._hog1d import HOG1DTransformer
from aeon.transformations.collection._matrix_profile import MatrixProfile
from aeon.transformations.collection._normalise import Normalise
from aeon.transformations.collection._pad import Padder
from aeon.transformations.collection._periodogram import PeriodogramTransformer
from aeon.transformations.collection._reduce import Tabularizer
from aeon.transformations.collection._resize import Resizer
from aeon.transformations.collection._scaler import TimeSeriesScaler
from aeon.transformations.collection._segment import (
IntervalSegmenter,
RandomIntervalSegmenter,
SlidingWindowSegmenter,
)
from aeon.transformations.collection._slope import SlopeTransformer
from aeon.transformations.collection._truncate import Truncator
from aeon.transformations.collection.acf import AutocorrelationFunctionTransformer
from aeon.transformations.collection.ar_coefficient import ARCoefficientTransformer
from aeon.transformations.collection.base import BaseCollectionTransformer
from aeon.transformations.collection.channel_selection import (
ElbowClassPairwise,
ElbowClassSum,
)
from aeon.transformations.collection.dwt import DWTTransformer
from aeon.transformations.collection.hog1d import HOG1DTransformer
from aeon.transformations.collection.matrix_profile import MatrixProfile
from aeon.transformations.collection.periodogram import PeriodogramTransformer
from aeon.transformations.collection.reduce import Tabularizer
from aeon.transformations.collection.scaler import TimeSeriesScaler
from aeon.transformations.collection.segment import (
IntervalSegmenter,
RandomIntervalSegmenter,
SlidingWindowSegmenter,
)
from aeon.transformations.collection.slope import SlopeTransformer
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _transform(self, X, y=None):
order = self.order(X) if callable(self.order) else self.order
if order > n_timepoints - self.min_values:
order = n_timepoints - self.min_values
if order < 0:
if order <= 0:
order = 1

if order > n_timepoints - 1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np

from aeon.transformations.collection import BaseCollectionTransformer
from aeon.transformations.collection.base import BaseCollectionTransformer
from aeon.utils.numba.wavelets import haar_transform


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import numpy as np

from aeon.transformations.collection import BaseCollectionTransformer
from aeon.transformations.collection.base import BaseCollectionTransformer
from aeon.utils import split_series


Expand Down Expand Up @@ -48,7 +48,7 @@ def _transform(self, X, y=None):
Parameters
----------
X : 3D np.ndarray of shape = [n_cases, 1, n_timepoints]
X : 3D np.ndarray of shape (n_cases, 1, n_timepoints)
collection of time series to transform
y : ignored argument for interface compatibility
Expand All @@ -60,8 +60,6 @@ def _transform(self, X, y=None):
"""
# Get information about the dataframe
n_cases, n_channels, n_timepoints = X.shape
if n_channels > 1:
raise ValueError("HOG1D does not support multivariate time series.")
# Check the parameters are appropriate
self._check_parameters(n_timepoints)
transX = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np

from aeon.transformations.collection import BaseCollectionTransformer
from aeon.transformations.collection.base import BaseCollectionTransformer


def _sliding_dot_products(q, t, q_len, t_len):
Expand Down Expand Up @@ -217,8 +217,7 @@ def _transform(self, X, y=None):
Parameters
----------
X : 3D np.ndarray of shape = [n_cases, n_channels, n_timepoints]
panel of time series to transform
X : 3D np.ndarray of shape (n_cases, n_channels, n_timepoints)
y : ignored argument for interface compatibility
Returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

import numpy as np

from aeon.transformations.collection import BaseCollectionTransformer
from aeon.transformations.collection.base import BaseCollectionTransformer
from aeon.utils.validation import check_n_jobs


class PeriodogramTransformer(BaseCollectionTransformer):
"""Periodogram transformer.
This transformer converts a time series into its periodogram representation.
This transformer converts a collection of time series into its periodogram
representation.
Parameters
----------
Expand Down Expand Up @@ -82,17 +83,15 @@ def _transform(self, X, y=None):
kwargs = {"mode": self.pad_with}
if self.pad_with == "constant":
kwargs["constant_values"] = self.constant_value

len = int(math.pow(2, math.ceil(math.log(X.shape[2], 2))) - X.shape[2])
X = np.pad(
X,
(
(0, 0),
(0, 0),
(
0,
int(
math.pow(2, math.ceil(math.log(X.shape[2], 2))) - X.shape[2]
),
len,
),
),
**kwargs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__maintainer__ = []
__all__ = ["Tabularizer"]

from aeon.transformations.collection import BaseCollectionTransformer
from aeon.transformations.collection.base import BaseCollectionTransformer


class Tabularizer(BaseCollectionTransformer):
Expand All @@ -23,12 +23,12 @@ class Tabularizer(BaseCollectionTransformer):
}

def _transform(self, X, y=None):
"""Transform nested pandas dataframe into tabular dataframe.
"""Transform collection into tabular dataframe.
Parameters
----------
X : pandas DataFrame or 3D np.ndarray
panel of time series to transform
X : 3D np.ndarray of shape (n_cases, n_channels, n_timepoints)
Collection of time series to transform.
y : ignored argument for interface compatibility
Returns
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pandas as pd
from sklearn.utils import check_random_state

from aeon.transformations.collection import BaseCollectionTransformer
from aeon.transformations.collection.base import BaseCollectionTransformer
from aeon.utils.datetime import get_time_index
from aeon.utils.validation import check_window_length

Expand Down Expand Up @@ -407,7 +407,7 @@ class SlidingWindowSegmenter(BaseCollectionTransformer):
Examples
--------
>>> from aeon.datasets import load_unit_test
>>> from aeon.transformations.collection.segment import SlidingWindowSegmenter
>>> from aeon.transformations.collection import SlidingWindowSegmenter
>>> data = np.array([[[1, 2, 3, 4, 5, 6, 7, 8]], [[5, 5, 5, 5, 5, 5, 5, 5]]])
>>> seggy = SlidingWindowSegmenter(window_length=4)
>>> data2 = seggy.fit_transform(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import numpy as np

from aeon.transformations.collection import BaseCollectionTransformer
from aeon.transformations.collection.base import BaseCollectionTransformer
from aeon.utils import split_series


Expand All @@ -29,7 +29,7 @@ class SlopeTransformer(BaseCollectionTransformer):
Examples
--------
>>> import numpy as np
>>> from aeon.transformations.collection.slope import SlopeTransformer
>>> from aeon.transformations.collection import SlopeTransformer
>>> X = np.array([[[4, 6, 10, 12, 8, 6, 5, 5]]])
>>> s = SlopeTransformer(n_intervals=2)
>>> res = s.fit_transform(X)
Expand Down Expand Up @@ -57,8 +57,7 @@ def _transform(self, X, y=None):
Returns
-------
3D np.ndarray of shape = [n_cases, n_channels, n_timepoints]
collection of time series to transform
3D np.ndarray of shape = [n_cases, n_channels, n_intervals]
"""
# Get information about the dataframe
n_cases, n_channels, n_timepoints = X.shape
Expand Down
8 changes: 4 additions & 4 deletions aeon/transformations/collection/_truncate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Truncation transformer - truncate unequal length panels to lower/upper bounds."""
"""Truncation transformer - truncate unequal length collections."""

__all__ = ["Truncator"]
__maintainer__ = []
Expand All @@ -11,9 +11,9 @@
class Truncator(BaseCollectionTransformer):
"""Truncate unequal length time series to a lower bounds.
Truncates all series in panel between lower/upper range bounds. This transformer
assumes that all series have the same number of channels (dimensions) and
that all channels in a single series are the same length.
Truncates all series in collection between lower/upper range bounds. This
transformer assumes that all series have the same number of channels (dimensions)
and that all channels in a single series are the same length.
Parameters
----------
Expand Down
35 changes: 18 additions & 17 deletions aeon/transformations/collection/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,20 +377,21 @@ def _update(self, X, y=None):
# standard behaviour: no update takes place, new data is ignored
return self

def _check_y(self, y, n_cases):
if y is None:
return None
# Check y valid input for collection transformations
if not isinstance(y, (pd.Series, np.ndarray)):
raise TypeError(
f"y must be a np.array or a pd.Series, but found type: {type(y)}"
)
if isinstance(y, np.ndarray) and y.ndim > 1:
raise TypeError(f"y must be 1-dimensional, found {y.ndim} dimensions")
# Check matching number of labels
n_labels = y.shape[0]
if n_cases != n_labels:
raise ValueError(
f"Mismatch in number of cases. Number in X = {n_cases} nos in y = "
f"{n_labels}"
)

def _check_y(self, y, n_cases):
if y is None:
return None
# Check y valid input for collection transformations
if not isinstance(y, (pd.Series, np.ndarray)):
raise TypeError(
f"y must be a np.array or a pd.Series, but found type: {type(y)}"
)
if isinstance(y, np.ndarray) and y.ndim > 1:
raise TypeError(f"y must be 1-dimensional, found {y.ndim} dimensions")
# Check matching number of labels
n_labels = y.shape[0]
if n_cases != n_labels:
raise ValueError(
f"Mismatch in number of cases. Number in X = {n_cases} nos in y = "
f"{n_labels}"
)
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def _fit(self, X, y=None):
Parameters
----------
X : 3D np.ndarray of shape = [n_cases, n_channels, n_timepoints]
panel of time series to transform
X : 3D np.ndarray of shape (n_cases, n_channels, n_timepoints)
Collection of time series to transform
y : ignored argument for interface compatibility
Returns
Expand Down Expand Up @@ -128,8 +128,8 @@ def _transform(self, X, y=None):
Parameters
----------
X : 3D np.ndarray of shape = [n_cases, n_channels, n_timepoints]
panel of time series to transform
X : 3D np.ndarray of shape (n_cases, n_channels, n_timepoints)
Collection of time series to transform
y : ignored argument for interface compatibility
Returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def _fit(self, X, y=None):
Parameters
----------
X : 3D np.ndarray of shape = [n_cases, n_channels, n_timepoints]
panel of time series to transform
X : 3D np.ndarray of shape (n_cases, n_channels, n_timepoints)
Collection of time series to transform
y : ignored argument for interface compatibility
Returns
Expand Down Expand Up @@ -147,8 +147,8 @@ def _transform(self, X, y=None):
Parameters
----------
X : 3D np.ndarray of shape = [n_cases, n_channels, n_timepoints]
panel of time series to transform
X : 3D np.ndarray of shape (n_cases, n_channels, n_timepoints)
Collection of time series to transform.
y : ignored argument for interface compatibility
Returns
Expand Down
13 changes: 3 additions & 10 deletions aeon/transformations/collection/feature_based/_tsfresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,19 +550,12 @@ def _fit_transform(self, X, y=None):
Writes to self:
_is_fitted : flag is set to True.
_X : X, coerced copy of X, if remember_data tag is True
possibly coerced to inner type or update_data compatible type
by reference, when possible
model attributes (ending in "_") : dependent on estimator
Parameters
----------
X : Series or Panel, any supported type
Data to be transformed, of python type as follows:
Series: pd.Series, pd.DataFrame, or np.ndarray (1D or 2D)
Panel: pd.DataFrame with 2-level MultiIndex, list of pd.DataFrame,
nested pd.DataFrame, or pd.DataFrame in long/wide format
y : Series or Panel, default=None
X : 3D np.ndarray of shape (n_cases, n_channels, n_timepoints)
collection of time series to transform
y : Series, default=None
Additional data, e.g., labels for transformation
Returns
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Signature based panel transformations."""
"""Signature based Collection transformations."""

__all__ = [
"SignatureTransformer",
Expand Down
14 changes: 14 additions & 0 deletions aeon/transformations/collection/tests/test_acf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Test for incorrect input for ARCoefficientTransformer transformer."""

import numpy as np
import pytest

from aeon.transformations.collection import AutocorrelationFunctionTransformer


def test_acf():
"""Test ACF Transformer exceptions."""
X = np.random.random((2, 1, 10))
acf = AutocorrelationFunctionTransformer(n_lags=100)
with pytest.raises(ValueError, match=r"must be smaller than n_timepoints - 1"):
acf.fit_transform(X)
28 changes: 28 additions & 0 deletions aeon/transformations/collection/tests/test_ar_coefficient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Test for incorrect input for ARCoefficientTransformer transformer."""

import numpy as np
import pytest

from aeon.transformations.collection import ARCoefficientTransformer
from aeon.utils.validation._dependencies import _check_soft_dependencies


@pytest.mark.skipif(
not _check_soft_dependencies("statsmodels", severity="none"),
reason="skip test if required soft dependency statsmodels not available",
)
def test_ar_coefficient():
"""Test AR Coefficient Transformer exceptions."""
X = np.random.random((2, 1, 10))
ar = ARCoefficientTransformer(order=0)
Xt = ar.fit_transform(X)
assert Xt.shape[2] == 1
ar = ARCoefficientTransformer(order=-10)
Xt = ar.fit_transform(X)
assert Xt.shape[2] == 1
ar = ARCoefficientTransformer(order=100)
with pytest.raises(ValueError, match=r"must be smaller than n_timepoints - 1"):
ar.fit_transform(X)
ar = ARCoefficientTransformer(order=6, min_values=5)
Xt = ar.fit_transform(X)
assert Xt.shape[2] == 5
Loading

0 comments on commit a15250e

Please sign in to comment.