code: def conditional_anomaly_scores(
      parent_samples: np.ndarray,
      target_samples: np.ndarray,
      causal_mechanism: ConditionalStochasticModel,
      anomaly_scorer_factory: Callable[
          [], AnomalyScorer
      ] = MedianCDFQuantileScorer,
      num_samples_conditional: int = 10000,
  ) -> np.ndarray:
      """Estimates the conditional anomaly scores based on the expected outcomes of the causal model.
  
      :param parent_samples: Samples from all parents of the target node.
      :param target_samples: Samples from the target node.
      :param causal_mechanism: Causal mechanism of the target node.
      :param anomaly_scorer_factory: A callable that returns an anomaly scorer.
      :param num_samples_conditional: Number of samples drawn from the conditional distribution based on the given
                                      parent samples. The more samples, the more accurate the results.
      :return: The conditional anomaly score for each sample in target_samples.
      """
      parent_samples, target_samples = shape_into_2d(
          parent_samples, target_samples
      )
      if parent_samples.shape[0] != target_samples.shape[0]:
          raise ValueError(
              "There should be as many parent samples as target samples!"
          )
  
      result = np.zeros(parent_samples.shape[0])
      for i in range(parent_samples.shape[0]):
          samples_from_conditional = causal_mechanism.draw_samples(
              repmat(parent_samples[i], num_samples_conditional, 1)
          )
          anomaly_scorer = anomaly_scorer_factory()
          anomaly_scorer.fit(samples_from_conditional)
          result[i] = anomaly_scorer.score(target_samples[i])[0]
  
      return result
  
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 1 for calling a global function with example usage: conditional_anomaly_scores(parent_samples, target_samples, causal_mechanism, anomaly_scorer_factory, num_samples_conditional) and returns: result