code: def feature_relevance_distribution(
      prediction_method: Callable[[np.ndarray], np.ndarray],
      feature_samples: np.ndarray,
      subset_scoring_func: Callable[
          [np.ndarray, np.ndarray], Union[np.ndarray, float]
      ],
      max_num_samples_randomization: int = 5000,
      max_num_baseline_samples: int = 500,
      max_batch_size: int = 100,
      randomize_features_jointly: bool = True,
      shapley_config: Optional[ShapleyConfig] = None,
  ) -> np.ndarray:
      """Estimates the population based feature relevance of the input features for the given prediction_method. This
      method uses all samples given in feature_samples by comparing the output of the prediction_method given certain
      features are randomized with the outputs when no features are randomized. The subset_scoring_func defines
      how these predictions are compared. For instance, the variance of deviations.
  
      If the randomized predictions should rather be compared to the original data, this has (and can) be defined via
      the set function by ignoring the second input parameter (the predicted values using all feauters). Instead, the
      original data can be used.
  
      Note: The distribution level relevance is estimated by taking the expectation of the outcome of the set functions
      when applied to multiple samples. Due to the linearity of the Shapley value estimation, this is equivalent to taking
      the expectation over the Shapley values.
  
      Related paper:
      Janzing, D., Minorics, L., & Bloebaum, P. (2020).
      Feature relevance quantification in explainable AI: A causal problem.
      In International Conference on Artificial Intelligence and Statistics (pp. 2907-2916). PMLR.
  
      :param prediction_method: A callable that is expected to return a prediction for given samples.
      :param feature_samples: Samples from the joint distribution.
      :param subset_scoring_func: Set function for estimating the quantity of interest based on the model outcomes. This function
                                  expects two inputs; the outcome of the prediction model for some samples if certain features are permuted and the
                                  outcome of the model for the same samples when no features were permuted. The set functions represents the
                                  comparison between the samples, for instance, the variance of deviations. This is then used as the 'characteristic function'
                                  in coalition games when estimating the Shapley values.
      :param max_num_samples_randomization: Maximum number of samples used for randomizing the feature that are not in the susbet. Consider increasing this
                                            number for more accurate results (if enough samples are available) or reducing it for less memory consumption and
                                            faster runtime.
      :param max_num_baseline_samples: Maximum number of samples on which the set function is evaluated on. These samples are used as fixed observations for
                                       features that are in the subset. For instance, in case of taking the mean as set_function_summary_func, this defines the maximum number
                                       of samples used to estimate the mean. Consider increasing this number for more accurate results (if enough samples are
                                       available) or reducing it for less memory consumption and faster runtime.
      :param max_batch_size: Maximum batch size for a estimating the predictions. This has a significant influence on the
                             overall memory usage. If set to -1, all samples are used in one batch.
      :param randomize_features_jointly: If set to True, features that are not in a subset are jointly permuted.
                                         Note that this still represents an interventional distribution. If set to False, features that are not in a subset
                                         are independently permuted. Note: The theory in the linked publication assumes that this is set to True.
      :param shapley_config: Config for the Shapley estimator.
      :return: A numpy array with the feature relevance of each input feature.
      """
      feature_samples = shape_into_2d(feature_samples)
  
      if shapley_config is None:
          shapley_config = ShapleyConfig()
  
      baseline_samples = feature_samples[
          np.random.choice(
              feature_samples.shape[0],
              min(max_num_baseline_samples, feature_samples.shape[0]),
              replace=False,
          )
      ]
      feature_samples = feature_samples[
          np.random.choice(
              feature_samples.shape[0],
              min(
                  max_num_samples_randomization,
                  feature_samples.shape[0],
              ),
              replace=False,
          )
      ]
  
      return feature_relevance_sample(
          prediction_method,
          feature_samples,
          baseline_samples,
          subset_scoring_func,
          None,
          True,
          max_batch_size,
          randomize_features_jointly,
          shapley_config,
      )
  
file_path: dowhy/dowhy/gcm/feature_relevance.py
imports: from typing import Any, Callable, Dict, Optional, Tuple, Union
  import numpy
  import pandas
  from dowhy.gcm.causal_mechanisms import ProbabilityEstimatorModel
  from dowhy.gcm.causal_models import StructuralCausalModel, validate_node
  from dowhy.gcm.fitting_sampling import draw_samples
  from dowhy.gcm.shapley import ShapleyConfig, estimate_shapley_values
  from dowhy.gcm.stats import marginal_expectation
  from dowhy.gcm.util.general import shape_into_2d, variance_of_deviations, variance_of_matching_values
  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: feature_relevance_distribution(prediction_method, feature_samples, subset_scoring_func, max_num_samples_randomization, max_num_baseline_samples, max_batch_size, randomize_features_jointly, shapley_config) and returns: feature_relevance_sample