mirror of
https://github.com/wassname/pytorch-ts.git
synced 2026-08-11 11:24:31 +08:00
fixes
This commit is contained in:
@@ -0,0 +1 @@
|
||||
from .exception import assert_pts
|
||||
|
||||
@@ -6,7 +6,7 @@ from .process import ProcessDataEntry
|
||||
|
||||
class ListDataset(Dataset):
|
||||
def __init__(
|
||||
self, data_iter: Iterable[DataEntry], freq: str, one_dim_target: bool = True
|
||||
self, data_iter: Iterable[DataEntry], freq: str, one_dim_target: bool = True
|
||||
) -> None:
|
||||
process = ProcessDataEntry(freq, one_dim_target)
|
||||
self.list_data = [process(data) for data in data_iter]
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Union, List
|
||||
|
||||
import numpy as np
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from .stat import ScaleHistogram
|
||||
|
||||
|
||||
class InstanceSampler(ABC):
|
||||
@abstractmethod
|
||||
def __call__(self, ts: np.ndarray, a: int, b: int) -> Union[np.ndarray, List[int]]:
|
||||
@@ -30,7 +30,7 @@ class UniformSplitSampler(InstanceSampler):
|
||||
while ts.shape[-1] >= len(self.lookup):
|
||||
self.lookup = np.arange(2 * len(self.lookup))
|
||||
mask = np.random.uniform(low=0.0, high=1.0, size=b - a + 1) < self.p
|
||||
return self.lookup[a : a + len(mask)][mask]
|
||||
return self.lookup[a: a + len(mask)][mask]
|
||||
|
||||
|
||||
class TestSplitSampler(InstanceSampler):
|
||||
@@ -69,7 +69,7 @@ class ExpectedNumInstanceSampler(InstanceSampler):
|
||||
p = self.num_instances / self.avg_length
|
||||
|
||||
mask = np.random.uniform(low=0.0, high=1.0, size=b - a + 1) < p
|
||||
indices = self.lookup[a : a + len(mask)][mask]
|
||||
indices = self.lookup[a: a + len(mask)][mask]
|
||||
return indices
|
||||
|
||||
|
||||
@@ -97,5 +97,5 @@ class BucketInstanceSampler(InstanceSampler):
|
||||
self.lookup = np.arange(2 * len(self.lookup))
|
||||
p = 1.0 / self.scale_histogram.count(ts)
|
||||
mask = np.random.uniform(low=0.0, high=1.0, size=b - a + 1) < p
|
||||
indices = self.lookup[a : a + len(mask)][mask]
|
||||
indices = self.lookup[a: a + len(mask)][mask]
|
||||
return indices
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
def assert_pts(condition: bool, message: str, *args, **kwargs) -> None:
|
||||
if not condition:
|
||||
raise Exception(message.format(*args, **kwargs))
|
||||
@@ -7,6 +7,7 @@ import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
from pts.dataset import DataEntry, InstanceSampler
|
||||
from pts import assert_pts
|
||||
from .time_feature import TimeFeature
|
||||
|
||||
MAX_IDLE_TRANSFORMS = 100
|
||||
@@ -237,7 +238,7 @@ class AsNumpyArray(SimpleTransformation):
|
||||
# ugly: required as list conversion will fail in the case of a
|
||||
# float
|
||||
value = np.asarray(value, dtype=self.dtype)
|
||||
assert_data_error(
|
||||
assert_pts(
|
||||
value.ndim >= self.expected_ndim,
|
||||
'Input for field "{self.field}" does not have the required'
|
||||
"dimension (field: {self.field}, ndim observed: {value.ndim}, "
|
||||
|
||||
Reference in New Issue
Block a user