atan2
DiminishingAtan2
Bases: OneToOneInversableDerivableTransformer
Transform series by applying the Atan2 equation (same as in Masster) fro diminishing return multiply by the max parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- | saturation (float | Parameter of the atan diminishing function (0 < saturation < 1). The convexity of the response curve increases with saturation. | required |
- | max (float | Symbolic maximum, which represents the value above which the variable is in the area of saturation (default to None and then set to the maximum value of the training serie). | required |
Source code in eki_mmo_equations/one_to_one_transformations/diminishing_return/atan2.py
class DiminishingAtan2(OneToOneInversableDerivableTransformer):
"""
Transform series by applying the Atan2 equation (same as in Masster) fro diminishing return
multiply by the max parameter.
```math
\\frac {\\arctan (saturation \\times (\\frac{serie}{max})^2)}{\\frac{\\pi}{2}}
```
Args:
- saturation (float): Parameter of the atan diminishing function (0 < saturation < 1). The convexity of the
response curve increases with saturation.
- max (float): Symbolic maximum, which represents the value above which the variable is in the area of
saturation (default to None and then set to the maximum value of the training serie).
"""
def __init__(self, saturation, max=None) -> None:
self.saturation = saturation
self.max = max
@property
def parameters(self) -> Dict[str, float]:
return self.__dict__
# ------- METHODS -------
def fit(self, serie: np.ndarray, y=None):
if self.max is None:
if np.any(serie[serie > 0]):
self.max = serie.max()
else:
self.max = serie.min() or 1
return super().fit(serie, y)
def transform(self, serie: np.ndarray, copy=False) -> np.ndarray:
serie = super().transform(serie, copy)
return self._transformer(serie, self.saturation, self.max)
def inverse_transform(self, serie: np.ndarray, copy=False) -> np.ndarray:
serie = super().inverse_transform(serie, copy)
return self._inverse_transformer(serie, self.saturation, self.max)
def derivative_transform(self, serie: np.ndarray, copy=False) -> np.ndarray:
serie = super().derivative_transform(serie, copy)
return self._derivative_transformer(serie, self.saturation, self.max)
# ------- TRANSFORMERS -------
@staticmethod
def _transformer(serie: np.ndarray, saturation, max) -> np.ndarray:
a = (serie / max) ** 2
return np.arctan(saturation * a) / (np.pi / 2)
@staticmethod
def _inverse_transformer(serie: np.ndarray, saturation, max) -> np.ndarray:
return max * np.sqrt(np.tan((serie * np.pi / 2)) / saturation)
@staticmethod
def _derivative_transformer(serie: np.ndarray, saturation, max) -> np.ndarray:
a = (serie / max) ** 2
return (2 * saturation * serie / max**2) / (1 + (saturation * a) ** 2)
# ------- CHECKERS -------
def check_params(self, serie: np.ndarray):
"""Check if parameters respect their application scope."""
if self.saturation <= 0 or self.saturation >= 1:
raise ParameterScopeException(f"Parameter saturation must be in ]0, 1[, not {self.saturation}.")
if self.max <= 0:
raise ParameterScopeException(f"Parameter max must be strictly positive, not {self.max}.")
check_params(serie)
Check if parameters respect their application scope.
Source code in eki_mmo_equations/one_to_one_transformations/diminishing_return/atan2.py
def check_params(self, serie: np.ndarray):
"""Check if parameters respect their application scope."""
if self.saturation <= 0 or self.saturation >= 1:
raise ParameterScopeException(f"Parameter saturation must be in ]0, 1[, not {self.saturation}.")
if self.max <= 0:
raise ParameterScopeException(f"Parameter max must be strictly positive, not {self.max}.")
DiminishingAtan2Unscale
Bases: DiminishingAtan2
Transform series by applying the Atan2 equation (same as in Masster) fro diminishing return multiply by the max parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- | saturation (float | Parameter of the atan diminishing function (0 < saturation < 1). The convexity of the response curve increases with saturation. | required |
- | max (float | Symbolic maximum, which represents the value above which the variable is in the area of saturation (default to None and then set to the maximum value of the training serie). | required |
Source code in eki_mmo_equations/one_to_one_transformations/diminishing_return/atan2.py
class DiminishingAtan2Unscale(DiminishingAtan2):
"""Transform series by applying the Atan2 equation (same as in Masster) fro diminishing return
multiply by the max parameter.
```math
\\ max \\times \\frac {\\arctan (saturation \\times (\\frac{serie}{max})^2)}{\\frac{\\pi}{2}}
```
Args:
- saturation (float): Parameter of the atan diminishing function (0 < saturation < 1). The convexity of the
response curve increases with saturation.
- max (float): Symbolic maximum, which represents the value above which the variable is in the area of
saturation (default to None and then set to the maximum value of the training serie).
"""
@staticmethod
def _transformer(serie: np.ndarray, saturation, max) -> np.ndarray:
return max * super(DiminishingAtan2Unscale, DiminishingAtan2Unscale)._transformer(
serie=serie, saturation=saturation, max=max
)
@staticmethod
def _inverse_transformer(serie: np.ndarray, saturation, max) -> np.ndarray:
return max * np.sqrt(np.tan(serie * np.pi / (2 * max)) / saturation)
@staticmethod
def _derivative_transformer(serie: np.ndarray, saturation, max) -> np.ndarray:
return max * super(DiminishingAtan2Unscale, DiminishingAtan2Unscale)._derivative_transformer(
serie=serie, saturation=saturation, max=max
)
# ------- CHECKERS -------
def check_params(self, serie: np.ndarray):
"""Check if parameters respect their application scope."""
if self.saturation <= 0 or self.saturation >= 1:
raise ParameterScopeException(f"Parameter saturation must be in ]0, 1[, not {self.saturation}.")
if self.max <= 0:
raise ParameterScopeException(f"Parameter max must be strictly positive, not {self.max}.")
check_params(serie)
Check if parameters respect their application scope.
Source code in eki_mmo_equations/one_to_one_transformations/diminishing_return/atan2.py
def check_params(self, serie: np.ndarray):
"""Check if parameters respect their application scope."""
if self.saturation <= 0 or self.saturation >= 1:
raise ParameterScopeException(f"Parameter saturation must be in ]0, 1[, not {self.saturation}.")
if self.max <= 0:
raise ParameterScopeException(f"Parameter max must be strictly positive, not {self.max}.")