class_docstr: Projects a vector on n first principal components and assigns
  a discrete value to each projection depending on the bin.
class_docstr_tok: ["Projects","a","vector","on","n","first","principal","components","and","assigns","a","discrete","value","to","each","projection","depending","on","the","bin","."]
docstr: Computes principal components for training vector set. Uses
  first projection_count principal components for projections.
  
  Training set must be either a numpy matrix or a list of
  numpy vectors.
docstr_tok: ["Computes","principal","components","for","training","vector","set",".","Uses","first","projection_count","principal","components","for","projections",".","Training","set","must","be","either","a","numpy","matrix","or","a","list","of","numpy","vectors","."]
code: def __init__(
      self, hash_name, projection_count, training_set, bin_width
  ):
      """
      Computes principal components for training vector set. Uses
      first projection_count principal components for projections.
  
      Training set must be either a numpy matrix or a list of
      numpy vectors.
      """
      super(PCADiscretizedProjections, self).__init__(hash_name)
      self.projection_count = projection_count
      self.bin_width = bin_width
  
      # Only do training if training set was specified
      if not training_set is None:
          # Get numpy array representation of input
          training_set = numpy_array_from_list_or_numpy_array(
              training_set
          )
  
          # Get subspace size from training matrix
          self.dim = training_set.shape[0]
  
          # Get transposed training set matrix for PCA
          training_set_t = numpy.transpose(training_set)
  
          # Compute principal components
          (eigenvalues, eigenvectors) = perform_pca(training_set_t)
  
          # Get largest N eigenvalue/eigenvector indices
          largest_eigenvalue_indices = numpy.flipud(
              scipy.argsort(eigenvalues)
          )[:projection_count]
  
          # Create matrix for first N principal components
          self.components = numpy.zeros(
              (self.dim, len(largest_eigenvalue_indices))
          )
  
          # Put first N principal components into matrix
          for index in range(len(largest_eigenvalue_indices)):
              self.components[:, index] = eigenvectors[
                  :, largest_eigenvalue_indices[index]
              ]
  
          # We need the component vectors to be in the rows
          self.components = numpy.transpose(self.components)
  
      # This is only used in case we need to process sparse vectors
      self.components_csr = None
  
file_path: NearPy/nearpy/hashes/pcadiscretizedprojections.py
imports: import numpy
  import scipy
  import scipy.sparse
  from nearpy.hashes.lshash import LSHash
  from nearpy.utils import numpy_array_from_list_or_numpy_array, perform_pca
label_desc: Use image node_id 1 to create a new PCADiscretizedProjections object from inherited base classes: LSHash with example: obj = PCADiscretizedProjections(hash_name, projection_count, training_set, bin_width)