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