class_docstr: Base class for all the Undirected Graphical models.
  
  Each node in the graph can represent either a random variable, `Factor`,
  or a cluster of random variables. Edges in the graph are interactions
  between the nodes.
  
  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 UndirectedGraph with no nodes and no edges
  
  >>> from pgmpy.base import UndirectedGraph
  >>> G = UndirectedGraph()
  
  G can be grown in several ways
  
  **Nodes:**
  
  Add one node at a time:
  
  >>> G.add_node('a')
  
  Add the nodes from any container (a list, set or tuple or the nodes
  from another graph).
  
  >>> G.add_nodes_from(['a', 'b'])
  
  **Edges:**
  
  G can also be grown by adding edges.
  
  Add one edge,
  
  >>> G.add_edge('a', 'b')
  
  a list of edges,
  
  >>> G.add_edges_from([('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","the","Undirected","Graphical","models",".","Each","node","in","the","graph","can","represent","either","a","random","variable",",","`","Factor","`",",","or","a","cluster","of","random","variables",".","Edges","in","the","graph","are","interactions","between","the","nodes",".","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","UndirectedGraph","with","no","nodes","and","no","edges",">",">",">","from","pgmpy.base","import","UndirectedGraph",">",">",">","G","=","UndirectedGraph","(",")","G","can","be","grown","in","several","ways","*","*","Nodes",":","*","*","Add","one","node","at","a","time",":",">",">",">","G.add_node","(","'","a","'",")","Add","the","nodes","from","any","container","(","a","list",",","set","or","tuple","or","the","nodes","from","another","graph",")",".",">",">",">","G.add_nodes_from","(","[","'","a","'",",","'","b","'","]",")","*","*","Edges",":","*","*","G","can","also","be","grown","by","adding","edges",".","Add","one","edge",",",">",">",">","G.add_edge","(","'","a","'",",","'","b","'",")","a","list","of","edges",",",">",">",">","G.add_edges_from","(","[","(","'","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: Add all the edges in ebunch.
  
  If nodes referred in the ebunch are not already present, they
  will be automatically added. Node names can be any hashable python
  object.
  
  **The behavior of adding weights is different than networkx.
  
  Parameters
  ----------
  ebunch : container of edges
      Each edge given in the container will be added to the graph.
      The edges must be given as 2-tuples (u, v).
  
  weights: list, tuple (default=None)
      A container of weights (int, float). The weight value at index i
      is associated with the edge at index i.
  
  Examples
  --------
  >>> from pgmpy.base import UndirectedGraph
  >>> G = UndirectedGraph()
  >>> G.add_nodes_from(nodes=['Alice', 'Bob', 'Charles'])
  >>> G.add_edges_from(ebunch=[('Alice', 'Bob'), ('Bob', 'Charles')])
  >>> G.nodes()
  NodeView(('Alice', 'Bob', 'Charles'))
  >>> G.edges()
  EdgeView([('Alice', 'Bob'), ('Bob', 'Charles')])
  
  When the node is not already in the model:
  >>> G.add_edges_from(ebunch=[('Alice', 'Ankur')])
  >>> G.nodes()
  NodeView(('Alice', 'Ankur', 'Charles', 'Bob'))
  >>> G.edges()
  EdgeView([('Alice', 'Bob'), ('Bob', 'Charles'), ('Alice', 'Ankur')])
  
  Adding edges with weights:
  >>> G.add_edges_from([('Ankur', 'Maria'), ('Maria', 'Mason')],
  ...                  weights=[0.3, 0.5])
  >>> G.edge['Ankur']['Maria']
  {'weight': 0.3}
  >>> G.edge['Maria']['Mason']
  {'weight': 0.5}
docstr_tok: ["Add","all","the","edges","in","ebunch",".","If","nodes","referred","in","the","ebunch","are","not","already","present",",","they","will","be","automatically","added",".","Node","names","can","be","any","hashable","python","object",".","*","*","The","behavior","of","adding","weights","is","different","than","networkx",".","Parameters","--","--","--","--","--","ebunch",":","container","of","edges","Each","edge","given","in","the","container","will","be","added","to","the","graph",".","The","edges","must","be","given","as","2-tuples","(","u",",","v",")",".","weights",":","list",",","tuple","(","default=None",")","A","container","of","weights","(","int",",","float",")",".","The","weight","value","at","index","i","is","associated","with","the","edge","at","index","i",".","Examples","--","--","--","--",">",">",">","from","pgmpy.base","import","UndirectedGraph",">",">",">","G","=","UndirectedGraph","(",")",">",">",">","G.add_nodes_from","(","nodes=","[","'Alice","'",",","'Bob","'",",","'Charles","'","]",")",">",">",">","G.add_edges_from","(","ebunch=","[","(","'Alice","'",",","'Bob","'",")",",","(","'Bob","'",",","'Charles","'",")","]",")",">",">",">","G.nodes","(",")","NodeView","(","(","'Alice","'",",","'Bob","'",",","'Charles","'",")",")",">",">",">","G.edges","(",")","EdgeView","(","[","(","'Alice","'",",","'Bob","'",")",",","(","'Bob","'",",","'Charles","'",")","]",")","When","the","node","is","not","already","in","the","model",":",">",">",">","G.add_edges_from","(","ebunch=","[","(","'Alice","'",",","'Ankur","'",")","]",")",">",">",">","G.nodes","(",")","NodeView","(","(","'Alice","'",",","'Ankur","'",",","'Charles","'",",","'Bob","'",")",")",">",">",">","G.edges","(",")","EdgeView","(","[","(","'Alice","'",",","'Bob","'",")",",","(","'Bob","'",",","'Charles","'",")",",","(","'Alice","'",",","'Ankur","'",")","]",")","Adding","edges","with","weights",":",">",">",">","G.add_edges_from","(","[","(","'Ankur","'",",","'Maria","'",")",",","(","'Maria","'",",","'Mason","'",")","]",",","...","weights=","[","0.3",",","0.5","]",")",">",">",">","G.edge","[","'Ankur","'","]","[","'Maria","'","]","{","'weight","'",":","0.3","}",">",">",">","G.edge","[","'Maria","'","]","[","'Mason","'","]","{","'weight","'",":","0.5","}"]
code: def add_edges_from(self, ebunch, weights=None):
      """
      Add all the edges in ebunch.
  
      If nodes referred in the ebunch are not already present, they
      will be automatically added. Node names can be any hashable python
      object.
  
      **The behavior of adding weights is different than networkx.
  
      Parameters
      ----------
      ebunch : container of edges
          Each edge given in the container will be added to the graph.
          The edges must be given as 2-tuples (u, v).
  
      weights: list, tuple (default=None)
          A container of weights (int, float). The weight value at index i
          is associated with the edge at index i.
  
      Examples
      --------
      >>> from pgmpy.base import UndirectedGraph
      >>> G = UndirectedGraph()
      >>> G.add_nodes_from(nodes=['Alice', 'Bob', 'Charles'])
      >>> G.add_edges_from(ebunch=[('Alice', 'Bob'), ('Bob', 'Charles')])
      >>> G.nodes()
      NodeView(('Alice', 'Bob', 'Charles'))
      >>> G.edges()
      EdgeView([('Alice', 'Bob'), ('Bob', 'Charles')])
  
      When the node is not already in the model:
      >>> G.add_edges_from(ebunch=[('Alice', 'Ankur')])
      >>> G.nodes()
      NodeView(('Alice', 'Ankur', 'Charles', 'Bob'))
      >>> G.edges()
      EdgeView([('Alice', 'Bob'), ('Bob', 'Charles'), ('Alice', 'Ankur')])
  
      Adding edges with weights:
      >>> G.add_edges_from([('Ankur', 'Maria'), ('Maria', 'Mason')],
      ...                  weights=[0.3, 0.5])
      >>> G.edge['Ankur']['Maria']
      {'weight': 0.3}
      >>> G.edge['Maria']['Mason']
      {'weight': 0.5}
      """
      ebunch = list(ebunch)
  
      if weights:
          if len(ebunch) != len(weights):
              raise ValueError(
                  "The number of elements in ebunch and weights"
                  "should be equal"
              )
          for index in range(len(ebunch)):
              self.add_edge(
                  ebunch[index][0],
                  ebunch[index][1],
                  weight=weights[index],
              )
      else:
          for edge in ebunch:
              self.add_edge(edge[0], edge[1])
  
file_path: pgmpy/pgmpy/base/UndirectedGraph.py
imports: import itertools
  import networkx
label_desc: Use image node_id 5 for calling the UndirectedGraph obj's underlying member method code with example usage: obj.add_edges_from(ebunch, weights) without return types