code: def test_adv_md(adv_md_params):
      # ModelDistillation parameters
      (
          threshold,
          loss_type,
          threshold_perc,
          return_instance_score,
      ) = adv_md_params
  
      # define ancillary model
      layers = [
          tf.keras.layers.InputLayer(input_shape=(input_dim)),
          tf.keras.layers.Dense(y.shape[1], activation=tf.nn.softmax),
      ]
      distilled_model = tf.keras.Sequential(layers)
  
      # init ModelDistillation detector
      admd = ModelDistillation(
          threshold=threshold,
          model=model,
          distilled_model=distilled_model,
          loss_type=loss_type,
      )
  
      assert admd.threshold == threshold
      assert admd.meta == {
          "name": "ModelDistillation",
          "detector_type": "adversarial",
          "data_type": None,
          "online": False,
          "version": __version__,
      }
      for layer in admd.model.layers:
          assert not layer.trainable
  
      # fit AdversarialVAE, infer threshold and compute scores
      admd.fit(X, epochs=5, verbose=False)
      admd.infer_threshold(X, threshold_perc=threshold_perc)
      iscore = admd.score(X)
      perc_score = (
          100
          * (iscore < admd.threshold).astype(int).sum()
          / iscore.shape[0]
      )
      assert threshold_perc + 1 > perc_score > threshold_perc - 1
  
      # make and check predictions
      ad_preds = admd.predict(
          X, return_instance_score=return_instance_score
      )
  
      assert ad_preds["meta"] == admd.meta
      if return_instance_score:
          assert (
              ad_preds["data"]["is_adversarial"].sum()
              == (ad_preds["data"]["instance_score"] > admd.threshold)
              .astype(int)
              .sum()
          )
      else:
          assert ad_preds["data"]["instance_score"] is None
  
file_path: alibi-detect/alibi_detect/ad/tests/test_admd.py
imports: from itertools import product
  import numpy
  import pytest
  from sklearn.datasets import load_iris
  import tensorflow
  from tensorflow.keras.utils import to_categorical
  from alibi_detect.ad import ModelDistillation
  from alibi_detect.version import __version__
label_desc: Use image node_id 2 for calling a global function with example usage: test_adv_md(adv_md_params) without return types