def estimate_u(sumLogPi=None, nDoc=0, gamma=1.0, alpha0=1.0, initu=None, approx_grad=False, factr=1.0e7, **kwargs):
  sumLogPi = np.squeeze(np.asarray(sumLogPi, dtype=np.float64))
  assert sumLogPi.ndim == 1
  K = sumLogPi.size - 1
  if initu is None:
    initu = np.hstack( [np.ones(K), alpha0*np.ones(K)])
  assert initu.size == 2*K

  initc = np.log(initu)
  myFunc = lambda c: objFunc_c(c, sumLogPi, nDoc, gamma, alpha0)
  myGrad = lambda c: objGrad_c(c, sumLogPi, nDoc, gamma, alpha0)
  
  with warnings.catch_warnings():
    warnings.filterwarnings('error', category=RuntimeWarning,
                               message='overflow')
    try:
      chat, fhat, Info = scipy.optimize.fmin_l_bfgs_b(myFunc, initc,
                                                  fprime=myGrad, disp=None,
                                                  approx_grad=approx_grad,
                                                  factr=factr,
                                                  **kwargs)
    except RuntimeWarning:
      raise ValueError("FAILURE: overflow!" )
    except AssertionError:
      raise ValueError("FAILURE: NaN found!")
      
  if Info['warnflag'] > 1:
    raise ValueError("FAILURE: " + Info['task'])

  uhat = np.exp(chat)
  Info['initu'] = initu
  Info['objFunc'] = lambda u: objFunc_u(u, sumLogPi, nDoc, gamma, alpha0)
  Info['gradFunc'] = lambda u: objGrad_u(u, sumLogPi, nDoc, gamma, alpha0)
  return uhat, fhat, Info

########################################################### Objective/gradient
########################################################### in terms of u
Run gradient optimization to estimate best v for specified problem
dataset/ETHPy150Open daeilkim/refinery/refinery/bnpy/bnpy-dev/bnpy/allocmodel/admix/OptimizerForHDPFullVarModel.py/estimate_u