code: def noise_samples_of_ancestors(
      causal_model: StructuralCausalModel,
      target_node: Any,
      num_samples: int,
  ) -> Tuple[pd.DataFrame, pd.DataFrame]:
      sorted_nodes = list(nx.topological_sort(causal_model.graph))
      all_ancestors_of_node = nx.ancestors(
          causal_model.graph, target_node
      )
      all_ancestors_of_node.update({target_node})
  
      drawn_samples = pd.DataFrame(
          np.empty((num_samples, len(sorted_nodes))),
          columns=sorted_nodes,
      )
      drawn_noise_samples = pd.DataFrame(
          np.empty((num_samples, len(sorted_nodes))),
          columns=sorted_nodes,
      )
  
      for node in sorted_nodes:
          if node not in all_ancestors_of_node:
              continue
  
          if is_root_node(causal_model.graph, node):
              noise = (
                  causal_model.causal_mechanism(node)
                  .draw_samples(num_samples)
                  .reshape(-1)
              )
              drawn_noise_samples[node] = noise.squeeze()
              drawn_samples[node] = noise.squeeze()
          else:
              noise = (
                  causal_model.causal_mechanism(node)
                  .draw_noise_samples(num_samples)
                  .reshape(-1)
              )
              drawn_noise_samples[node] = noise.squeeze()
              drawn_samples[node] = (
                  causal_model.causal_mechanism(node)
                  .evaluate(
                      _parent_samples_of(
                          node, causal_model, drawn_samples
                      ),
                      noise,
                  )
                  .squeeze()
              )
  
          if node == target_node:
              break
  
      return drawn_samples, drawn_noise_samples
  
file_path: dowhy/dowhy/gcm/_noise.py
imports: from typing import Any, Callable, List, Optional, Tuple
  import networkx
  import numpy
  import pandas
  from dowhy.gcm.causal_models import InvertibleStructuralCausalModel, ProbabilisticCausalModel, StructuralCausalModel, validate_causal_dag
  from dowhy.gcm.ml.prediction_model import PredictionModel
  from dowhy.gcm.util.general import shape_into_2d
  from dowhy.graph import get_ordered_predecessors, is_root_node, node_connected_subgraph_view
label_desc: Use image node_id 6 for calling a global function with example usage: noise_samples_of_ancestors(causal_model, target_node, num_samples) and returns: drawn_samples,  drawn_noise_samples