import math


def marginal_parameter_likelihood(p: float, lambda_: float, x: int, tx: float, T: float) -> float:
    """Computes the marginal likelihood of the parameters lambda and p, given the transaction history.
    See http://brucehardie.com/papers/018/fader_et_al_mksc_05.pdf equation (3).

    Args:
        p (float): The churn parameter ``p``.
        lambda_ (float): The time interval parameter ``lambda``.
        x (int): The number of events observed.
        tx (float): The time of the last transaction observed.
        T (float): The current time (``asof_time``).

    Returns:
        float: The likelihood
    """
    z1 = (1 - p) ** x * lambda_**x * math.exp(-lambda_ * T)
    delta = int(x > 0)
    z2 = delta * p * (1 - p) ** (x - 1) * lambda_**x * math.exp(-lambda_ * tx)
    return z1 + z2