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
37 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 | |
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 numpy array representing data for a single time series with shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The changed data, with the same shape as the input |
Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
75 76 77 78 79 80 81 82 83 84 85 86 | |
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 numpy array representing data for a single time series with shape |
required |
Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
65 66 67 68 69 70 71 72 73 | |
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
88 89 90 91 92 | |
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 AllFitTest(AllSeriesCustomHandler):
def __init__(self):
self.count = 0
super().__init__()
def partial_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 ["train"]
Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
95 96 97 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 | |
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 numpy array representing data for a time series with shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The changed data, with the same shape as the input |
Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
134 135 136 137 138 139 140 141 142 143 144 145 | |
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
147 148 149 150 151 | |
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 numpy array representing data for a time series with shape |
required |
Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
124 125 126 127 128 129 130 131 132 | |
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:
data[:, :] = -1
return data
@staticmethod
def get_target_sets():
return ["test"]
Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
154 155 156 157 158 159 160 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 | |
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 numpy array representing data for a time series with shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The changed data, with the same shape as the input |
Source code in cesnet_tszoo\utils\custom_handler\custom_handler.py
175 176 177 178 179 180 181 182 183 184 185 186 | |
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
188 189 190 191 192 | |