Skip to content

log

Log

Bases: OneToOneInversableDerivableTransformer

Transform series by applying natural log 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/log.py
class Log(OneToOneInversableDerivableTransformer):
    """Transform series by applying natural log function combined with (over) affine function.

    ```math
        \\ln (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) -> None:
        self.constant = constant
        self.slope = slope

    @property
    def parameters(self) -> Dict[str, float]:
        return self.__dict__

    # ------- METHODS -------

    def fit(self, serie: np.ndarray, y=None):

        if self.constant is None:
            if serie.min() < 0:
                self.constant = 1 - serie.min()
            else:
                self.constant = 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.constant, 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.constant, 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.constant, self.slope)

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

    @staticmethod
    def _transformer(serie: np.ndarray, constant, slope) -> np.ndarray:
        with np.errstate(over="raise", divide="raise"):
            return np.log(constant + slope * serie)

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

    @staticmethod
    def _derivative_transformer(serie: np.ndarray, constant, slope) -> np.ndarray:
        with np.errstate(over="raise", divide="raise"):
            return slope / (constant + slope * serie)

    # ------- 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/log.py
def check_params(self, serie: np.ndarray):
    """Check if parameters respect their application scope."""
    pass