logistic
Logistic
Bases: OneToOneInversableDerivableTransformer
Transform series by applying logistic function combined with (over) affine function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- | slope (float | Slope of the affine function. | required |
- | constant (float | y-intercept of the affine function. | required |
Source code in eki_mmo_equations/one_to_one_transformations/mathematical_functions/logistic.py
class Logistic(OneToOneInversableDerivableTransformer):
"""Transform series by applying logistic function combined with (over) affine function.
```math
\\frac{1}{1+\\exp(-slope \\times (serie-constant))}
```
Args:
- slope (float): Slope of the affine function.
- constant (float): y-intercept of the affine function.
"""
def __init__(self, slope: float, constant: float) -> None:
self.slope = slope
self.constant = constant
@property
def parameters(self) -> Dict[str, float]:
return self.__dict__
# ------- METHODS -------
def transform(self, serie: np.ndarray, copy=False) -> np.ndarray:
serie = super().transform(serie, copy)
return self._transformer(serie, self.slope, self.constant)
def inverse_transform(self, serie: np.ndarray, copy=False) -> np.ndarray:
serie = super().inverse_transform(serie, copy)
return self._inverse_transformer(serie, self.slope, self.constant)
def derivative_transform(self, serie: np.ndarray, copy=False) -> np.ndarray:
serie = super().derivative_transform(serie, copy)
return self._derivative_transformer(serie, self.slope, self.constant)
# ------- TRANSFORMERS -------
@staticmethod
def _transformer(serie: np.ndarray, slope, constant) -> np.ndarray:
with np.errstate(over="raise", divide="raise"):
return 1 / (1 + np.exp(-slope * (serie - constant)))
@staticmethod
def _inverse_transformer(serie: np.ndarray, slope, constant) -> np.ndarray:
with np.errstate(over="raise", divide="raise"):
return constant - np.log(1 / serie - 1) / slope
@staticmethod
def _derivative_transformer(serie: np.ndarray, slope, constant) -> np.ndarray:
with np.errstate(over="raise", divide="raise"):
return slope * np.exp(-slope * (serie - constant)) / ((1 + np.exp(-slope * (serie - constant))) ** 2)
# ------- CHECKERS -------
def check_params(self, serie: np.ndarray):
"""Check if parameters respect their application scope."""
pass
check_params(serie)
Check if parameters respect their application scope.
Source code in eki_mmo_equations/one_to_one_transformations/mathematical_functions/logistic.py
def check_params(self, serie: np.ndarray):
"""Check if parameters respect their application scope."""
pass