code: def conditional_expected_number_of_purchases_up_to_time(self, t, frequency, recency, T):
          
          x = frequency
          r, alpha, a, b = self._unload_params("r", "alpha", "a", "b")
  
          _a = r + x
          _b = b + x
          _c = a + b + x - 1
          _z = t / (alpha + T + t)
          ln_hyp_term = np.log(hyp2f1(_a, _b, _c, _z))
  
          # if the value is inf, we are using a different but equivalent
          # formula to compute the function evaluation.
          ln_hyp_term_alt = np.log(hyp2f1(_c - _a, _c - _b, _c, _z)) + (_c - _a - _b) * np.log(1 - _z)
          ln_hyp_term = np.where(np.isinf(ln_hyp_term), ln_hyp_term_alt, ln_hyp_term)
          first_term = (a + b + x - 1) / (a - 1)
          second_term = 1 - np.exp(ln_hyp_term + (r + x) * np.log((alpha + T) / (alpha + t + T)))
  
          numerator = first_term * second_term
          denominator = 1 + (x > 0) * (a / (b + x - 1)) * ((alpha + T) / (alpha + recency)) ** (r + x)
  
          return numerator / denominator
docs: 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