class_docstr: Search structure which provides query speedup at the loss of recall.
  
  There are two components to this.
  
  = Cluster Indexes =
  Uses cluster pruning index structure as defined in:
  http://nlp.stanford.edu/IR-book/html/htmledition/cluster-pruning-1.html
  
  Refer to ClusterIndex documentation.
  
  = Multiple Indexes =
  The MultiClusterIndex creates multiple ClusterIndexes. This method
  gives better recall at the cost of allocating more memory. The
  ClusterIndexes are created by randomly picking representative clusters.
  The randomization tends to do a pretty good job but it is not perfect.
  Elements can be assigned to clusters that are far from an optimal match.
  Creating more Indexes (random cluster allocations) increases the chances
  of finding a good match.
  
  There are three perameters that impact recall. Will discuss them all
  here:
  1) MuitiClusterIndex(matrix_size)
      This impacts the tree structure (see cluster index documentation).
      Has a good default value. By increasing this value your index will
      behave increasingly like brute force search and you will loose query
      efficiency. If matrix_size is greater than your number of records
      you get brute force search.
  2) MuitiClusterIndex.search(k_clusters)
      Number of clusters to check when looking for records. This increases
      recall at the cost of query speed. Can be specified dynamically.
  3) MuitiClusterIndex(num_indexes)
      Number of indexes to generate. This increases recall at the cost of
      query speed. It also increases memory usage. It can only be
      specified at index construction time.
  
      Compared to (2) this argument gives better recall and has comparable
      speed. This statement assumes default (automatic) matrix_size is
      used.
       Scenario 1:
  
       (a) num_indexes=2, k_clusters=1
       (b) num_indexes=1, k_clusters=2
  
       (a) will have better recall but consume 2x the memory. (a) will be
       slightly slower than (b).
  
       Scenario 2:
  
       (a) num_indexes=2, k_clusters=1, matrix_size >> records
       (b) num_indexes=1, k_clusters=2, matrix_size >> records
  
       This means that each index does a brute force search. (a) and (b)
       will have the same recall. (a) will be 2x slower than (b). (a) will
       consume 2x the memory of (b).
  
       Scenario 1 will be much faster than Scenario 2 for large data.
       Scenario 2 will have better recall than Scenario 1.
class_docstr_tok: ["Search","structure","which","provides","query","speedup","at","the","loss","of","recall",".","There","are","two","components","to","this",".","=","Cluster","Indexes","=","Uses","cluster","pruning","index","structure","as","defined","in",":","http",":","\/\/nlp.stanford.edu\/IR-book\/html\/htmledition\/cluster-pruning-1.html","Refer","to","ClusterIndex","documentation",".","=","Multiple","Indexes","=","The","MultiClusterIndex","creates","multiple","ClusterIndexes",".","This","method","gives","better","recall","at","the","cost","of","allocating","more","memory",".","The","ClusterIndexes","are","created","by","randomly","picking","representative","clusters",".","The","randomization","tends","to","do","a","pretty","good","job","but","it","is","not","perfect",".","Elements","can","be","assigned","to","clusters","that","are","far","from","an","optimal","match",".","Creating","more","Indexes","(","random","cluster","allocations",")","increases","the","chances","of","finding","a","good","match",".","There","are","three","perameters","that","impact","recall",".","Will","discuss","them","all","here",":","1",")","MuitiClusterIndex","(","matrix_size",")","This","impacts","the","tree","structure","(","see","cluster","index","documentation",")",".","Has","a","good","default","value",".","By","increasing","this","value","your","index","will","behave","increasingly","like","brute","force","search","and","you","will","loose","query","efficiency",".","If","matrix_size","is","greater","than","your","number","of","records","you","get","brute","force","search",".","2",")","MuitiClusterIndex.search","(","k_clusters",")","Number","of","clusters","to","check","when","looking","for","records",".","This","increases","recall","at","the","cost","of","query","speed",".","Can","be","specified","dynamically",".","3",")","MuitiClusterIndex","(","num_indexes",")","Number","of","indexes","to","generate",".","This","increases","recall","at","the","cost","of","query","speed",".","It","also","increases","memory","usage",".","It","can","only","be","specified","at","index","construction","time",".","Compared","to","(","2",")","this","argument","gives","better","recall","and","has","comparable","speed",".","This","statement","assumes","default","(","automatic",")","matrix_size","is","used",".","Scenario","1",":","(","a",")","num_indexes=2",",","k_clusters=1","(","b",")","num_indexes=1",",","k_clusters=2","(","a",")","will","have","better","recall","but","consume","2x","the","memory",".","(","a",")","will","be","slightly","slower","than","(","b",")",".","Scenario","2",":","(","a",")","num_indexes=2",",","k_clusters=1",",","matrix_size",">",">","records","(","b",")","num_indexes=1",",","k_clusters=2",",","matrix_size",">",">","records","This","means","that","each","index","does","a","brute","force","search",".","(","a",")","and","(","b",")","will","have","the","same","recall",".","(","a",")","will","be","2x","slower","than","(","b",")",".","(","a",")","will","consume","2x","the","memory","of","(","b",")",".","Scenario","1","will","be","much","faster","than","Scenario","2","for","large","data",".","Scenario","2","will","have","better","recall","than","Scenario","1","."]
docstr: Find the closest item(s) for each feature_list in the index.
  
  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
          within each index. This increases recall at the cost of some
          speed.
  
      num_indexes: number of indexes to search. This increases recall at
          the cost of some speed. Can not be larger than the number of
          num_indexes that was specified in the constructor. Defaults to
          searching all indexes.
  
  Returns:
      For each element in features_list, return the k-nearest items
      and (optionally) their distance score
      [[(score1_1, item1_1), ..., (score1_k, item1_k)],
       [(score2_1, item2_1), ..., (score2_k, item2_k)], ...]
  
      Note: if return_distance == False then the scores are omitted
      [[item1_1, ..., item1_k],
       [item2_1, ..., item2_k], ...]
docstr_tok: ["Find","the","closest","item","(","s",")","for","each","feature_list","in","the","index",".","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","within","each","index",".","This","increases","recall","at","the","cost","of","some","speed",".","num_indexes",":","number","of","indexes","to","search",".","This","increases","recall","at","the","cost","of","some","speed",".","Can","not","be","larger","than","the","number","of","num_indexes","that","was","specified","in","the","constructor",".","Defaults","to","searching","all","indexes",".","Returns",":","For","each","element","in","features_list",",","return","the","k-nearest","items","and","(","optionally",")","their","distance","score","[","[","(","score1_1",",","item1_1",")",",","...",",","(","score1_k",",","item1_k",")","]",",","[","(","score2_1",",","item2_1",")",",","...",",","(","score2_k",",","item2_k",")","]",",","...","]","Note",":","if","return_distance","==","False","then","the","scores","are","omitted","[","[","item1_1",",","...",",","item1_k","]",",","[","item2_1",",","...",",","item2_k","]",",","...","]"]
code: def search(
      self,
      features,
      k=1,
      k_clusters=1,
      return_distance=True,
      num_indexes=None,
  ):
      """Find the closest item(s) for each feature_list in the index.
  
      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
              within each index. This increases recall at the cost of some
              speed.
  
          num_indexes: number of indexes to search. This increases recall at
              the cost of some speed. Can not be larger than the number of
              num_indexes that was specified in the constructor. Defaults to
              searching all indexes.
  
      Returns:
          For each element in features_list, return the k-nearest items
          and (optionally) their distance score
          [[(score1_1, item1_1), ..., (score1_k, item1_k)],
           [(score2_1, item2_1), ..., (score2_k, item2_k)], ...]
  
          Note: if return_distance == False then the scores are omitted
          [[item1_1, ..., item1_k],
           [item2_1, ..., item2_k], ...]
      """
      results = []
      if num_indexes is None:
          num_indexes = len(self.indexes)
      for ind in self.indexes[:num_indexes]:
          results.append(ind.search(features, k, k_clusters, True))
      ret = []
      for r in _np.hstack(results):
          ret.append(
              _filter_distance(
                  _k_best(_filter_unique(r), k), return_distance
              )
          )
  
      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 3 for calling the MultiClusterIndex obj's underlying member method code with example usage: obj.search(features, k, k_clusters, return_distance, num_indexes) and returns: ret