class_docstr: Base class for representing Cluster Graph.
  
  Cluster graph is an undirected graph which is associated with a subset of variables. The graph contains undirected
  edges that connects clusters whose scopes have a non-empty intersection.
  
  Formally, a cluster graph is  :math:`\mathcal{U}` for a set of factors :math:`\Phi` over :math:`\mathcal{X}` is an
  undirected graph, each of whose nodes :math:`i` is associated with a subset :math:`C_i \subseteq X`. A cluster
  graph must be family-preserving - each factor :math:`\phi \in \Phi` must be associated with a cluster C, denoted
  :math:`\alpha(\phi)`, such that :math:`Scope[\phi] \subseteq C_i`. Each edge between a pair of clusters :math:`C_i`
  and :math:`C_j` is associated with a sepset :math:`S_{i,j} \subseteq C_i \cap C_j`.
  
  Parameters
  ----------
  data: input graph
      Data to initialize graph. If data=None (default) an empty graph is created. The data is an edge list
  
  Examples
  --------
  Create an empty ClusterGraph with no nodes and no edges
  
  >>> from pgmpy.models import ClusterGraph
  >>> G = ClusterGraph()
  
  G can be grown by adding clique nodes.
  
  **Nodes:**
  
  Add a tuple (or list or set) of nodes as single clique node.
  
  >>> G.add_node(('a', 'b', 'c'))
  >>> G.add_nodes_from([('a', 'b'), ('a', 'b', 'c')])
  
  **Edges:**
  
  G can also be grown by adding edges.
  
  >>> G.add_edge(('a', 'b', 'c'), ('a', 'b'))
  
  or a list of edges
  
  >>> G.add_edges_from([(('a', 'b', 'c'), ('a', 'b')),
  ...                   (('a', 'b', 'c'), ('a', 'c'))])
class_docstr_tok: ["Base","class","for","representing","Cluster","Graph",".","Cluster","graph","is","an","undirected","graph","which","is","associated","with","a","subset","of","variables",".","The","graph","contains","undirected","edges","that","connects","clusters","whose","scopes","have","a","non-empty","intersection",".","Formally",",","a","cluster","graph","is",":","math",":","`","\\mathcal","{","U","}","`","for","a","set","of","factors",":","math",":","`","\\Phi","`","over",":","math",":","`","\\mathcal","{","X","}","`","is","an","undirected","graph",",","each","of","whose","nodes",":","math",":","`","i","`","is","associated","with","a","subset",":","math",":","`","C_i","\\subseteq","X","`",".","A","cluster","graph","must","be","family-preserving","-","each","factor",":","math",":","`","\\phi","\\in","\\Phi","`","must","be","associated","with","a","cluster","C",",","denoted",":","math",":","`","\\alpha","(","\\phi",")","`",",","such","that",":","math",":","`","Scope","[","\\phi","]","\\subseteq","C_i","`",".","Each","edge","between","a","pair","of","clusters",":","math",":","`","C_i","`","and",":","math",":","`","C_j","`","is","associated","with","a","sepset",":","math",":","`","S_","{","i",",","j","}","\\subseteq","C_i","\\cap","C_j","`",".","Parameters","--","--","--","--","--","data",":","input","graph","Data","to","initialize","graph",".","If","data=None","(","default",")","an","empty","graph","is","created",".","The","data","is","an","edge","list","Examples","--","--","--","--","Create","an","empty","ClusterGraph","with","no","nodes","and","no","edges",">",">",">","from","pgmpy.models","import","ClusterGraph",">",">",">","G","=","ClusterGraph","(",")","G","can","be","grown","by","adding","clique","nodes",".","*","*","Nodes",":","*","*","Add","a","tuple","(","or","list","or","set",")","of","nodes","as","single","clique","node",".",">",">",">","G.add_node","(","(","'","a","'",",","'","b","'",",","'","c","'",")",")",">",">",">","G.add_nodes_from","(","[","(","'","a","'",",","'","b","'",")",",","(","'","a","'",",","'","b","'",",","'","c","'",")","]",")","*","*","Edges",":","*","*","G","can","also","be","grown","by","adding","edges",".",">",">",">","G.add_edge","(","(","'","a","'",",","'","b","'",",","'","c","'",")",",","(","'","a","'",",","'","b","'",")",")","or","a","list","of","edges",">",">",">","G.add_edges_from","(","[","(","(","'","a","'",",","'","b","'",",","'","c","'",")",",","(","'","a","'",",","'","b","'",")",")",",","...","(","(","'","a","'",",","'","b","'",",","'","c","'",")",",","(","'","a","'",",","'","c","'",")",")","]",")"]
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 ClusterGraph
  >>> from pgmpy.factors.discrete import DiscreteFactor
  >>> student = ClusterGraph()
  >>> student.add_node(('Alice', 'Bob'))
  >>> 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","ClusterGraph",">",">",">","from","pgmpy.factors.discrete","import","DiscreteFactor",">",">",">","student","=","ClusterGraph","(",")",">",">",">","student.add_node","(","(","'Alice","'",",","'Bob","'",")",")",">",">",">","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 ClusterGraph
      >>> from pgmpy.factors.discrete import DiscreteFactor
      >>> student = ClusterGraph()
      >>> student.add_node(('Alice', 'Bob'))
      >>> factor = DiscreteFactor(['Alice', 'Bob'], cardinality=[3, 2],
      ...                 values=np.random.rand(6))
      >>> student.add_factors(factor)
      """
      for factor in factors:
          factor_scope = set(factor.scope())
          nodes = [set(node) for node in self.nodes()]
          if factor_scope not in nodes:
              raise ValueError(
                  "Factors defined on clusters of variable not"
                  "present in model"
              )
  
          self.factors.append(factor)
  
file_path: pgmpy/pgmpy/models/ClusterGraph.py
imports: from collections import defaultdict
  import numpy
  from pgmpy.base import UndirectedGraph
  from pgmpy.factors import factor_product
label_desc: Use image node_id 5 for calling the ClusterGraph obj's underlying member method code with example usage: obj.add_factors() without return types