class_docstr: Finds an estimate for the manifold of given feature vectors.
class_docstr_tok: ["Finds","an","estimate","for","the","manifold","of","given","feature","vectors","."]
docstr: Evaluate if new feature vectors are in the estimated manifold.
docstr_tok: ["Evaluate","if","new","feature","vectors","are","in","the","estimated","manifold","."]
code: def evaluate(
      self, eval_features, return_realism=False, return_neighbors=False
  ):
      """Evaluate if new feature vectors are in the estimated manifold."""
      num_eval_images = eval_features.shape[0]
      num_ref_images = self.D.shape[0]
      distance_batch = np.zeros(
          [self.row_batch_size, num_ref_images], dtype=np.float16
      )
      batch_predictions = np.zeros(
          [num_eval_images, self.num_nhoods], dtype=np.int32
      )
      # max_realism_score = np.zeros([num_eval_images,], dtype=np.float32)
      realism_score = np.zeros(
          [
              num_eval_images,
          ],
          dtype=np.float32,
      )
      nearest_indices = np.zeros(
          [
              num_eval_images,
          ],
          dtype=np.int32,
      )
  
      for begin1 in range(0, num_eval_images, self.row_batch_size):
          end1 = min(begin1 + self.row_batch_size, num_eval_images)
          feature_batch = eval_features[begin1:end1]
  
          for begin2 in range(0, num_ref_images, self.col_batch_size):
              end2 = min(begin2 + self.col_batch_size, num_ref_images)
              ref_batch = self._ref_features[begin2:end2]
  
              distance_batch[
                  0 : end1 - begin1, begin2:end2
              ] = self._distance_block.pairwise_distances(
                  feature_batch, ref_batch
              )
  
          # From the minibatch of new feature vectors, determine if they are in the estimated manifold.
          # If a feature vector is inside a hypersphere of some reference sample, then the new sample lies on the estimated manifold.
          # The radii of the hyperspheres are determined from distances of neighborhood size k.
          samples_in_manifold = (
              distance_batch[0 : end1 - begin1, :, None] <= self.D
          )
          batch_predictions[begin1:end1] = np.any(
              samples_in_manifold, axis=1
          ).astype(np.int32)
  
          # max_realism_score[begin1:end1] = np.max(self.D[:, 0] / (distance_batch[0:end1-begin1, :] + 1e-18), axis=1)
          # nearest_indices[begin1:end1] = np.argmax(self.D[:, 0] / (distance_batch[0:end1-begin1, :] + 1e-18), axis=1)
          nearest_indices[begin1:end1] = np.argmin(
              distance_batch[0 : end1 - begin1, :], axis=1
          )
          realism_score[begin1:end1] = self.D[
              nearest_indices[begin1:end1], 0
          ] / np.min(distance_batch[0 : end1 - begin1, :], axis=1)
  
      if return_realism and return_neighbors:
          return batch_predictions, realism_score, nearest_indices
      elif return_realism:
          return batch_predictions, realism_score
      elif return_neighbors:
          return batch_predictions, nearest_indices
  
      return batch_predictions
  
file_path: insightface/reconstruction/ostec/external/stylegan2/metrics/precision_recall.py
imports: import os
  import numpy
  import tensorflow
  import dnnlib
  import dnnlib.tflib
  from metrics import metric_base
  from training import misc
label_desc: Use image node_id 2 for calling the ManifoldEstimator obj's underlying member method code with example usage: obj.evaluate(eval_features, return_realism, return_neighbors) and returns: batch_predictions, batch_predictions,  realism_score,  nearest_indices, batch_predictions,  realism_score, batch_predictions,  nearest_indices