class_docstr: Base class for all Directed Graphical Models.
  
  Each node in the graph can represent either a random variable, `Factor`,
  or a cluster of random variables. Edges in the graph represent the
  dependencies between these.
  
  Parameters
  ----------
  data: input graph
      Data to initialize graph. If data=None (default) an empty graph is
      created. The data can be an edge list or any Networkx graph object.
  
  Examples
  --------
  Create an empty DAG with no nodes and no edges
  
  >>> from pgmpy.base import DAG
  >>> G = DAG()
  
  G can be grown in several ways:
  
  **Nodes:**
  
  Add one node at a time:
  
  >>> G.add_node(node='a')
  
  Add the nodes from any container (a list, set or tuple or the nodes
  from another graph).
  
  >>> G.add_nodes_from(nodes=['a', 'b'])
  
  **Edges:**
  
  G can also be grown by adding edges.
  
  Add one edge,
  
  >>> G.add_edge(u='a', v='b')
  
  a list of edges,
  
  >>> G.add_edges_from(ebunch=[('a', 'b'), ('b', 'c')])
  
  If some edges connect nodes not yet in the model, the nodes
  are added automatically. There are no errors when adding
  nodes or edges that already exist.
  
  **Shortcuts:**
  
  Many common graph features allow python syntax for speed reporting.
  
  >>> 'a' in G     # check if node in graph
  True
  >>> len(G)  # number of nodes in graph
  3
class_docstr_tok: ["Base","class","for","all","Directed","Graphical","Models",".","Each","node","in","the","graph","can","represent","either","a","random","variable",",","`","Factor","`",",","or","a","cluster","of","random","variables",".","Edges","in","the","graph","represent","the","dependencies","between","these",".","Parameters","--","--","--","--","--","data",":","input","graph","Data","to","initialize","graph",".","If","data=None","(","default",")","an","empty","graph","is","created",".","The","data","can","be","an","edge","list","or","any","Networkx","graph","object",".","Examples","--","--","--","--","Create","an","empty","DAG","with","no","nodes","and","no","edges",">",">",">","from","pgmpy.base","import","DAG",">",">",">","G","=","DAG","(",")","G","can","be","grown","in","several","ways",":","*","*","Nodes",":","*","*","Add","one","node","at","a","time",":",">",">",">","G.add_node","(","node=","'","a","'",")","Add","the","nodes","from","any","container","(","a","list",",","set","or","tuple","or","the","nodes","from","another","graph",")",".",">",">",">","G.add_nodes_from","(","nodes=","[","'","a","'",",","'","b","'","]",")","*","*","Edges",":","*","*","G","can","also","be","grown","by","adding","edges",".","Add","one","edge",",",">",">",">","G.add_edge","(","u=","'","a","'",",","v=","'","b","'",")","a","list","of","edges",",",">",">",">","G.add_edges_from","(","ebunch=","[","(","'","a","'",",","'","b","'",")",",","(","'","b","'",",","'","c","'",")","]",")","If","some","edges","connect","nodes","not","yet","in","the","model",",","the","nodes","are","added","automatically",".","There","are","no","errors","when","adding","nodes","or","edges","that","already","exist",".","*","*","Shortcuts",":","*","*","Many","common","graph","features","allow","python","syntax","for","speed","reporting",".",">",">",">","'","a","'","in","G","#","check","if","node","in","graph","True",">",">",">","len","(","G",")","#","number","of","nodes","in","graph","3"]
docstr: Applies the do operator to the graph and returns a new DAG with the
  transformed graph.
  
  The do-operator, do(X = x) has the effect of removing all edges from
  the parents of X and setting X to the given value x.
  
  Parameters
  ----------
  nodes : list, array-like
      The names of the nodes to apply the do-operator for.
  
  inplace: boolean (default: False)
      If inplace=True, makes the changes to the current object,
      otherwise returns a new instance.
  
  Returns
  -------
  Modified DAG: pgmpy.base.DAG
      A new instance of DAG modified by the do-operator
  
  Examples
  --------
  Initialize a DAG
  >>> graph = DAG()
  >>> graph.add_edges_from([('X', 'A'),
  ...                       ('A', 'Y'),
  ...                       ('A', 'B')])
  >>> # Applying the do-operator will return a new DAG with the desired structure.
  >>> graph_do_A = graph.do('A')
  >>> # Which we can verify is missing the edges we would expect.
  >>> graph_do_A.edges
  OutEdgeView([('A', 'B'), ('A', 'Y')])
  
  References
  ----------
  Causality: Models, Reasoning, and Inference, Judea Pearl (2000). p.70.
docstr_tok: ["Applies","the","do","operator","to","the","graph","and","returns","a","new","DAG","with","the","transformed","graph",".","The","do-operator",",","do","(","X","=","x",")","has","the","effect","of","removing","all","edges","from","the","parents","of","X","and","setting","X","to","the","given","value","x.","Parameters","--","--","--","--","--","nodes",":","list",",","array-like","The","names","of","the","nodes","to","apply","the","do-operator","for",".","inplace",":","boolean","(","default",":","False",")","If","inplace=True",",","makes","the","changes","to","the","current","object",",","otherwise","returns","a","new","instance",".","Returns","--","--","--","-","Modified","DAG",":","pgmpy.base.DAG","A","new","instance","of","DAG","modified","by","the","do-operator","Examples","--","--","--","--","Initialize","a","DAG",">",">",">","graph","=","DAG","(",")",">",">",">","graph.add_edges_from","(","[","(","'","X","'",",","'","A","'",")",",","...","(","'","A","'",",","'","Y","'",")",",","...","(","'","A","'",",","'","B","'",")","]",")",">",">",">","#","Applying","the","do-operator","will","return","a","new","DAG","with","the","desired","structure",".",">",">",">","graph_do_A","=","graph.do","(","'","A","'",")",">",">",">","#","Which","we","can","verify","is","missing","the","edges","we","would","expect",".",">",">",">","graph_do_A.edges","OutEdgeView","(","[","(","'","A","'",",","'","B","'",")",",","(","'","A","'",",","'","Y","'",")","]",")","References","--","--","--","--","--","Causality",":","Models",",","Reasoning",",","and","Inference",",","Judea","Pearl","(","2000",")",".","p.70","."]
code: def do(self, nodes, inplace=False):
      """
      Applies the do operator to the graph and returns a new DAG with the
      transformed graph.
  
      The do-operator, do(X = x) has the effect of removing all edges from
      the parents of X and setting X to the given value x.
  
      Parameters
      ----------
      nodes : list, array-like
          The names of the nodes to apply the do-operator for.
  
      inplace: boolean (default: False)
          If inplace=True, makes the changes to the current object,
          otherwise returns a new instance.
  
      Returns
      -------
      Modified DAG: pgmpy.base.DAG
          A new instance of DAG modified by the do-operator
  
      Examples
      --------
      Initialize a DAG
      >>> graph = DAG()
      >>> graph.add_edges_from([('X', 'A'),
      ...                       ('A', 'Y'),
      ...                       ('A', 'B')])
      >>> # Applying the do-operator will return a new DAG with the desired structure.
      >>> graph_do_A = graph.do('A')
      >>> # Which we can verify is missing the edges we would expect.
      >>> graph_do_A.edges
      OutEdgeView([('A', 'B'), ('A', 'Y')])
  
      References
      ----------
      Causality: Models, Reasoning, and Inference, Judea Pearl (2000). p.70.
      """
      dag = self if inplace else self.copy()
  
      if isinstance(nodes, (str, int)):
          nodes = [nodes]
      else:
          nodes = list(nodes)
  
      if not set(nodes).issubset(set(self.nodes())):
          raise ValueError(
              f"Nodes not found in the model: {set(nodes) - set(self.nodes)}"
          )
  
      for node in nodes:
          parents = list(dag.predecessors(node))
          for parent in parents:
              dag.remove_edge(parent, node)
      return dag
  
imports: import itertools
  import networkx
  import numpy
  from pgmpy.base import UndirectedGraph
  from pgmpy.global_vars import logger
  from pgmpy.independencies import Independencies
label_desc: Use image node_id 22 for calling the DAG obj's underlying member method code with example usage: obj.do(nodes, inplace) and returns: dag