Skip to content

tanh

Tanh

Bases: OneToOneInversableDerivableTransformer

Transform series by applying hyperbolic tangent function combined with (over) linear function.

Parameters:

Name Type Description Default
slope float

Slope of the linear function.

required
Source code in eki_mmo_equations/one_to_one_transformations/mathematical_functions/tanh.py
class Tanh(OneToOneInversableDerivableTransformer):
    """Transform series by applying hyperbolic tangent function combined with (over) linear function.

    ```math
        \\tanh (slope \\times serie)
    ```

    Args:
        slope (float): Slope of the linear function.
    """

    def __init__(self, slope: float) -> None:
        self.slope = slope

    @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)

    def inverse_transform(self, serie: np.ndarray, copy=False) -> np.ndarray:
        serie = super().inverse_transform(serie, copy)

        return self._inverse_transformer(serie, self.slope)

    def derivative_transform(self, serie: np.ndarray, copy=False) -> np.ndarray:
        serie = super().derivative_transform(serie, copy)

        return self._derivative_transformer(serie, self.slope)

    # ------- TRANSFORMERS -------

    @staticmethod
    def _transformer(serie: np.ndarray, slope) -> np.ndarray:
        return np.tanh(slope * serie)

    @staticmethod
    def _inverse_transformer(serie: np.ndarray, slope) -> np.ndarray:
        with np.errstate(over="raise", divide="raise"):
            return np.arctanh(serie) / slope

    @staticmethod
    def _derivative_transformer(serie: np.ndarray, slope) -> np.ndarray:
        with np.errstate(over="raise", divide="raise"):
            cosh = np.cosh(slope * serie)
            sinh = np.sinh(slope * serie)
            return slope * (cosh**2 - sinh**2) / (cosh**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/tanh.py
def check_params(self, serie: np.ndarray):
    """Check if parameters respect their application scope."""
    pass