Skip to content

Custom handlers

cesnet_tszoo.utils.custom_handler.custom_handler

PerSeriesCustomHandler

Bases: CustomHandler

Base class for PerSeriesCustomHandler. Used for custom handlers that are fitted on single train time series and then applied to that time series parts from target sets.

This class serves as the foundation for creating PerSeriesCustomHandler handlers and should be subclassed from.

Example:

import numpy as np

class PerFitTest(PerSeriesCustomHandler):

    def __init__(self):
        self.count = 0
        super().__init__()

    def fit(self, data: np.ndarray) -> None:
        self.count += 1

    def apply(self, data: np.ndarray) -> np.ndarray:
        data[:, :] = self.count
        return data

    @staticmethod
    def get_target_sets():
        return ["val"]
Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
class PerSeriesCustomHandler(CustomHandler):
    """
    Base class for PerSeriesCustomHandler. Used for custom handlers that are fitted on single train time series and then applied to that time series parts from target sets.

    This class serves as the foundation for creating PerSeriesCustomHandler handlers and should be subclassed from.

    Example:

        import numpy as np

        class PerFitTest(PerSeriesCustomHandler):

            def __init__(self):
                self.count = 0
                super().__init__()

            def fit(self, data: np.ndarray) -> None:
                self.count += 1

            def apply(self, data: np.ndarray) -> np.ndarray:
                data[:, :] = self.count
                return data

            @staticmethod
            def get_target_sets():
                return ["val"]             
    """

    @abstractmethod
    def fit(self, data: np.ndarray) -> None:
        """
        Sets the PerSeriesCustomHandler values for a given time series data. Usually train set part of the time series.

        Parameters:
            data: A structured numpy array representing data for a single time series with shape `(times)`. Use data["base_data"] to get non matrix features excluding any identifiers. 
                  For matrix features use their name instead of base_data.
        """
        ...

    @abstractmethod
    def apply(self, data: np.ndarray) -> np.ndarray:
        """
        Applies on the input data for a given time series part.

        Parameters:
            data: A structured numpy array representing data for a single time series with shape `(times)`. Use data["base_data"] to get non matrix features excluding any identifiers. 
                  For matrix features use their name instead of base_data.  

        Returns:
            The changed data, with the same shape and dtype as the input `(times)`.            
        """
        ...

    @staticmethod
    @abstractmethod
    def get_target_sets() -> set[SplitType] | set[Literal["train", "val", "test", "all"]]:
        """Specifies on which sets this handler should be used. """
        ...

apply abstractmethod

apply(data: ndarray) -> np.ndarray

Applies on the input data for a given time series part.

Parameters:

Name Type Description Default
data ndarray

A structured numpy array representing data for a single time series with shape (times). Use data["base_data"] to get non matrix features excluding any identifiers. For matrix features use their name instead of base_data.

required

Returns:

Type Description
ndarray

The changed data, with the same shape and dtype as the input (times).

Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
77
78
79
80
81
82
83
84
85
86
87
88
89
@abstractmethod
def apply(self, data: np.ndarray) -> np.ndarray:
    """
    Applies on the input data for a given time series part.

    Parameters:
        data: A structured numpy array representing data for a single time series with shape `(times)`. Use data["base_data"] to get non matrix features excluding any identifiers. 
              For matrix features use their name instead of base_data.  

    Returns:
        The changed data, with the same shape and dtype as the input `(times)`.            
    """
    ...

fit abstractmethod

fit(data: ndarray) -> None

Sets the PerSeriesCustomHandler values for a given time series data. Usually train set part of the time series.

Parameters:

Name Type Description Default
data ndarray

A structured numpy array representing data for a single time series with shape (times). Use data["base_data"] to get non matrix features excluding any identifiers. For matrix features use their name instead of base_data.

required
Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
66
67
68
69
70
71
72
73
74
75
@abstractmethod
def fit(self, data: np.ndarray) -> None:
    """
    Sets the PerSeriesCustomHandler values for a given time series data. Usually train set part of the time series.

    Parameters:
        data: A structured numpy array representing data for a single time series with shape `(times)`. Use data["base_data"] to get non matrix features excluding any identifiers. 
              For matrix features use their name instead of base_data.
    """
    ...

get_target_sets abstractmethod staticmethod

get_target_sets() -> set[SplitType] | set[Literal['train', 'val', 'test', 'all']]

Specifies on which sets this handler should be used.

Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
91
92
93
94
95
@staticmethod
@abstractmethod
def get_target_sets() -> set[SplitType] | set[Literal["train", "val", "test", "all"]]:
    """Specifies on which sets this handler should be used. """
    ...

AllSeriesCustomHandler

Bases: CustomHandler

Base class for AllSeriesCustomHandler. Used for custom handlers that are fitted on all train time series and then applied to all (from target sets) time series.

This class serves as the foundation for creating AllSeriesCustomHandler handlers and should be subclassed from.

Example:

import numpy as np

class PerFitTest(PerSeriesCustomHandler):

    def __init__(self):
        self.count = 0
        super().__init__()

    def fit(self, data: np.ndarray) -> None:
        self.count += 1

    def apply(self, data: np.ndarray) -> np.ndarray:
        for name in data.dtype.names:
            data[name][:, :] = self.count

        return data

    @staticmethod
    def get_target_sets():
        return ["val"]
Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
class AllSeriesCustomHandler(CustomHandler):
    """
    Base class for AllSeriesCustomHandler. Used for custom handlers that are fitted on all train time series and then applied to all (from target sets) time series.

    This class serves as the foundation for creating AllSeriesCustomHandler handlers and should be subclassed from.

    Example:

        import numpy as np

        class PerFitTest(PerSeriesCustomHandler):

            def __init__(self):
                self.count = 0
                super().__init__()

            def fit(self, data: np.ndarray) -> None:
                self.count += 1

            def apply(self, data: np.ndarray) -> np.ndarray:
                for name in data.dtype.names:
                    data[name][:, :] = self.count       

                return data

            @staticmethod
            def get_target_sets():
                return ["val"]

    """

    @abstractmethod
    def partial_fit(self, data: np.ndarray) -> None:
        """
        Sets the AllSeriesCustomHandler values for a given time series data. Usually train set part of some time series.

        Parameters:
            data: A structured numpy array representing data for a single time series with shape `(times)`. Use data["base_data"] to get non matrix features excluding any identifiers. 
                  For matrix features use their name instead of base_data. 
        """
        ...

    @abstractmethod
    def apply(self, data: np.ndarray) -> np.ndarray:
        """
        Applies on the input data for a given time series part.

        Parameters:
            data: A structured numpy array representing data for a single time series with shape `(times)`. Use data["base_data"] to get non matrix features excluding any identifiers. 
                  For matrix features use their name instead of base_data.

        Returns:
            The changed data, with the same shape and dtype as the input `(times)`.            
        """
        ...

    @staticmethod
    @abstractmethod
    def get_target_sets() -> set[SplitType] | set[Literal["train", "val", "test", "all"]]:
        """Specifies on which sets this handler should be used. """
        ...

apply abstractmethod

apply(data: ndarray) -> np.ndarray

Applies on the input data for a given time series part.

Parameters:

Name Type Description Default
data ndarray

A structured numpy array representing data for a single time series with shape (times). Use data["base_data"] to get non matrix features excluding any identifiers. For matrix features use their name instead of base_data.

required

Returns:

Type Description
ndarray

The changed data, with the same shape and dtype as the input (times).

Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
140
141
142
143
144
145
146
147
148
149
150
151
152
@abstractmethod
def apply(self, data: np.ndarray) -> np.ndarray:
    """
    Applies on the input data for a given time series part.

    Parameters:
        data: A structured numpy array representing data for a single time series with shape `(times)`. Use data["base_data"] to get non matrix features excluding any identifiers. 
              For matrix features use their name instead of base_data.

    Returns:
        The changed data, with the same shape and dtype as the input `(times)`.            
    """
    ...

get_target_sets abstractmethod staticmethod

get_target_sets() -> set[SplitType] | set[Literal['train', 'val', 'test', 'all']]

Specifies on which sets this handler should be used.

Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
154
155
156
157
158
@staticmethod
@abstractmethod
def get_target_sets() -> set[SplitType] | set[Literal["train", "val", "test", "all"]]:
    """Specifies on which sets this handler should be used. """
    ...

partial_fit abstractmethod

partial_fit(data: ndarray) -> None

Sets the AllSeriesCustomHandler values for a given time series data. Usually train set part of some time series.

Parameters:

Name Type Description Default
data ndarray

A structured numpy array representing data for a single time series with shape (times). Use data["base_data"] to get non matrix features excluding any identifiers. For matrix features use their name instead of base_data.

required
Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
129
130
131
132
133
134
135
136
137
138
@abstractmethod
def partial_fit(self, data: np.ndarray) -> None:
    """
    Sets the AllSeriesCustomHandler values for a given time series data. Usually train set part of some time series.

    Parameters:
        data: A structured numpy array representing data for a single time series with shape `(times)`. Use data["base_data"] to get non matrix features excluding any identifiers. 
              For matrix features use their name instead of base_data. 
    """
    ...

NoFitCustomHandler

Bases: CustomHandler

Base class for NoFitCustomHandler. Used for custom handlers that are not fitted and are applied to (from target sets) time series.

This class serves as the foundation for creating NoFitCustomHandler handlers and should be subclassed from.

Example:

import numpy as np

class NoFitTest(NoFitCustomHandler):
    def apply(self, data: np.ndarray) -> np.ndarray:
        for name in data.dtype.names:
            data[name][:, :] = -1
        return data

    @staticmethod
    def get_target_sets():
        return ["test"]
Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
class NoFitCustomHandler(CustomHandler):
    """
    Base class for NoFitCustomHandler. Used for custom handlers that are not fitted and are applied to (from target sets) time series.

    This class serves as the foundation for creating NoFitCustomHandler handlers and should be subclassed from.

    Example:

        import numpy as np

        class NoFitTest(NoFitCustomHandler):
            def apply(self, data: np.ndarray) -> np.ndarray:
                for name in data.dtype.names:
                    data[name][:, :] = -1
                return data

            @staticmethod
            def get_target_sets():
                return ["test"]

    """

    @abstractmethod
    def apply(self, data: np.ndarray) -> np.ndarray:
        """
        Applies on the input data for a given time series part.

        Parameters:
            data: A structured numpy array representing data for a single time series with shape `(times)`. Use data["base_data"] to get non matrix features excluding any identifiers. 
                  For matrix features use their name instead of base_data.

        Returns:
            The changed data, with the same shape and dtype as the input `(times)`.            
        """
        ...

    @staticmethod
    @abstractmethod
    def get_target_sets() -> set[SplitType] | set[Literal["train", "val", "test", "all"]]:
        """Specifies on which sets this handler should be used. """
        ...

apply abstractmethod

apply(data: ndarray) -> np.ndarray

Applies on the input data for a given time series part.

Parameters:

Name Type Description Default
data ndarray

A structured numpy array representing data for a single time series with shape (times). Use data["base_data"] to get non matrix features excluding any identifiers. For matrix features use their name instead of base_data.

required

Returns:

Type Description
ndarray

The changed data, with the same shape and dtype as the input (times).

Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
183
184
185
186
187
188
189
190
191
192
193
194
195
@abstractmethod
def apply(self, data: np.ndarray) -> np.ndarray:
    """
    Applies on the input data for a given time series part.

    Parameters:
        data: A structured numpy array representing data for a single time series with shape `(times)`. Use data["base_data"] to get non matrix features excluding any identifiers. 
              For matrix features use their name instead of base_data.

    Returns:
        The changed data, with the same shape and dtype as the input `(times)`.            
    """
    ...

get_target_sets abstractmethod staticmethod

get_target_sets() -> set[SplitType] | set[Literal['train', 'val', 'test', 'all']]

Specifies on which sets this handler should be used.

Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
197
198
199
200
201
@staticmethod
@abstractmethod
def get_target_sets() -> set[SplitType] | set[Literal["train", "val", "test", "all"]]:
    """Specifies on which sets this handler should be used. """
    ...