<reponame>btcross26/forward_stagewise_regression<gh_stars>1-10
"""Link function abstract base class."""

# author: <NAME>
# email: <EMAIL>
# created: 2019-08-26


from abc import ABC, abstractmethod

import numpy as np


class BaseLink(ABC):
    """Abstract base class for link functions."""

    def __call__(self, y: np.ndarray, inverse: bool = False) -> np.ndarray:
        """
        Call the instance object to calculate the link function.

        If `inverse` is True (default), get the link, eta, as a function of `y`.
        If `inverse` is False, then get y as a function of the link. In this case,
        one should pass the link function eta as the argument `y`.
        """
        if inverse:
            return self._inverse_link(y)
        return self._link(y)

    @abstractmethod
    def _link(self, y: np.ndarray) -> np.ndarray:
        """Get the link, eta, as a function of y."""
        ...

    @abstractmethod
    def _inverse_link(self, eta: np.ndarray) -> np.ndarray:
        """Get the target, y, as a function of the link, `eta`."""
        ...

    @abstractmethod
    def dydeta(self, y: np.ndarray) -> np.ndarray:
        """Get the derivative of `y` with respect to the link as a function of y."""
        ...

    @abstractmethod
    def d2ydeta2(self, y: np.ndarray) -> np.ndarray:
        """Get the second derivative of `y` with respect to the link as a function of y."""
        ...

"""Link function abstract base class."""

# author: <NAME>
# email: <EMAIL>
# created: 2019-08-26


from abc import ABC, abstractmethod

import numpy as np


class BaseLink(ABC):
    """Abstract base class for link functions."""

    def __call__(self, y: np.ndarray, inverse: bool = False) -> np.ndarray:
        """
        Call the instance object to calculate the link function.

        If `inverse` is True (default), get the link, eta, as a function of `y`.
        If `inverse` is False, then get y as a function of the link. In this case,
        one should pass the link function eta as the argument `y`.
        """
        if inverse:
            return self._inverse_link(y)
        return self._link(y)

    @abstractmethod
    def _link(self, y: np.ndarray) -> np.ndarray:
        """Get the link, eta, as a function of y."""
        ...

    @abstractmethod
    def _inverse_link(self, eta: np.ndarray) -> np.ndarray:
        """Get the target, y, as a function of the link, `eta`."""
        ...

    @abstractmethod
    def dydeta(self, y: np.ndarray) -> np.ndarray:
        """Get the derivative of `y` with respect to the link as a function of y."""
        ...

    @abstractmethod
    def d2ydeta2(self, y: np.ndarray) -> np.ndarray:
        """Get the second derivative of `y` with respect to the link as a function of y."""
        ...
Link function abstract base class. # author: <NAME> # email: <EMAIL> # created: 2019-08-26 Abstract base class for link functions. Call the instance object to calculate the link function.          If `inverse` is True (default), get the link, eta, as a function of `y`.         If `inverse` is False, then get y as a function of the link. In this case,         one should pass the link function eta as the argument `y`. Get the link, eta, as a function of y. Get the target, y, as a function of the link, `eta`. Get the derivative of `y` with respect to the link as a function of y. Get the second derivative of `y` with respect to the link as a function of y.