code: def _loglikelihood(params, x, tx, T):
          warnings.simplefilter(action="ignore", category=FutureWarning)
  
          
          alpha, beta, gamma, delta = params
  
          betaln_ab = betaln(alpha, beta)
          betaln_gd = betaln(gamma, delta)
  
          A = betaln(alpha + x, beta + T - x) - betaln_ab + betaln(gamma, delta + T) - betaln_gd
  
          B = 1e-15 * np.ones_like(T)
          recency_T = T - tx - 1
  
          for j in np.arange(recency_T.max() + 1):
              ix = recency_T >= j
              B = B + ix * betaf(alpha + x, beta + tx - x + j) * betaf(gamma + 1, delta + tx + j)
  
          B = log(B) - betaln_gd - betaln_ab
          return logaddexp(A, B)
docs: Log likelihood for optimizer.