Skip to content

affine

Affine

Bases: OneToOneInversableDerivableTransformer

Transform series by applying 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/affine.py
class Affine(OneToOneInversableDerivableTransformer):
    """Transform series by applying affine function.

    ```math
        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__

    @property
    def is_linear(self) -> bool:
        if self.constant == 0:
            is_linear = True
        else:
            is_linear = False
        return is_linear

    # ------- 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: float, constant: float) -> np.ndarray:
        if (abs(slope - 1) < FLOAT_TOLERANCE_THRESHOLD) & (abs(constant) < FLOAT_TOLERANCE_THRESHOLD):
            return serie
        return slope * serie + constant

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

    @staticmethod
    def _derivative_transformer(serie: np.ndarray, slope, constant) -> np.ndarray:
        return slope * np.ones(np.shape(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/affine.py
def check_params(self, serie: np.ndarray):
    """Check if parameters respect their application scope."""
    pass