docstr: Likelihood Ratios for Out-of-Distribution Detection. Ren, J. et al. NeurIPS 2019.
  https://arxiv.org/abs/1906.02845
  
  Parameters
  ----------
  threshold
      Threshold used for the likelihood ratio (LLR) to determine outliers.
  model
      Generative model, defaults to PixelCNN.
  model_background
      Optional model for the background. Only needed if it is different from `model`.
  log_prob
      Function used to evaluate log probabilities under the model
      if the model does not have a `log_prob` function.
  sequential
      Whether the data is sequential. Used to create targets during training.
  data_type
      Optionally specify the data type (tabular, image or time-series). Added to metadata.
docstr_tok: ["Likelihood","Ratios","for","Out-of-Distribution","Detection",".","Ren",",","J.","et","al",".","NeurIPS","2019.","https",":","\/\/arxiv.org\/abs\/1906.02845","Parameters","--","--","--","--","--","threshold","Threshold","used","for","the","likelihood","ratio","(","LLR",")","to","determine","outliers",".","model","Generative","model",",","defaults","to","PixelCNN",".","model_background","Optional","model","for","the","background",".","Only","needed","if","it","is","different","from","`","model","`",".","log_prob","Function","used","to","evaluate","log","probabilities","under","the","model","if","the","model","does","not","have","a","`","log_prob","`","function",".","sequential","Whether","the","data","is","sequential",".","Used","to","create","targets","during","training",".","data_type","Optionally","specify","the","data","type","(","tabular",",","image","or","time-series",")",".","Added","to","metadata","."]
code: def __init__(
      self,
      threshold: float = None,
      model: Union[tf.keras.Model, Distribution, PixelCNN] = None,
      model_background: Union[
          tf.keras.Model, Distribution, PixelCNN
      ] = None,
      log_prob: Callable = None,
      sequential: bool = False,
      data_type: str = None,
  ) -> None:
      """
      Likelihood Ratios for Out-of-Distribution Detection. Ren, J. et al. NeurIPS 2019.
      https://arxiv.org/abs/1906.02845
  
      Parameters
      ----------
      threshold
          Threshold used for the likelihood ratio (LLR) to determine outliers.
      model
          Generative model, defaults to PixelCNN.
      model_background
          Optional model for the background. Only needed if it is different from `model`.
      log_prob
          Function used to evaluate log probabilities under the model
          if the model does not have a `log_prob` function.
      sequential
          Whether the data is sequential. Used to create targets during training.
      data_type
          Optionally specify the data type (tabular, image or time-series). Added to metadata.
      """
      super().__init__()
  
      if threshold is None:
          logger.warning(
              "No threshold level set. Need to infer threshold using `infer_threshold`."
          )
  
      self.has_log_prob = True if hasattr(model, "log_prob") else False
      self.sequential = sequential
      self.log_prob = log_prob
      self.threshold = threshold
  
      # semantic model trained on original data
      self.dist_s = model
      # background model trained on perturbed data
      if model_background is None:
          try:
              self.dist_b = model.copy()
          except AttributeError:
              self.dist_b = tf.keras.models.clone_model(model)
      else:
          self.dist_b = model_background
  
      # set metadata
      self.meta["detector_type"] = "outlier"
      self.meta["data_type"] = data_type
      self.meta["online"] = False
  
imports: from functools import partial
  import logging
  import numpy
  import tensorflow
  from tensorflow.keras.layers import Input
  from tensorflow.keras.models import Model
  from tensorflow_probability.python.distributions.distribution import Distribution
  from typing import Callable, Dict, Tuple, Union
  from alibi_detect.models.tensorflow.pixelcnn import PixelCNN
  from alibi_detect.models.tensorflow.trainer import trainer
  from alibi_detect.base import BaseDetector, FitMixin, ThresholdMixin, outlier_prediction_dict
  from alibi_detect.utils.tensorflow.prediction import predict_batch
  from alibi_detect.utils.tensorflow.perturbation import mutate_categorical
  from alibi_detect.utils._types import OptimizerTF
label_desc: Use image node_id 1 to create a new LLR object from inherited base classes: BaseDetector, FitMixin, ThresholdMixin with example: obj = LLR(threshold, model, model_background, log_prob, sequential, data_type)