code: def anomaly_scores(
      causal_model: ProbabilisticCausalModel,
      anomaly_data: pd.DataFrame,
      num_samples_conditional: int = 10000,
      num_samples_unconditional: int = 10000,
      anomaly_scorer_factory: Callable[
          [], AnomalyScorer
      ] = RescaledMedianCDFQuantileScorer,
  ) -> Dict[Any, np.ndarray]:
      if isinstance(anomaly_data, pd.Series):
          anomaly_data = pd.DataFrame([anomaly_data])
  
      validate_causal_dag(causal_model.graph)
  
      results = {}
      for node in tqdm(
          causal_model.graph.nodes,
          desc="Estimating conditional anomaly scores",
          position=0,
          leave=True,
          disable=not config.show_progress_bars,
      ):
          if is_root_node(causal_model.graph, node):
              anomaly_scorer = anomaly_scorer_factory()
              anomaly_scorer.fit(
                  causal_model.causal_mechanism(node).draw_samples(
                      num_samples_unconditional
                  )
              )
              results[node] = anomaly_scorer.score(
                  anomaly_data[node].to_numpy()
              )
          else:
              tmp_anomaly_parent_samples = anomaly_data[
                  get_ordered_predecessors(causal_model.graph, node)
              ].to_numpy()
              tmp_anomaly_target_samples = anomaly_data[node].to_numpy()
              results[node] = conditional_anomaly_scores(
                  tmp_anomaly_parent_samples,
                  tmp_anomaly_target_samples,
                  causal_model.causal_mechanism(node),
                  anomaly_scorer_factory,
                  num_samples_conditional,
              )
  
      return results
  
file_path: dowhy/dowhy/gcm/anomaly.py
imports: from typing import Any, Callable, Dict, Optional, Union
  import numpy
  import pandas
  from numpy.matlib import repmat
  from tqdm import tqdm
  from dowhy.gcm import config
  from dowhy.gcm._noise import compute_noise_from_data, get_noise_dependent_function, noise_samples_of_ancestors
  from dowhy.gcm.anomaly_scorer import AnomalyScorer
  from dowhy.gcm.anomaly_scorers import MedianCDFQuantileScorer, RescaledMedianCDFQuantileScorer
  from dowhy.gcm.causal_mechanisms import ConditionalStochasticModel
  from dowhy.gcm.causal_models import InvertibleStructuralCausalModel, ProbabilisticCausalModel, validate_causal_dag
  from dowhy.gcm.shapley import ShapleyConfig, estimate_shapley_values
  from dowhy.gcm.stats import permute_features
  from dowhy.gcm.util.general import shape_into_2d
  from dowhy.graph import get_ordered_predecessors, is_root_node
label_desc: Use image node_id 2 for calling a global function with example usage: anomaly_scores(causal_model, anomaly_data, num_samples_conditional, num_samples_unconditional, anomaly_scorer_factory) and returns: results