class_docstr: Drift detector based on the partial MMD Distance.
  (see T. Viehmann: Partial Wasserstein and Maximum Mean Discrepancy distances
  for bridging the gap between outlier detection and drift detection,
  https://arxiv.org/abs/2106.01289 )
  Note: We recommend using dtype double as input for now.
  
  Args:
       fraction_to_match: fraction of x probability mass to be matched
       n_perm: number of bootstrap permutations to run to compute p-value (None for not returning a p-value)
       method: PartialKernelMMDDriftDetector.METHOD_TWOSTAGE, METHOD_APPROX, or METHOD_QP
class_docstr_tok: ["Drift","detector","based","on","the","partial","MMD","Distance",".","(","see","T.","Viehmann",":","Partial","Wasserstein","and","Maximum","Mean","Discrepancy","distances","for","bridging","the","gap","between","outlier","detection","and","drift","detection",",","https",":","\/\/arxiv.org\/abs\/2106.01289",")","Note",":","We","recommend","using","dtype","double","as","input","for","now",".","Args",":","fraction_to_match",":","fraction","of","x","probability","mass","to","be","matched","n_perm",":","number","of","bootstrap","permutations","to","run","to","compute","p-value","(","None","for","not","returning","a","p-value",")","method",":","PartialKernelMMDDriftDetector.METHOD_TWOSTAGE",",","METHOD_APPROX",",","or","METHOD_QP"]
docstr: Record a sample as the reference distribution
  
  Args:
      x: The reference data
      n_test: If an int is specified, the last n_test datapoints
          will not be considered part of the reference data. Instead,
          bootstrappin using permutations will be used to determine
          the distribution under the null hypothesis at fit time.
          Future testing must then always be done with n_test elements
          to get p-values.
docstr_tok: ["Record","a","sample","as","the","reference","distribution","Args",":","x",":","The","reference","data","n_test",":","If","an","int","is","specified",",","the","last","n_test","datapoints","will","not","be","considered","part","of","the","reference","data",".","Instead",",","bootstrappin","using","permutations","will","be","used","to","determine","the","distribution","under","the","null","hypothesis","at","fit","time",".","Future","testing","must","then","always","be","done","with","n_test","elements","to","get","p-values","."]
code: def fit(self, x: torch.Tensor, n_test: Optional[int] = None):
      """Record a sample as the reference distribution
  
      Args:
          x: The reference data
          n_test: If an int is specified, the last n_test datapoints
              will not be considered part of the reference data. Instead,
              bootstrappin using permutations will be used to determine
              the distribution under the null hypothesis at fit time.
              Future testing must then always be done with n_test elements
              to get p-values.
      """
      x = x.detach()
      if n_test is None:
          self.base_outputs = x
      else:
          torchdrift.utils.check(
              0 < n_test < x.size(0),
              "n_test must be strictly between 0 and the number of samples",
          )
          self.n_test = n_test
          self.base_outputs = x[:-n_test]
  
          n_ref = x.size(0) - n_test
          with_distant_point = self.fraction_to_match < 1.0
  
          scores = []
          for i in range(self.n_perm):
              slicing = torch.randperm(x.size(0))
              scores.append(
                  self.partial_mmd(
                      x[slicing[:-n_test]],
                      x[slicing[-n_test:]],
                      fraction_to_match=self.fraction_to_match,
                      kernel=self.kernel,
                  )
              )
          scores = torch.stack(scores)
  
          self.scores = scores
  
          self.dist_min = scores.min().double()
          mean = scores.mean() - self.dist_min
          var = scores.var().double()
          self.dist_alpha = mean**2 / var
          self.dist_beta = mean / var
          self.scores = scores
      return x
  
file_path: TorchDrift/torchdrift/detectors/partial_mmd.py
imports: from typing import Optional
  import torch
  from .mmd import GaussianKernel
  from .detector import Detector
  import torchdrift
  import warnings
label_desc: Use image node_id 2 for calling the PartialKernelMMDDriftDetector obj's underlying member method code with example usage: obj.fit(x, n_test) and returns: x