code: def detect_anomalies(
      series,
      anomaly_threshold=0.01,
      use_gibbs_predictive_dist=False,
      num_warmup_steps=50,
      num_samples=100,
      jit_compile=False,
      seed=None,
  ):
      """Detects anomalies in a Pandas time series using a default seasonal model.
  
      This function fits a `LocalLinearTrend` model with automatically determined
      seasonal effects, and returns a predictive credible interval at each step
      of the series. The fitting is done via Gibbs sampling, implemented
      specifically for this model class, which sometimes gives useful results more
      quickly than other fitting methods such as VI or HMC.
  
      Args:
        series: a Pandas `pd.Series` or `pd.DataFrame` instance indexed by a
          `pd.DateTimeIndex`. This may be irregular (missing timesteps) and/or
          contain unobserved steps indicated by `NaN` values (`NaN` values may also
          be provided to indicate future steps at which a forecast is desired).
          Multiple columns in a `pd.DataFrame` will generate results with a batch
          dimension.
        anomaly_threshold: float, confidence level for anomaly detection. An
            anomaly will be detected if the observed series falls outside the
            equal-tailed credible interval containing `(1 - anomaly_threshold)` of
            the posterior predictive probability mass.
        use_gibbs_predictive_dist: Python `bool`. If `True`, the predictive
          distribution is derived from Gibbs samples of the latent level, which
          incorporate information from the entire series *including future
          timesteps*. Otherwise, the predictive distribution is the 'filtering'
          distribution in which (conditioned on sampled parameters) the prediction
          at each step depends only on values observed at previous steps.
          Default value: `False`.
        num_warmup_steps: `int` number of steps to take before starting to collect
          samples.
          Default value: `50`.
        num_samples: `int` number of steps to take while sampling parameter
          values.
          Default value: `100`.
        jit_compile: Python `bool`. If `True`, compile the sampler with XLA. This
          adds overhead to the first call, but may speed up subsequent calls with
          series of the same shape and frequency.
          Default value: `True`.
        seed: PRNG seed; see `tfp.random.sanitize_seed` for details.
      Returns:
        prediction_output: instance of `PredictionOutput` named tuple containing
          the predicted credible intervals for each point (omitting the first) in
          the series.
      """
      regularized_series = regularization.regularize_series(series)
      observed_time_series = (
          sts_util.canonicalize_observed_time_series_with_mask(
              regularized_series
          )
      )
      anomaly_threshold = tf.convert_to_tensor(
          anomaly_threshold,
          dtype=observed_time_series.time_series.dtype,
          name="anomaly_threshold",
      )
  
      seasonal_structure = seasonality_util.create_seasonal_structure(
          frequency=regularized_series.index.freq,
          num_steps=len(regularized_series),
      )
      # Convert SeasonType keys into strings, because `tf.function` doesn't like
      # enum-valued arguments.
      seasonal_structure = {
          str(k): v for (k, v) in seasonal_structure.items()
      }
      inner_fn = (
          _detect_anomalies_inner_compiled
          if jit_compile
          else _detect_anomalies_inner
      )
      lower_limit, upper_limit, mean, tail_probabilities = inner_fn(
          observed_time_series,
          seasonal_structure=seasonal_structure,
          anomaly_threshold=anomaly_threshold,
          use_gibbs_predictive_dist=use_gibbs_predictive_dist,
          num_warmup_steps=num_warmup_steps,
          num_samples=num_samples,
          seed=seed,
      )
      return PredictionOutput(
          times=regularized_series.index,
          observed_time_series=observed_time_series.time_series[..., 0],
          mean=mean,
          lower_limit=lower_limit,
          upper_limit=upper_limit,
          tail_probabilities=tail_probabilities,
          is_anomaly=tail_probabilities < anomaly_threshold,
      )
  
imports: import collections
  import datetime
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import inverse_gamma
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.experimental.sts_gibbs import gibbs_sampler
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.math import root_search
  from tensorflow_probability.python.sts import default_model
  from tensorflow_probability.python.sts import regularization
  from tensorflow_probability.python.sts.forecast import one_step_predictive
  from tensorflow_probability.python.sts.internal import seasonality_util
  from tensorflow_probability.python.sts.internal import util
label_desc: Use image node_id 1 for calling a global function with example usage: detect_anomalies(series, anomaly_threshold, use_gibbs_predictive_dist, num_warmup_steps, num_samples, jit_compile, seed) and returns: PredictionOutput