def conditional_expected_number_of_purchases_up_to_time(self, t, frequency, recency, T):
        """
        Conditional expected number of purchases up to time.

        Calculate the expected number of repeat purchases up to time t for a
        randomly choose individual from the population, given they have
        purchase history (frequency, recency, T)

        Parameters
        ----------
        t: array_like
            times to calculate the expectation for.
        frequency: array_like
            historical frequency of customer.
        recency: array_like
            historical recency of customer.
        T: array_like
            age of the customer.

        Returns
        -------
        array_like

        """
        x, t_x = frequency, recency
        params = self._unload_params("r", "alpha", "s", "beta")
        r, alpha, s, beta = params

        likelihood = self._conditional_log_likelihood(params, x, t_x, T)
        first_term = (
            gammaln(r + x) - gammaln(r) + r * log(alpha) + s * log(beta) - (r + x) * log(alpha + T) - s * log(beta + T)
        )
        second_term = log(r + x) + log(beta + T) - log(alpha + T)
        third_term = log((1 - ((beta + T) / (beta + T + t)) ** (s - 1)) / (s - 1))
        return exp(first_term + second_term + third_term - likelihood)
def conditional_expected_number_of_purchases_up_to_time ( self , t , frequency , recency , T ) : x , t_x = frequency , recency params = self . _unload_params ( "r" , "alpha" , "s" , "beta" ) r , alpha , s , beta = params likelihood = self . _conditional_log_likelihood ( params , x , t_x , T ) first_term = ( gammaln ( r + x ) - gammaln ( r ) + r * log ( alpha ) + s * log ( beta ) - ( r + x ) * log ( alpha + T ) - s * log ( beta + T ) ) second_term = log ( r + x ) + log ( beta + T ) - log ( alpha + T ) third_term = log ( ( 1 - ( ( beta + T ) / ( beta + T + t ) ) ** ( s - 1 ) ) / ( s - 1 ) ) return exp ( first_term + second_term + third_term - likelihood )
Conditional expected number of purchases up to time.

        Calculate the expected number of repeat purchases up to time t for a
        randomly choose individual from the population, given they have
        purchase history (frequency, recency, T)

        Parameters
        ----------
        t: array_like
            times to calculate the expectation for.
        frequency: array_like
            historical frequency of customer.
        recency: array_like
            historical recency of customer.
        T: array_like
            age of the customer.

        Returns
        -------
        array_like