mirror of
https://github.com/wassname/pytorch-ts.git
synced 2026-08-11 11:24:31 +08:00
Model serialization (#8)
* wip: serialization ran successfully * wip: deserialization ran successfully * wip: deepar serialization
This commit is contained in:
committed by
Kashif Rasul
parent
2ee8a60f7f
commit
502f6d6c26
@@ -4,11 +4,12 @@ from typing import List
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from pandas.tseries.frequencies import to_offset
|
||||
|
||||
from pts.core.component import validated
|
||||
from .utils import get_granularity
|
||||
|
||||
|
||||
class TimeFeature(ABC):
|
||||
@validated()
|
||||
def __init__(self, normalized: bool = True):
|
||||
self.normalized = normalized
|
||||
|
||||
|
||||
+10
-11
@@ -19,8 +19,7 @@ from scipy.special import erf, erfinv
|
||||
import torch
|
||||
|
||||
from pts.exception import assert_pts
|
||||
from pts.dataset import DataEntry
|
||||
|
||||
from pts.core.component import validated
|
||||
from pts.dataset import DataEntry
|
||||
|
||||
from .transform import (
|
||||
@@ -42,7 +41,7 @@ class AsNumpyArray(SimpleTransformation):
|
||||
dtype
|
||||
numpy dtype to use.
|
||||
"""
|
||||
|
||||
@validated()
|
||||
def __init__(
|
||||
self, field: str, expected_ndim: int, dtype: np.dtype = np.float32
|
||||
) -> None:
|
||||
@@ -86,7 +85,7 @@ class ExpandDimArray(SimpleTransformation):
|
||||
axis
|
||||
Axis to expand (see np.expand_dims for details)
|
||||
"""
|
||||
|
||||
@validated()
|
||||
def __init__(self, field: str, axis: Optional[int] = None) -> None:
|
||||
self.field = field
|
||||
self.axis = axis
|
||||
@@ -112,7 +111,7 @@ class VstackFeatures(SimpleTransformation):
|
||||
drop_inputs
|
||||
If set to true the input fields will be dropped.
|
||||
"""
|
||||
|
||||
@validated()
|
||||
def __init__(
|
||||
self, output_field: str, input_fields: List[str], drop_inputs: bool = True,
|
||||
) -> None:
|
||||
@@ -148,7 +147,7 @@ class ConcatFeatures(SimpleTransformation):
|
||||
drop_inputs
|
||||
If set to true the input fields will be dropped.
|
||||
"""
|
||||
|
||||
@validated()
|
||||
def __init__(
|
||||
self, output_field: str, input_fields: List[str], drop_inputs: bool = True,
|
||||
) -> None:
|
||||
@@ -180,7 +179,7 @@ class SwapAxes(SimpleTransformation):
|
||||
axes
|
||||
Axes to use
|
||||
"""
|
||||
|
||||
@validated()
|
||||
def __init__(self, input_fields: List[str], axes: Tuple[int, int]) -> None:
|
||||
self.input_fields = input_fields
|
||||
self.axis1, self.axis2 = axes
|
||||
@@ -215,7 +214,7 @@ class ListFeatures(SimpleTransformation):
|
||||
drop_inputs
|
||||
If true the input fields will be removed from the result.
|
||||
"""
|
||||
|
||||
@validated()
|
||||
def __init__(
|
||||
self, output_field: str, input_fields: List[str], drop_inputs: bool = True,
|
||||
) -> None:
|
||||
@@ -238,7 +237,7 @@ class TargetDimIndicator(SimpleTransformation):
|
||||
"""
|
||||
Label-encoding of the target dimensions.
|
||||
"""
|
||||
|
||||
@validated()
|
||||
def __init__(self, field_name: str, target_field: str) -> None:
|
||||
self.field_name = field_name
|
||||
self.target_field = target_field
|
||||
@@ -252,7 +251,7 @@ class SampleTargetDim(FlatMapTransformation):
|
||||
"""
|
||||
Samples random dimensions from the target at training time.
|
||||
"""
|
||||
|
||||
@validated()
|
||||
def __init__(
|
||||
self,
|
||||
field_name: str,
|
||||
@@ -304,7 +303,7 @@ class CDFtoGaussianTransform(MapTransformation):
|
||||
Note that this transformation is currently intended for multivariate
|
||||
targets only.
|
||||
"""
|
||||
|
||||
@validated()
|
||||
def __init__(
|
||||
self,
|
||||
target_dim: int,
|
||||
|
||||
@@ -18,7 +18,7 @@ import pandas as pd
|
||||
|
||||
from pts.dataset import DataEntry
|
||||
from pts.feature import TimeFeature
|
||||
|
||||
from pts.core.component import validated
|
||||
from .transform import SimpleTransformation, MapTransformation
|
||||
from .split import shift_timestamp
|
||||
|
||||
@@ -49,7 +49,7 @@ class AddObservedValuesIndicator(SimpleTransformation):
|
||||
they will not be replaced. In any case the indicator is included in the
|
||||
result.
|
||||
"""
|
||||
|
||||
@validated()
|
||||
def __init__(
|
||||
self,
|
||||
target_field: str,
|
||||
@@ -101,7 +101,7 @@ class AddConstFeature(MapTransformation):
|
||||
dtype
|
||||
Numpy dtype to use for resulting array.
|
||||
"""
|
||||
|
||||
@validated()
|
||||
def __init__(
|
||||
self,
|
||||
output_field: str,
|
||||
@@ -146,7 +146,7 @@ class AddTimeFeatures(MapTransformation):
|
||||
pred_length
|
||||
Prediction length
|
||||
"""
|
||||
|
||||
@validated()
|
||||
def __init__(
|
||||
self,
|
||||
start_field: str,
|
||||
@@ -226,7 +226,7 @@ class AddAgeFeature(MapTransformation):
|
||||
If set to true the age feature grows logarithmically otherwise linearly
|
||||
over time.
|
||||
"""
|
||||
|
||||
@validated()
|
||||
def __init__(
|
||||
self,
|
||||
target_field: str,
|
||||
|
||||
@@ -15,7 +15,7 @@ from collections import Counter
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from pts.dataset import DataEntry
|
||||
|
||||
from pts.core.component import validated
|
||||
from .transform import SimpleTransformation, MapTransformation
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class RenameFields(SimpleTransformation):
|
||||
mapping
|
||||
Name mapping `input_name -> output_name`
|
||||
"""
|
||||
|
||||
@validated()
|
||||
def __init__(self, mapping: Dict[str, str]) -> None:
|
||||
self.mapping = mapping
|
||||
values_count = Counter(mapping.values())
|
||||
@@ -46,6 +46,8 @@ class RenameFields(SimpleTransformation):
|
||||
|
||||
|
||||
class RemoveFields(SimpleTransformation):
|
||||
|
||||
@validated()
|
||||
def __init__(self, field_names: List[str]) -> None:
|
||||
self.field_names = field_names
|
||||
|
||||
@@ -67,7 +69,7 @@ class SetField(SimpleTransformation):
|
||||
value
|
||||
Value to be set
|
||||
"""
|
||||
|
||||
@validated()
|
||||
def __init__(self, output_field: str, value: Any) -> None:
|
||||
self.output_field = output_field
|
||||
self.value = value
|
||||
@@ -88,7 +90,7 @@ class SetFieldIfNotPresent(SimpleTransformation):
|
||||
value
|
||||
Value to be set
|
||||
"""
|
||||
|
||||
@validated()
|
||||
def __init__(self, field: str, value: Any) -> None:
|
||||
self.output_field = field
|
||||
self.value = value
|
||||
@@ -108,7 +110,7 @@ class SelectFields(MapTransformation):
|
||||
input_fields
|
||||
List of fields to keep.
|
||||
"""
|
||||
|
||||
@validated()
|
||||
def __init__(self, input_fields: List[str]) -> None:
|
||||
self.input_fields = input_fields
|
||||
|
||||
|
||||
Reference in New Issue
Block a user