class_docstr: Search structure which gives speedup at slight loss of recall.
  
  Uses cluster pruning structure as defined in:
  http://nlp.stanford.edu/IR-book/html/htmledition/cluster-pruning-1.html
  
  tldr - searching for a document in an index of K documents is naievely
      O(K). However you can create a tree structure where the first level
      is O(sqrt(K)) and each of the leaves are also O(sqrt(K)).
  
      You randomly pick sqrt(K) items to be in the top level. Then for
      the K doccuments you assign it to the closest neighbor in the top
      level.
  
      This breaks up one O(K) search into O(2 * sqrt(K)) searches which
      is much much faster when K is big.
  
      This generalizes to h levels. The runtime becomes:
          O(h * h_root(K))
class_docstr_tok: ["Search","structure","which","gives","speedup","at","slight","loss","of","recall",".","Uses","cluster","pruning","structure","as","defined","in",":","http",":","\/\/nlp.stanford.edu\/IR-book\/html\/htmledition\/cluster-pruning-1.html","tldr","-","searching","for","a","document","in","an","index","of","K","documents","is","naievely","O","(","K",")",".","However","you","can","create","a","tree","structure","where","the","first","level","is","O","(","sqrt","(","K",")",")","and","each","of","the","leaves","are","also","O","(","sqrt","(","K",")",")",".","You","randomly","pick","sqrt","(","K",")","items","to","be","in","the","top","level",".","Then","for","the","K","doccuments","you","assign","it","to","the","closest","neighbor","in","the","top","level",".","This","breaks","up","one","O","(","K",")","search","into","O","(","2","*","sqrt","(","K",")",")","searches","which","is","much","much","faster","when","K","is","big",".","This","generalizes","to","h","levels",".","The","runtime","becomes",":","O","(","h","*","h_root","(","K",")",")"]
docstr: Find the closest item(s) for each feature_list in.
  
  Args:
      features: A matrix with rows that represent records
          (corresponding to the elements in records_data) and columns
          that describe a point in space for each row.
      k: Return the k closest results.
      k_clusters: number of branches (clusters) to search at each level.
          This increases recall at the cost of some speed.
  
  Returns:
      For each element in features_list, return the k-nearest items
      and their distance score
      [[(score1_1, item1_1), ..., (score1_k, item1_k)],
       [(score2_1, item2_1), ..., (score2_k, item2_k)], ...]
docstr_tok: ["Find","the","closest","item","(","s",")","for","each","feature_list","in",".","Args",":","features",":","A","matrix","with","rows","that","represent","records","(","corresponding","to","the","elements","in","records_data",")","and","columns","that","describe","a","point","in","space","for","each","row",".","k",":","Return","the","k","closest","results",".","k_clusters",":","number","of","branches","(","clusters",")","to","search","at","each","level",".","This","increases","recall","at","the","cost","of","some","speed",".","Returns",":","For","each","element","in","features_list",",","return","the","k-nearest","items","and","their","distance","score","[","[","(","score1_1",",","item1_1",")",",","...",",","(","score1_k",",","item1_k",")","]",",","[","(","score2_1",",","item2_1",")",",","...",",","(","score2_k",",","item2_k",")","]",",","...","]"]
code: def _search(self, features, k=1, k_clusters=1):
      """Find the closest item(s) for each feature_list in.
  
      Args:
          features: A matrix with rows that represent records
              (corresponding to the elements in records_data) and columns
              that describe a point in space for each row.
          k: Return the k closest results.
          k_clusters: number of branches (clusters) to search at each level.
              This increases recall at the cost of some speed.
  
      Returns:
          For each element in features_list, return the k-nearest items
          and their distance score
          [[(score1_1, item1_1), ..., (score1_k, item1_k)],
           [(score2_1, item2_1), ..., (score2_k, item2_k)], ...]
      """
      if self.is_terminal:
          nearest = self.root.nearest_search(features)
          return [r[:k] for r in nearest]
      else:
          ret = []
          nearest = self.root.nearest_search(features)
  
          for search_i, nearest_clusters in enumerate(nearest):
              curr_ret = []
  
              for cluster_i, distance_cluster in enumerate(
                  nearest_clusters
              ):
                  distance, cluster = distance_cluster
                  cluster_items = cluster.search(
                      features[search_i], k=k, k_clusters=k_clusters
                  )
  
                  for elements in cluster_items:
                      if len(elements) > 0:
                          curr_ret.extend(elements)
  
                  # if we have k elements and we have searched at least
                  # k_clusters then we are done
                  if len(curr_ret) >= k and cluster_i + 1 >= k_clusters:
                      break
  
              ret.append(_k_best(curr_ret, k))
          return ret
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import collections
  import random
  import numpy
  import pysparnn.matrix_distance
label_desc: Use image node_id 5 for calling the ClusterIndex obj's underlying member method code with example usage: obj._search(features, k, k_clusters) and returns: unknown, ret