class_docstr: The stochastic greedy algorithm for optimization.
  
  The stochastic greedy algorithm is a simple approach that, for each 
  iteration, randomly selects a subset of data and then finds the best next 
  example within that subset. The distinction between this approach and the 
  sample greedy algorithm is that this subset changes at each iteration, 
  meaning that the algorithm does cover the entire data set. In contrast, 
  the sample greedy algorithm is equivalent to manually subsampling the data 
  before running a selector on it. The size of this subset is proportional 
  to the number of examples that are chosen and determined in a manner that 
  results in the same amount of computation being done no matter how many 
  elements are selected. A key idea from this approach is that, while the 
  exact ranking of the elements may differ from the naive/lazy greedy 
  approaches, the set of selected elements is likely to be similar despite 
  the limited amount of computation.
  
  .. code::python
  
          from apricot import FeatureBasedSelection
  
          X = numpy.random.randint(10, size=(10000, 100))
  
          selector = FeatureBasedSelection(100, 'sqrt', optimizer='stochastic')
          selector.fit(X)
  
  Parameters
  ----------
  self.function : base.BaseSelection
          A submodular function that implements the `_calculate_gains` and
          `_select_next` methods. This is the function that will be
          optimized.
  
  epsilon : float, optional
          The inverse of the sampling probability of any particular point being 
          included in the subset, such that 1 - epsilon is the probability that
          a point is included. Default is 0.9.
  
  random_state : int or RandomState or None, optional
          The random seed to use for the random selection process.
  
  self.verbose : bool
          Whether to display a progress bar during the optimization process.
  
  
  Attributes
  ----------
  self.function : base.BaseSelection
          A submodular function that implements the `_calculate_gains` and
          `_select_next` methods. This is the function that will be
          optimized.
  
  self.verbose : bool
          Whether to display a progress bar during the optimization process.
  
  self.gains_ : numpy.ndarray or None
          The gain that each example would give the last time that it was
          evaluated.
class_docstr_tok: ["The","stochastic","greedy","algorithm","for","optimization",".","The","stochastic","greedy","algorithm","is","a","simple","approach","that",",","for","each","iteration",",","randomly","selects","a","subset","of","data","and","then","finds","the","best","next","example","within","that","subset",".","The","distinction","between","this","approach","and","the","sample","greedy","algorithm","is","that","this","subset","changes","at","each","iteration",",","meaning","that","the","algorithm","does","cover","the","entire","data","set",".","In","contrast",",","the","sample","greedy","algorithm","is","equivalent","to","manually","subsampling","the","data","before","running","a","selector","on","it",".","The","size","of","this","subset","is","proportional","to","the","number","of","examples","that","are","chosen","and","determined","in","a","manner","that","results","in","the","same","amount","of","computation","being","done","no","matter","how","many","elements","are","selected",".","A","key","idea","from","this","approach","is","that",",","while","the","exact","ranking","of","the","elements","may","differ","from","the","naive\/lazy","greedy","approaches",",","the","set","of","selected","elements","is","likely","to","be","similar","despite","the","limited","amount","of","computation",".","..","code",":",":python","from","apricot","import","FeatureBasedSelection","X","=","numpy.random.randint","(","10",",","size=","(","10000",",","100",")",")","selector","=","FeatureBasedSelection","(","100",",","'sqrt","'",",","optimizer='stochastic","'",")","selector.fit","(","X",")","Parameters","--","--","--","--","--","self.function",":","base.BaseSelection","A","submodular","function","that","implements","the","`","_calculate_gains","`","and","`","_select_next","`","methods",".","This","is","the","function","that","will","be","optimized",".","epsilon",":","float",",","optional","The","inverse","of","the","sampling","probability","of","any","particular","point","being","included","in","the","subset",",","such","that","1","-","epsilon","is","the","probability","that","a","point","is","included",".","Default","is","0.9.","random_state",":","int","or","RandomState","or","None",",","optional","The","random","seed","to","use","for","the","random","selection","process",".","self.verbose",":","bool","Whether","to","display","a","progress","bar","during","the","optimization","process",".","Attributes","--","--","--","--","--","self.function",":","base.BaseSelection","A","submodular","function","that","implements","the","`","_calculate_gains","`","and","`","_select_next","`","methods",".","This","is","the","function","that","will","be","optimized",".","self.verbose",":","bool","Whether","to","display","a","progress","bar","during","the","optimization","process",".","self.gains_",":","numpy.ndarray","or","None","The","gain","that","each","example","would","give","the","last","time","that","it","was","evaluated","."]
code: def select(self, X, k, sample_cost=None):
      cost = 0.0
      if sample_cost is None:
          sample_cost = numpy.ones(X.shape[0], dtype="float64")
  
      n = X.shape[0]
      subset_size = -numpy.log(self.epsilon) * n / k
      subset_size = max(int(subset_size), 1)
  
      while cost < k:
          idxs = self.random_state.choice(
              self.function.idxs,
              replace=False,
              size=min(subset_size, self.function.idxs.shape[0]),
          )
  
          gains = (
              self.function._calculate_gains(X, idxs)
              / sample_cost[idxs]
          )
          idxs_ = numpy.lexsort((numpy.arange(gains.shape[0]), -gains))
  
          for idx in idxs_:
              best_idx = idxs[idx]
              if cost + sample_cost[best_idx] <= k:
                  break
          else:
              return
  
          cost += sample_cost[best_idx]
          self.function._select_next(X[best_idx], gains[idx], best_idx)
  
          if self.verbose == True:
              self.function.pbar.update(1)
  
imports: import os
  import copy
  import numpy
  import scipy
  from tqdm import tqdm
  from .utils import PriorityQueue
  from .utils import check_random_state
  from .utils import _calculate_pairwise_distances
label_desc: Use image node_id 2 for calling the StochasticGreedy obj's underlying member method code with example usage: obj.select(X, k, sample_cost) without return types