code: def intrinsic_causal_influence_sample(
      causal_model: InvertibleStructuralCausalModel,
      target_node: Any,
      baseline_samples: pd.DataFrame,
      noise_feature_samples: Optional[pd.DataFrame] = None,
      prediction_model: Union[
          PredictionModel, ClassificationModel, str
      ] = "approx",
      subset_scoring_func: Optional[
          Callable[[np.ndarray, np.ndarray], Union[np.ndarray, float]]
      ] = None,
      num_noise_feature_samples: int = 5000,
      max_batch_size: int = 100,
      auto_assign_quality: auto.AssignmentQuality = auto.AssignmentQuality.GOOD,
      shapley_config: Optional[ShapleyConfig] = None,
  ) -> List[Dict[Any, Any]]:
      """Estimates the intrinsic causal impact of upstream nodes on a specified target_node, using the provided
      baseline_samples as a reference. In this context, observed values are attributed to the noise factors present in
      upstream nodes. Compared to intrinsic_causal_influence, this method quantifies the influences with respect to single
      observations instead of the distribution. Note that the current implementation only supports non-categorical data,
      since the noise terms need to be reconstructed.
  
      **Research Paper**:
      Janzing et al. *Quantifying causal contributions via structure preserving interventions*. arXiv:2007.00714, 2021.
  
      :param causal_model: The fitted invertible structural causal model.
      :param target_node: Node of interest.
      :param baseline_samples: Samples for which the influence should be estimated.
      :param noise_feature_samples: Optional noise samples of upstream nodes used as 'background' samples. If None is
                                    given, new noise samples are generated based on the graph. These samples are used for
                                    randomizing features that are not in the subset.
      :param prediction_model: Prediction model for estimating the functional relationship between subsets of ancestor
                               noise terms and the target node. This can be an instance of a PredictionModel, the string
                               'approx' or the string 'exact'. With 'exact', the underlying causal models in the graph
                               are utilized directly by propagating given noise inputs through the graph, which ensures
                               that generated samples follow the fitted models. In contrast, the 'approx' method involves
                               selecting and training a suitable model based on data sampled from the graph. This might
                               lead to deviations from the outcomes of the fitted models, but is faster and can be more
                               robust in certain settings.
      :param subset_scoring_func: Set function for estimating the quantity of interest based. This function
                                  expects two inputs; the outcome of the model for some samples if certain features are permuted and the
                                  outcome of the model for the same samples when no features were permuted. By default,
                                  the difference between means of these samples are estimated.
      :param num_noise_feature_samples: If no noise_feature_samples are given, noise samples are drawn from the graph.
                                        This parameter indicates how many.
      :param max_batch_size: Maximum batch size for estimating multiple predictions at once. This has a significant influence on the
                            overall memory usage. If set to -1, all samples are used in one batch.
      :param auto_assign_quality: Auto assign quality for the 'approx' prediction_model option.
      :param shapley_config: :class:`~dowhy.gcm.shapley.ShapleyConfig` for the Shapley estimator.
      :return: A list of dictionaries indicating the intrinsic causal influence of a node on the target for a particular
               sample. This is, each dictionary belongs to one baseline sample.
      """
      validate_node(causal_model.graph, target_node)
      causal_model = InvertibleStructuralCausalModel(
          node_connected_subgraph_view(causal_model.graph, target_node)
      )
  
      (
          feature_samples,
          tmp_noise_feature_samples,
      ) = noise_samples_of_ancestors(
          causal_model, target_node, num_noise_feature_samples
      )
  
      if has_categorical(feature_samples.to_numpy()):
          raise ValueError(
              "The current implementation requires all variables to be numeric, i.e., non-categorical! "
              "There is at least one node in the graph that is categorical."
          )
  
      if noise_feature_samples is None:
          noise_feature_samples = tmp_noise_feature_samples
  
      if subset_scoring_func is None:
          subset_scoring_func = means_difference
  
      target_samples = feature_samples[target_node].to_numpy()
      node_names = noise_feature_samples.columns
      noise_feature_samples, target_samples = shape_into_2d(
          noise_feature_samples.to_numpy(), target_samples
      )
  
      prediction_method = _get_icc_noise_function(
          causal_model,
          target_node,
          prediction_model,
          noise_feature_samples,
          node_names,
          target_samples,
          auto_assign_quality,
          False,  # Currently only supports continues target since we need to reconstruct its noise term.
      )
  
      shapley_vales = feature_relevance_sample(
          prediction_method,
          feature_samples=noise_feature_samples,
          baseline_samples=compute_noise_from_data(
              causal_model, baseline_samples
          )[node_names].to_numpy(),
          subset_scoring_func=subset_scoring_func,
          max_batch_size=max_batch_size,
          shapley_config=shapley_config,
      )
  
      return [
          {
              (predecessor, target_node): shapley_vales[i][q]
              for q, predecessor in enumerate(node_names)
          }
          for i in range(shapley_vales.shape[0])
      ]
  
imports: import logging
  import warnings
  from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union, cast
  import numpy
  import pandas
  from joblib import Parallel, delayed
  from numpy.matlib import repmat
  import dowhy.gcm.auto
  from dowhy.gcm import feature_relevance_sample
  from dowhy.gcm._noise import compute_data_from_noise, compute_noise_from_data, noise_samples_of_ancestors
  from dowhy.gcm.causal_mechanisms import ClassifierFCM, ConditionalStochasticModel, ProbabilityEstimatorModel
  from dowhy.gcm.causal_models import InvertibleStructuralCausalModel, ProbabilisticCausalModel, StructuralCausalModel, validate_causal_dag, validate_node
  from dowhy.gcm.divergence import estimate_kl_divergence_of_probabilities
  from dowhy.gcm.fitting_sampling import draw_samples
  from dowhy.gcm.ml import ClassificationModel, PredictionModel
  from dowhy.gcm.shapley import ShapleyConfig, estimate_shapley_values
  from dowhy.gcm.stats import marginal_expectation
  from dowhy.gcm.uncertainty import estimate_entropy_of_probabilities, estimate_variance
  from dowhy.gcm.util.general import has_categorical, is_categorical, means_difference, set_random_seed, shape_into_2d
  from dowhy.graph import get_ordered_predecessors, is_root_node, node_connected_subgraph_view
label_desc: Use image node_id 5 for calling a global function with example usage: intrinsic_causal_influence_sample(causal_model, target_node, baseline_samples, noise_feature_samples, prediction_model, subset_scoring_func, num_noise_feature_samples, max_batch_size, auto_assign_quality, shapley_config) and returns: unknown