def learn_fresh_model(freshModel, targetData, Kmax=500, Kfresh=10,
                      freshInitName='randexamples', freshAlgName='VB',
                      nFreshLap=50, randstate=np.random,
                      doRemoveRedundant=True,
                      doSimpleThrTest=False, curModel=None, **kwargs):
  ''' Learn a new model with Kfresh components
      Enforces an "upper limit" on number of components Kmax,
        so if Kexisting + Kfresh would exceed Kmax,
          we only consider Kmax-Kexisting components

      Returns
      -------
      freshSS : bnpy SuffStatDict with Kfresh components
  '''
  Kfresh = np.minimum(Kfresh, Kmax - freshModel.obsModel.K)

  if Kfresh < 2:
    raise BirthProposalError('BIRTH: Skipped to avoid exceeding user-specified limit of Kmax=%d components. ' % (Kmax))

  seed = randstate.choice(xrange(100000))
  freshModel.init_global_params(targetData, K=Kfresh, 
                                seed=seed, initname=freshInitName)
 
  LearnAlgConstructor = dict()
  LearnAlgConstructor['VB'] = VBLearnAlg
  algP = dict(nLap=nFreshLap, convergeSigFig=6, startLap=0)
  outP = dict(saveEvery=-1, traceEvery=-1, printEvery=-1)
  learnAlg = LearnAlgConstructor[freshAlgName](savedir=None, 
                    algParams=algP, outputParams=outP, seed=seed)

  targetLP, evBound = learnAlg.fit(freshModel, targetData)
  targetSS = freshModel.get_global_suff_stats(targetData, targetLP)
  
  if doSimpleThrTest:
    Nthr = np.maximum(100, 0.05 * targetData.nObs)
    rejectIDs = np.flatnonzero(targetSS.N < Nthr)
    rejectIDs = np.sort(rejectIDs)[::-1]
    for kreject in rejectIDs:
      targetSS.removeComp(kreject)
    
  elif curModel is not None:
    targetSS = clean_up_fresh_model(targetData, curModel, freshModel, 
                            randstate=randstate, **kwargs)

  if targetSS.K < 2:
    msg = 'BIRTH: Did not create >1 useful comps. TargetData size %d'
    raise BirthProposalError(msg % (targetData.nObs))

  if doRemoveRedundant:
    targetSS = clean_up_expanded_suff_stats(targetData, curModel, targetSS,
                            randstate=randstate, **kwargs)

  if kwargs['cleanupModifyOrigComps']:
    didCreateNewComps = (curModel.obsModel.K - targetSS.K) >= 1
  else:
    didCreateNewComps = targetSS.K >= 1

  if not didCreateNewComps:
      msg = 'BIRTH: Did not create any new comps after cleanup.'
      raise BirthProposalError(msg)
  return targetSS
dataset/ETHPy150Open daeilkim/refinery/refinery/bnpy/bnpy-dev/bnpy/learnalg/BirthMove.py/learn_fresh_model/swapped operands of `-`