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: Check the model for various errors. This method checks for the following
  errors.
  
  * Checks if factors are defined for all the cliques or not.
  * Check for running intersection property is not done explicitly over
    here as it done in the add_edges method.
  * Checks if cardinality information for all the variables is available or not. If
    not it raises an error.
  * Check if cardinality of random variable remains same across all the
    factors.
  
  Returns
  -------
  check: boolean
      True if all the checks are passed
docstr_tok: ["Check","the","model","for","various","errors",".","This","method","checks","for","the","following","errors",".","*","Checks","if","factors","are","defined","for","all","the","cliques","or","not",".","*","Check","for","running","intersection","property","is","not","done","explicitly","over","here","as","it","done","in","the","add_edges","method",".","*","Checks","if","cardinality","information","for","all","the","variables","is","available","or","not",".","If","not","it","raises","an","error",".","*","Check","if","cardinality","of","random","variable","remains","same","across","all","the","factors",".","Returns","--","--","--","-","check",":","boolean","True","if","all","the","checks","are","passed"]
code: def check_model(self):
      """
      Check the model for various errors. This method checks for the following
      errors.
  
      * Checks if factors are defined for all the cliques or not.
      * Check for running intersection property is not done explicitly over
        here as it done in the add_edges method.
      * Checks if cardinality information for all the variables is available or not. If
        not it raises an error.
      * Check if cardinality of random variable remains same across all the
        factors.
  
      Returns
      -------
      check: boolean
          True if all the checks are passed
      """
      for clique in self.nodes():
          factors = filter(
              lambda x: set(x.scope()) == set(clique), self.factors
          )
          if not any(factors):
              raise ValueError(
                  "Factors for all the cliques or clusters not defined."
              )
  
      cardinalities = self.get_cardinality()
      if len(
          set((x for clique in self.nodes() for x in clique))
      ) != len(cardinalities):
          raise ValueError("Factors for all the variables not defined.")
  
      for factor in self.factors:
          for variable, cardinality in zip(
              factor.scope(), factor.cardinality
          ):
              if cardinalities[variable] != cardinality:
                  raise ValueError(
                      f"Cardinality of variable {variable} not matching among factors"
                  )
  
      return True
  
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 10 for calling the ClusterGraph obj's underlying member method code with example usage: obj.check_model() and returns: True