-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
cos.py
92 lines (74 loc) · 2.61 KB
/
cos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
#!/usr/bin/env python3 -u
# copyright: sktime developers, BSD-3-Clause License (see LICENSE file)
"""Implements cosine transformation."""
from math import pi
import numpy as np
from sktime.transformations.base import BaseTransformer
__author__ = ["afzal442"]
__all__ = ["CosineTransformer"]
class CosineTransformer(BaseTransformer):
"""Cosine transformation.
This is a wrapper around numpy's cosine function (see :func:`numpy.cos`).
See Also
--------
numpy.cos
Examples
--------
>>> from sktime.transformations.series.cos import CosineTransformer
>>> from sktime.datasets import load_airline
>>> y = load_airline()
>>> transformer = CosineTransformer()
>>> y_hat = transformer.fit_transform(y)
"""
_tags = {
# packaging info
# --------------
"authors": "afzal442",
"maintainers": "afzal442",
# estimator type
# --------------
"scitype:transform-input": "Series",
# what is the scitype of X: Series, or Panel
"scitype:transform-output": "Series",
# what scitype is returned: Primitives, Series, Panel
"scitype:instancewise": True, # is this an instance-wise transform?
"X_inner_mtype": "np.ndarray", # which mtypes do _fit/_predict support for X?
"y_inner_mtype": "None", # which mtypes do _fit/_predict support for y?
"univariate-only": False,
"fit_is_empty": True,
"transform-returns-same-time-index": True,
"capability:inverse_transform": True,
"capability:inverse_transform:range": [-pi, pi],
}
def _transform(self, X, y=None):
"""Transform X and return a transformed version.
private _transform containing the core logic, called from transform
Parameters
----------
X : 2D np.ndarray
Data to be transformed
y : ignored argument for interface compatibility
Additional data, e.g., labels for transformation
Returns
-------
Xt : 2D np.ndarray
transformed version of X
"""
Xt = np.cos(X)
return Xt
def _inverse_transform(self, X, y=None):
"""Inverse transform X and return an inverse transformed version.
core logic
Parameters
----------
X : 2D np.ndarray
Data to be transformed
y : ignored argument for interface compatibility
Additional data, e.g., labels for transformation
Returns
-------
Xt : 2D np.ndarray
inverse transformed version of X
"""
Xt = np.arccos(X)
return Xt