MODULE REFERENCE
mappers
anomx.data.processing.transformers.mappersMapper and InvertibleMapper
InvertibleMapper
InvertibleMapper(fn: Callable[[np.number], np.number] | Callable[[pd.Timestamp, np.number], np.number], inverse_fn: Callable[[np.number], np.number] | Callable[[pd.Timestamp, np.number], np.number], name: str = 'InvertibleMapper', n_jobs: int = 1, verbose: bool = False, columns: str | list[str] | None = None)Bases: InvertibleDataTransformer
| Parameter | Type | Default |
|---|---|---|
fn | Callable[[np.number], np.number] | Callable[[pd.Timestamp, np.number], np.number] | required |
inverse_fn | Callable[[np.number], np.number] | Callable[[pd.Timestamp, np.number], np.number] | required |
name | str | 'InvertibleMapper' |
n_jobs | int | 1 |
verbose | bool | False |
columns | str | list[str] | None | None |
Data transformer to apply a custom function and its inverse to a (sequence of) TimeSeries (similar to calling anomx.data.timeseries.TimeSeries.map on each series).
Parameters
- fn
Either a function which takes a value and returns a value ie.
f(x) = yOr a function which takes a value and its timestamp and returns a value ie.f(timestamp, x) = y.- inverse_fn
Similarly to
fn, either a function which takes a value and returns a value ie.f(x) = yOr a function which takes a value and its timestamp and returns a value ie.f(timestamp, x) = y.inverse_fnshould be such thatinverse_fn(fn(x)) == x.- name
A specific name for the transformer.
- n_jobs
The number of jobs to run in parallel. Parallel jobs are created only when a
Sequence[TimeSeries]is passed as input to a method, parallelising operations regarding differentTimeSeries. Defaults to1(sequential). Setting the parameter to-1means using all the available processors. Note: for a small amount of data, the parallelisation overhead could end up increasing the total required amount of time.- verbose
Optionally, whether to print operations progress
Examples
>>> import numpy as np
>>> from anomx.data.timeseries import TimeSeries
>>> from anomx.data.processing.transformers import InvertibleMapper
>>> series = TimeSeries.from_values(np.array([1, 10, 100]))
>>> transformer = InvertibleMapper(np.log10, lambda x: 10 ** x)
>>> series_transformed = transformer.transform(series)
>>> print(series_transformed.values())
[[0.]
[1.]
[2.]]
[3.]]
>>> series_restored = transformer.inverse_transform(series_transformed)
>>> print(series_restored.values())
[[ 1.]
[ 10.]
[100.]]Members
ts_transformstaticmethod
ts_transform(series: TimeSeries, params: Mapping[str, Mapping[str, MapperFn]]) -> TimeSeries| Parameter | Type | Default |
|---|---|---|
series | TimeSeries | required |
params | Mapping[str, Mapping[str, MapperFn]] | required |
Returns TimeSeries
ts_inverse_transformstaticmethod
ts_inverse_transform(series: TimeSeries, params: Mapping[str, Mapping[str, MapperFn]], insample: TimeSeries | None = None) -> TimeSeries| Parameter | Type | Default |
|---|---|---|
series | TimeSeries | required |
params | Mapping[str, Mapping[str, MapperFn]] | required |
insample | TimeSeries | None | None |
Returns TimeSeries
Inherited members
Mapper
Mapper(fn: Callable[[np.number], np.number] | Callable[[pd.Timestamp, np.number], np.number], name: str = 'Mapper', n_jobs: int = 1, verbose: bool = False, columns: str | list[str] | None = None)Bases: BaseDataTransformer
| Parameter | Type | Default |
|---|---|---|
fn | Callable[[np.number], np.number] | Callable[[pd.Timestamp, np.number], np.number] | required |
name | str | 'Mapper' |
n_jobs | int | 1 |
verbose | bool | False |
columns | str | list[str] | None | None |
Data transformer to apply a custom function to a (sequence of) TimeSeries (similar to calling anomx.data.timeseries.TimeSeries.map on each series).
The mapper takes care of parallelizing the operations on multiple series over multiple processors.
Parameters
- fn
Either a function which takes a value and returns a value ie.
f(x) = yOr a function which takes a value and its timestamp and returns a value ie.f(timestamp, x) = y.- name
A specific name for the transformer.
- n_jobs
The number of jobs to run in parallel. Parallel jobs are created only when a
Sequence[TimeSeries]is passed as input to a method, parallelising operations regarding differentTimeSeries. Defaults to1(sequential). Setting the parameter to-1means using all the available processors. Note: for a small amount of data, the parallelisation overhead could end up increasing the total required amount of time.- verbose
Optionally, whether to print operations progress
- columns
Optionally, a string or list of strings specifying the names of the components (columns) to transform. If specified, only these components will be transformed, and the remaining components will be kept untouched. For more information refer to the
BaseDataTransformerdocumentation. In case the transformer is applied on multiple TimeSeries, it is expected that all series have the same column order.
Examples
>>> import numpy as np
>>> from anomx.data.timeseries import TimeSeries
>>> from anomx.data.processing.transformers import Mapper
>>> series = TimeSeries.from_values(np.array([1, 10, 100]))
>>> transformer = Mapper(np.log10)
>>> series_transformed = transformer.transform(series)
>>> print(series_transformed.values())
[[0.]
[1.]
[2.]]Members
ts_transformstaticmethod
ts_transform(series: TimeSeries, params: Mapping[str, Any]) -> TimeSeries| Parameter | Type | Default |
|---|---|---|
series | TimeSeries | required |
params | Mapping[str, Any] | required |
Returns TimeSeries