Skip to content

[ENH] Optimize QUANTTransformer by using shape calculation in _fit method to avoid unnecessary computations #2727

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions aeon/transformations/collection/interval_based/_quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def __init__(self, interval_depth=6, quantile_divisor=4):

def _fit(self, X, y=None):
import torch
import torch.nn.functional as F

X = torch.tensor(X).float()

Expand All @@ -85,17 +84,19 @@ def _fit(self, X, y=None):
if self.interval_depth < 1:
raise ValueError("interval_depth must be >= 1")

in_length = X.shape[-1]

representation_functions = (
lambda X: X,
lambda X: F.avg_pool1d(F.pad(X.diff(), (2, 2), "replicate"), 5, 1),
lambda X: X.diff(n=2),
lambda X: torch.fft.rfft(X).abs(),
in_length, # lambda X: X
in_length
- 1, # lambda X: F.avg_pool1d(F.pad(X.diff(), (2, 2), "replicate"), 5, 1)
in_length - 2, # lambda X: X.diff(n=2)
in_length // 2 + 1, # lambda X: torch.fft.rfft(X).abs()
)

self.intervals_ = []
for function in representation_functions:
Z = function(X)
self.intervals_.append(self._make_intervals(input_length=Z.shape[-1]))

for length in representation_functions:
self.intervals_.append(self._make_intervals(input_length=length))

return self

Expand Down