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: Returns the partition function for a given undirected graph.
  
  A partition function is defined as
  
  .. math:: \sum_{X}(\prod_{i=1}^{m} \phi_i)
  
  where m is the number of factors present in the graph
  and X are all the random variables present.
  
  Examples
  --------
  >>> from pgmpy.models import ClusterGraph
  >>> from pgmpy.factors.discrete import DiscreteFactor
  >>> G = ClusterGraph()
  >>> G.add_nodes_from([('a', 'b', 'c'), ('a', 'b'), ('a', 'c')])
  >>> G.add_edges_from([(('a', 'b', 'c'), ('a', 'b')),
  ...                   (('a', 'b', 'c'), ('a', 'c'))])
  >>> phi1 = DiscreteFactor(['a', 'b', 'c'], [2, 2, 2], np.random.rand(8))
  >>> phi2 = DiscreteFactor(['a', 'b'], [2, 2], np.random.rand(4))
  >>> phi3 = DiscreteFactor(['a', 'c'], [2, 2], np.random.rand(4))
  >>> G.add_factors(phi1, phi2, phi3)
  >>> G.get_partition_function()
docstr_tok: ["Returns","the","partition","function","for","a","given","undirected","graph",".","A","partition","function","is","defined","as","..","math",":",":","\\sum_","{","X","}","(","\\prod_","{","i=1","}","^","{","m","}","\\phi_i",")","where","m","is","the","number","of","factors","present","in","the","graph","and","X","are","all","the","random","variables","present",".","Examples","--","--","--","--",">",">",">","from","pgmpy.models","import","ClusterGraph",">",">",">","from","pgmpy.factors.discrete","import","DiscreteFactor",">",">",">","G","=","ClusterGraph","(",")",">",">",">","G.add_nodes_from","(","[","(","'","a","'",",","'","b","'",",","'","c","'",")",",","(","'","a","'",",","'","b","'",")",",","(","'","a","'",",","'","c","'",")","]",")",">",">",">","G.add_edges_from","(","[","(","(","'","a","'",",","'","b","'",",","'","c","'",")",",","(","'","a","'",",","'","b","'",")",")",",","...","(","(","'","a","'",",","'","b","'",",","'","c","'",")",",","(","'","a","'",",","'","c","'",")",")","]",")",">",">",">","phi1","=","DiscreteFactor","(","[","'","a","'",",","'","b","'",",","'","c","'","]",",","[","2",",","2",",","2","]",",","np.random.rand","(","8",")",")",">",">",">","phi2","=","DiscreteFactor","(","[","'","a","'",",","'","b","'","]",",","[","2",",","2","]",",","np.random.rand","(","4",")",")",">",">",">","phi3","=","DiscreteFactor","(","[","'","a","'",",","'","c","'","]",",","[","2",",","2","]",",","np.random.rand","(","4",")",")",">",">",">","G.add_factors","(","phi1",",","phi2",",","phi3",")",">",">",">","G.get_partition_function","(",")"]
code: def get_partition_function(self):
      r"""
      Returns the partition function for a given undirected graph.
  
      A partition function is defined as
  
      .. math:: \sum_{X}(\prod_{i=1}^{m} \phi_i)
  
      where m is the number of factors present in the graph
      and X are all the random variables present.
  
      Examples
      --------
      >>> from pgmpy.models import ClusterGraph
      >>> from pgmpy.factors.discrete import DiscreteFactor
      >>> G = ClusterGraph()
      >>> G.add_nodes_from([('a', 'b', 'c'), ('a', 'b'), ('a', 'c')])
      >>> G.add_edges_from([(('a', 'b', 'c'), ('a', 'b')),
      ...                   (('a', 'b', 'c'), ('a', 'c'))])
      >>> phi1 = DiscreteFactor(['a', 'b', 'c'], [2, 2, 2], np.random.rand(8))
      >>> phi2 = DiscreteFactor(['a', 'b'], [2, 2], np.random.rand(4))
      >>> phi3 = DiscreteFactor(['a', 'c'], [2, 2], np.random.rand(4))
      >>> G.add_factors(phi1, phi2, phi3)
      >>> G.get_partition_function()
      """
      if self.check_model():
          factor = self.factors[0]
          factor = factor_product(
              factor,
              *[self.factors[i] for i in range(1, len(self.factors))],
          )
          return np.sum(factor.values)
  
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 9 for calling the ClusterGraph obj's underlying member method code with example usage: obj.get_partition_function() and returns: np