OOD_LLR#

class dataeval.detectors.ood.OOD_LLR(model: PixelCNN, model_background: PixelCNN | None = None, log_prob: Callable | None = None, sequential: bool = False)#

Likelihood Ratios based outlier detector.

Parameters:
  • model (PixelCNN) – Generative distribution model.

  • model_background (Optional[PixelCNN], default None) – Optional model for the background. Only needed if it is different from model.

  • log_prob (Optional[Callable], default None) – Function used to evaluate log probabilities under the model if the model does not have a log_prob function.

  • sequential (bool, default False) – Whether the data is sequential. Used to create targets during training.

fit(x_ref: ArrayLike, threshold_perc: float = 100.0, loss_fn: ~typing.Callable | None = None, optimizer: ~tf_keras.src.optimizers.optimizer.Optimizer = <class 'tf_keras.src.optimizers.adam.Adam'>, epochs: int = 20, batch_size: int = 64, verbose: bool = True, mutate_fn: ~typing.Callable = <function mutate_categorical>, mutate_fn_kwargs: dict = {'feature_range': (0, 255), 'rate': 0.2, 'seed': 0}, mutate_batch_size: int = 10000000000) None#

Train semantic and background generative models.

Parameters:
  • x_ref (ArrayLike) – Training data.

  • threshold_perc (float, default 100.0) – Percentage of reference data that is normal.

  • loss_fn (Callable | None, default None) – Loss function used for training.

  • optimizer (keras.optimizers.Optimizer, default keras.optimizers.Adam) – Optimizer used for training.

  • epochs (int, default 20) – Number of training epochs.

  • batch_size (int, default 64) – Batch size used for training.

  • verbose (bool, default True) – Whether to print training progress.

  • mutate_fn (Callable, default mutate_categorical) – Mutation function used to generate the background dataset.

  • mutate_fn_kwargs (dict, default {"rate": 0.2, "seed": 0, "feature_range": (0, 255)}) – Kwargs for the mutation function used to generate the background dataset. Default values set for an image dataset.

  • mutate_batch_size (int, default int(1e10)) – Batch size used to generate the mutations for the background dataset.

predict(X: ArrayLike, batch_size: int = 10000000000, ood_type: Literal['feature', 'instance'] = 'instance') OODOutput#

Predict whether instances are out-of-distribution or not.

Parameters:
  • X (ArrayLike) – Input data for out-of-distribution prediction.

  • batch_size (int, default 1e10) – Number of instances to process in each batch.

  • ood_type ("feature" | "instance", default "instance") – Predict out-of-distribution at the ‘feature’ or ‘instance’ level.

Returns:

  • Dictionary containing the outlier predictions for the selected level,

  • and the OOD scores for the data including both ‘instance’ and ‘feature’ (if present) level scores.

score(X: ArrayLike, batch_size: int = 10000000000) OODScoreOutput#

Compute the out-of-distribution (OOD) scores for a given dataset.

Parameters:
  • X (ArrayLike) – Input data to score.

  • batch_size (int, default 1e10) – Number of instances to process in each batch. Use a smaller batch size if your dataset is large or if you encounter memory issues.

Returns:

An object containing the instance-level and feature-level OOD scores.

Return type:

OODScoreOutput