docstr: Compute the out-of-fold drift metric such as the accuracy from a classifier
  trained to distinguish the reference data from the data to be tested.
  
  Parameters
  ----------
  x
      Batch of instances.
  
  Returns
  -------
  p-value, a notion of distance between the trained classifier's out-of-fold performance         and that which we'd expect under the null assumption of no drift,         and the out-of-fold classifier model prediction probabilities on the reference and test data         as well as the associated reference and test instances of the out-of-fold predictions.
docstr_tok: ["Compute","the","out-of-fold","drift","metric","such","as","the","accuracy","from","a","classifier","trained","to","distinguish","the","reference","data","from","the","data","to","be","tested",".","Parameters","--","--","--","--","--","x","Batch","of","instances",".","Returns","--","--","--","-","p-value",",","a","notion","of","distance","between","the","trained","classifier","'s","out-of-fold","performance","and","that","which","we","'d","expect","under","the","null","assumption","of","no","drift",",","and","the","out-of-fold","classifier","model","prediction","probabilities","on","the","reference","and","test","data","as","well","as","the","associated","reference","and","test","instances","of","the","out-of-fold","predictions","."]
code: def score(
      self, x: Union[np.ndarray, list]
  ) -> Tuple[
      float,
      float,
      np.ndarray,
      np.ndarray,
      Union[np.ndarray, list],
      Union[np.ndarray, list],
  ]:
      """
          Compute the out-of-fold drift metric such as the accuracy from a classifier
          trained to distinguish the reference data from the data to be tested.
  
          Parameters
          ----------
          x
              Batch of instances.
  
          Returns
          -------
          p-value, a notion of distance between the trained classifier's out-of-fold performance \
          and that which we'd expect under the null assumption of no drift, \
          and the out-of-fold classifier model prediction probabilities on the reference and test data \
          as well as the associated reference and test instances of the out-of-fold predictions.
          """
      x_ref, x = self.preprocess(x)
      x, y, splits = self.get_splits(x_ref, x)  # type: ignore
  
      # iterate over folds: train a new model for each fold and make out-of-fold (oof) predictions
      preds_oof_list, idx_oof_list = [], []
      for idx_tr, idx_te in splits:
          y_tr = y[idx_tr]
          if isinstance(x, np.ndarray):
              x_tr, x_te = x[idx_tr], x[idx_te]
          elif isinstance(x, list):
              x_tr, x_te = [x[_] for _ in idx_tr], [
                  x[_] for _ in idx_te
              ]
          else:
              raise TypeError(
                  f"x needs to be of type np.ndarray or list and not {type(x)}."
              )
          ds_tr = self.dataset(x_tr, y_tr)
          dl_tr = self.dataloader(ds_tr)
          self.model = (
              deepcopy(self.original_model)
              if self.retrain_from_scratch
              else self.model
          )
          self.model = self.model.to(self.device)
          train_args = [self.model, self.loss_fn, dl_tr, self.device]
          trainer(*train_args, **self.train_kwargs)  # type: ignore
          preds = self.predict_fn(x_te, self.model.eval())
          preds_oof_list.append(preds)
          idx_oof_list.append(idx_te)
      preds_oof = np.concatenate(preds_oof_list, axis=0)
      probs_oof = (
          softmax(preds_oof, axis=-1)
          if self.preds_type == "logits"
          else preds_oof
      )
      idx_oof = np.concatenate(idx_oof_list, axis=0)
      y_oof = y[idx_oof]
      n_cur = y_oof.sum()
      n_ref = len(y_oof) - n_cur
      p_val, dist = self.test_probs(y_oof, probs_oof, n_ref, n_cur)
      idx_sort = np.argsort(idx_oof)
      probs_sort = probs_oof[idx_sort]
      if isinstance(x, np.ndarray):
          x_oof = x[idx_oof]
          x_sort = x_oof[idx_sort]
      else:
          x_oof = [x[_] for _ in idx_oof]
          x_sort = [x_oof[_] for _ in idx_sort]
      return (
          p_val,
          dist,
          probs_sort[:n_ref, 1],
          probs_sort[n_ref:, 1],
          x_sort[:n_ref],
          x_sort[n_ref:],
      )
  
imports: from copy import deepcopy
  from functools import partial
  import numpy
  import torch
  import torch.nn
  from torch.utils.data import DataLoader
  from scipy.special import softmax
  from typing import Callable, Dict, Optional, Union, Tuple
  from alibi_detect.cd.base import BaseClassifierDrift
  from alibi_detect.models.pytorch.trainer import trainer
  from alibi_detect.utils.pytorch import get_device
  from alibi_detect.utils.pytorch.data import TorchDataset
  from alibi_detect.utils.pytorch.prediction import predict_batch
  from alibi_detect.utils.warnings import deprecated_alias
  from alibi_detect.utils.frameworks import Framework
  from alibi_detect.utils._types import TorchDeviceType
label_desc: Use image node_id 2 for calling the ClassifierDriftTorch obj's underlying member method code with example usage: obj.score(x) and returns: p_val,  dist,  probs_sort,  probs_sort,  x_sort,  x_sort