def subsample_data(DataObj, LP, targetCompID, targetProbThr=0.1,
                    maxTargetObs=100, maxTargetSize=100, randstate=np.random, 
                    subsampleroutine='keepentiredocuments', **kwargs):
  ''' 
    Select a subsample of the given dataset
      which is primarily associated with component "targetCompID"
      via a simple thresholding procedure
    
    Args
    -------
    DataObj : bnpy dataset object, with nObs observations
    LP : local param dict, containing fields
          resp : nObs x K matrix
    targetCompID : integer within {0, 1, ... K-1}
    ...
    TODO
    
    Returns
    -------
    new DataObj that contains a subset of the data
  '''
  if 'word_variational' in LP:
    # -------------------------------------- WordsData code
    if subsampleroutine == 'keeponlymatchingwords':
      mask = LP['word_variational'][: , targetCompID] > targetProbThr
      TargetData = DataObj.select_subset_by_mask(wordMask=np.flatnonzero(mask),
                                                doTrackFullSize=False)    
    elif subsampleroutine == 'keepentiredocuments':
      # Ndk : empirical doc-topic distribution
      #       rows sum to one
      if 'DocTopicFrac' in LP:
        Ndk = LP['DocTopicFrac']            
      else:
        Ndk = LP['DocTopicCount'].copy()
        Ndk /= np.sum(Ndk,axis=1)[:,np.newaxis]
      docmask = Ndk[:, targetCompID] > targetProbThr
      docIDs = np.flatnonzero(docmask)
      if docIDs.size == 0:
        return None
      # Select at most maxTargetSize of these docs, uniformly at random
      randstate.shuffle(docIDs)
      docIDs = docIDs[:maxTargetSize]
  
      TargetData = DataObj.select_subset_by_mask(docMask=docIDs,
                                                doTrackFullSize=False)    
  else:
    # -------------------------------------- XData code
    mask = LP['resp'][: , targetCompID] > targetProbThr
    objIDs = np.flatnonzero(mask)
    randstate.shuffle(objIDs)
    targetObjIDs = objIDs[:maxTargetObs]
    TargetData = DataObj.select_subset_by_mask(targetObjIDs, 
                                                doTrackFullSize=False)
  return TargetData

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