def select_birth_component(SS, K=None, targetSelectName='sizebiased', 
                           randstate=np.random, emptyTHR=100,
                           lapsSinceLastBirth=defaultdict(int),
                           excludeList=list(), doVerbose=False, **kwargs):
  ''' Choose a single component among indices {1,2,3, ... K-1, K}
      to target with a birth proposal.
  '''
  if SS is None:
    targetSelectName = 'uniform'
    assert K is not None
  elif K is None:
    K = SS.K
  else:
    assert K == SS.K
  
  if len(excludeList) >= K:
    raise BirthProposalError('BIRTH not possible. All possible K=%d targets used or excluded.' % (K))  
  ps = np.zeros(K)
  if targetSelectName == 'uniform':
    ps = np.ones(K)
  elif targetSelectName == 'sizebiased':
    if hasattr(SS, 'Nmajor'):
      ps = SS.Nmajor.copy()
    else:
      ps = SS.N.copy()
    ps[SS.N < emptyTHR] = 0
  elif targetSelectName == 'delaybiased':
    # Bias choice towards components that have not been selected in a long time
    lapDist = np.asarray([lapsSinceLastBirth[kk] for kk in range(K)])
    ps = np.maximum(lapDist + 1e-5, 0)
    ps = ps * ps
  elif targetSelectName == 'delayandsizebiased':
    # Bias choice towards components that have not been selected in a long time
    #  *and* which have many members
    lapDist = np.asarray([lapsSinceLastBirth[kk] for kk in range(K)])
    ps = np.maximum(lapDist + 1e-5, 0)
    if hasattr(SS, 'Nmajor'):
      ps = ps * SS.Nmajor
    else:
      ps = ps * SS.N
    ps[SS.N < emptyTHR] = 0
  else:
    raise NotImplementedError('Unrecognized procedure: ' + targetSelectName)
  # Make final selection via random draw
  ps[excludeList] = 0
  if np.sum(ps) < EPS:
    raise BirthProposalError('BIRTH not possible. All possible target comps have zero probability.')
  sortIDs = np.argsort(ps)[::-1]
  if doVerbose:
    for kk in sortIDs[:6]:
      print "comp %3d : %.2f prob | %3d delay | %8d size" % (kk, ps[kk]/sum(ps), lapsSinceLastBirth[kk], SS.N[kk])
  kbirth = discrete_single_draw(ps, randstate)
  return kbirth





###########################################################  Visualization
###########################################################
dataset/ETHPy150Open daeilkim/refinery/refinery/bnpy/bnpy-dev/bnpy/learnalg/BirthMove.py/select_birth_component/original