code: def _interventional_samples(
      pcm: ProbabilisticCausalModel,
      observed_data: pd.DataFrame,
      interventions: Dict[Any, Callable[[np.ndarray], np.ndarray]],
  ) -> pd.DataFrame:
      samples = observed_data.copy()
  
      affected_nodes = _get_nodes_affected_by_intervention(
          pcm.graph, interventions.keys()
      )
      sorted_nodes = nx.topological_sort(pcm.graph)
  
      # Simulating interventions by propagating the effects through the graph. For this, we iterate over the nodes based
      # on their topological order.
      for node in sorted_nodes:
          if node not in affected_nodes:
              continue
  
          if is_root_node(pcm.graph, node):
              node_data = samples[node].to_numpy()
          else:
              node_data = pcm.causal_mechanism(node).draw_samples(
                  _parent_samples_of(node, pcm, samples)
              )
  
          # After drawing samples of the node based on the data generation process, we apply the corresponding
          # intervention. The inputs of downstream nodes are therefore based on the outcome of the intervention in this
          # node.
          samples[node] = _evaluate_intervention(
              node, interventions, node_data.reshape(-1)
          )
  
      return samples
  
file_path: dowhy/dowhy/gcm/whatif.py
imports: from typing import Any, Callable, Dict, Iterable, List, Optional, Union
  import networkx
  import numpy
  import pandas
  from dowhy.gcm._noise import compute_noise_from_data
  from dowhy.gcm.causal_mechanisms import ClassifierFCM
  from dowhy.gcm.causal_models import InvertibleStructuralCausalModel, ProbabilisticCausalModel, StructuralCausalModel, validate_causal_dag
  from dowhy.gcm.fitting_sampling import draw_samples
  from dowhy.graph import DirectedGraph, get_ordered_predecessors, is_root_node, node_connected_subgraph_view, validate_node_in_graph
label_desc: Use image node_id 2 for calling a global function with example usage: _interventional_samples(pcm, observed_data, interventions) and returns: samples