class_docstr: Base class for Markov Model.
  
  A MarkovNetwork stores nodes and edges with potentials
  
  MarkovNetwork holds undirected edges.
  
  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 Markov Model with no nodes and no edges.
  
  >>> from pgmpy.models import MarkovNetwork
  >>> G = MarkovNetwork()
  
  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","Markov","Model",".","A","MarkovNetwork","stores","nodes","and","edges","with","potentials","MarkovNetwork","holds","undirected","edges",".","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","Markov","Model","with","no","nodes","and","no","edges",".",">",">",">","from","pgmpy.models","import","MarkovNetwork",">",">",">","G","=","MarkovNetwork","(",")","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: Associate a factor to the graph.
  See factors class for the order of potential values
  
  Parameters
  ----------
  *factor: pgmpy.factors.factors object
      A factor object on any subset of the variables of the model which
      is to be associated with the model.
  
  Returns
  -------
  None
  
  Examples
  --------
  >>> from pgmpy.models import MarkovNetwork
  >>> from pgmpy.factors.discrete import DiscreteFactor
  >>> student = MarkovNetwork([('Alice', 'Bob'), ('Bob', 'Charles'),
  ...                        ('Charles', 'Debbie'), ('Debbie', 'Alice')])
  >>> factor = DiscreteFactor(['Alice', 'Bob'], cardinality=[3, 2],
  ...                 values=np.random.rand(6))
  >>> student.add_factors(factor)
docstr_tok: ["Associate","a","factor","to","the","graph",".","See","factors","class","for","the","order","of","potential","values","Parameters","--","--","--","--","--","*","factor",":","pgmpy.factors.factors","object","A","factor","object","on","any","subset","of","the","variables","of","the","model","which","is","to","be","associated","with","the","model",".","Returns","--","--","--","-","None","Examples","--","--","--","--",">",">",">","from","pgmpy.models","import","MarkovNetwork",">",">",">","from","pgmpy.factors.discrete","import","DiscreteFactor",">",">",">","student","=","MarkovNetwork","(","[","(","'Alice","'",",","'Bob","'",")",",","(","'Bob","'",",","'Charles","'",")",",","...","(","'Charles","'",",","'Debbie","'",")",",","(","'Debbie","'",",","'Alice","'",")","]",")",">",">",">","factor","=","DiscreteFactor","(","[","'Alice","'",",","'Bob","'","]",",","cardinality=","[","3",",","2","]",",","...","values=np.random.rand","(","6",")",")",">",">",">","student.add_factors","(","factor",")"]
code: def add_factors(self, *factors):
      """
      Associate a factor to the graph.
      See factors class for the order of potential values
  
      Parameters
      ----------
      *factor: pgmpy.factors.factors object
          A factor object on any subset of the variables of the model which
          is to be associated with the model.
  
      Returns
      -------
      None
  
      Examples
      --------
      >>> from pgmpy.models import MarkovNetwork
      >>> from pgmpy.factors.discrete import DiscreteFactor
      >>> student = MarkovNetwork([('Alice', 'Bob'), ('Bob', 'Charles'),
      ...                        ('Charles', 'Debbie'), ('Debbie', 'Alice')])
      >>> factor = DiscreteFactor(['Alice', 'Bob'], cardinality=[3, 2],
      ...                 values=np.random.rand(6))
      >>> student.add_factors(factor)
      """
      for factor in factors:
          if set(factor.variables) - set(factor.variables).intersection(
              set(self.nodes())
          ):
              raise ValueError(
                  "Factors defined on variable not in the model", factor
              )
  
          self.factors.append(factor)
  
imports: import itertools
  from collections import defaultdict
  import networkx
  import numpy
  from networkx.algorithms.components import connected_components
  from pgmpy.base import UndirectedGraph
  from pgmpy.factors import factor_product
  from pgmpy.factors.discrete import DiscreteFactor
  from pgmpy.independencies import Independencies
label_desc: Use image node_id 3 for calling the MarkovNetwork obj's underlying member method code with example usage: obj.add_factors() without return types