class_docstr: Search class for exhaustive searches over all DAGs with a given set of variables.
  Takes a `StructureScore`-Instance as parameter; `estimate` finds the model with maximal score.
  
  Parameters
  ----------
  data: pandas DataFrame object
      dataframe object where each column represents one variable.
      (If some values in the data are missing the data cells should be set to `numpy.NaN`.
      Note that pandas converts each column containing `numpy.NaN`s to dtype `float`.)
  
  scoring_method: Instance of a `StructureScore`-subclass (`K2Score` is used as default)
      An instance of `K2Score`, `BDeuScore`, `BicScore` or 'AICScore'.
      This score is optimized during structure estimation by the `estimate`-method.
  
  state_names: dict (optional)
      A dict indicating, for each variable, the discrete set of states (or values)
      that the variable can take. If unspecified, the observed values in the data set
      are taken to be the only possible states.
  
  use_caching: boolean
      If True, uses caching of score for faster computation.
      Note: Caching only works for scoring methods which are decomposable. Can
      give wrong results in case of custom scoring methods.
class_docstr_tok: ["Search","class","for","exhaustive","searches","over","all","DAGs","with","a","given","set","of","variables",".","Takes","a","`","StructureScore","`","-Instance","as","parameter",";","`","estimate","`","finds","the","model","with","maximal","score",".","Parameters","--","--","--","--","--","data",":","pandas","DataFrame","object","dataframe","object","where","each","column","represents","one","variable",".","(","If","some","values","in","the","data","are","missing","the","data","cells","should","be","set","to","`","numpy.NaN","`",".","Note","that","pandas","converts","each","column","containing","`","numpy.NaN","`","s","to","dtype","`","float","`",".",")","scoring_method",":","Instance","of","a","`","StructureScore","`","-subclass","(","`","K2Score","`","is","used","as","default",")","An","instance","of","`","K2Score","`",",","`","BDeuScore","`",",","`","BicScore","`","or","'AICScore","'",".","This","score","is","optimized","during","structure","estimation","by","the","`","estimate","`","-method",".","state_names",":","dict","(","optional",")","A","dict","indicating",",","for","each","variable",",","the","discrete","set","of","states","(","or","values",")","that","the","variable","can","take",".","If","unspecified",",","the","observed","values","in","the","data","set","are","taken","to","be","the","only","possible","states",".","use_caching",":","boolean","If","True",",","uses","caching","of","score","for","faster","computation",".","Note",":","Caching","only","works","for","scoring","methods","which","are","decomposable",".","Can","give","wrong","results","in","case","of","custom","scoring","methods","."]
docstr: Computes all possible directed acyclic graphs with a given set of nodes,
  sparse ones first. `2**(n*(n-1))` graphs need to be searched, given `n` nodes,
  so this is likely not feasible for n>6. This is a generator.
  
  Parameters
  ----------
  nodes: list of nodes for the DAGs (optional)
      A list of the node names that the generated DAGs should have.
      If not provided, nodes are taken from data.
  
  Returns
  -------
  dags: Generator object for nx.DiGraphs
      Generator that yields all acyclic nx.DiGraphs, ordered by number of edges. Empty DAG first.
  
  Examples
  --------
  >>> import pandas as pd
  >>> from pgmpy.estimators import ExhaustiveSearch
  >>> s = ExhaustiveSearch(pd.DataFrame(data={'Temperature': [23, 19],
                                              'Weather': ['sunny', 'cloudy'],
                                              'Humidity': [65, 75]}))
  >>> list(s.all_dags())
  [<networkx.classes.digraph.DiGraph object at 0x7f6955216438>,
   <networkx.classes.digraph.DiGraph object at 0x7f6955216518>,
  ....
  >>> [dag.edges() for dag in s.all_dags()]
  [[], [('Humidity', 'Temperature')], [('Humidity', 'Weather')],
  [('Temperature', 'Weather')], [('Temperature', 'Humidity')],
  ....
  [('Weather', 'Humidity'), ('Weather', 'Temperature'), ('Temperature', 'Humidity')]]
docstr_tok: ["Computes","all","possible","directed","acyclic","graphs","with","a","given","set","of","nodes",",","sparse","ones","first",".","`","2","*","*","(","n","*","(","n-1",")",")","`","graphs","need","to","be","searched",",","given","`","n","`","nodes",",","so","this","is","likely","not","feasible","for","n",">","6",".","This","is","a","generator",".","Parameters","--","--","--","--","--","nodes",":","list","of","nodes","for","the","DAGs","(","optional",")","A","list","of","the","node","names","that","the","generated","DAGs","should","have",".","If","not","provided",",","nodes","are","taken","from","data",".","Returns","--","--","--","-","dags",":","Generator","object","for","nx.DiGraphs","Generator","that","yields","all","acyclic","nx.DiGraphs",",","ordered","by","number","of","edges",".","Empty","DAG","first",".","Examples","--","--","--","--",">",">",">","import","pandas","as","pd",">",">",">","from","pgmpy.estimators","import","ExhaustiveSearch",">",">",">","s","=","ExhaustiveSearch","(","pd.DataFrame","(","data=","{","'Temperature","'",":","[","23",",","19","]",",","'Weather","'",":","[","'sunny","'",",","'cloudy","'","]",",","'Humidity","'",":","[","65",",","75","]","}",")",")",">",">",">","list","(","s.all_dags","(",")",")","[","<","networkx.classes.digraph.DiGraph","object","at","0x7f6955216438",">",",","<","networkx.classes.digraph.DiGraph","object","at","0x7f6955216518",">",",","....",">",">",">","[","dag.edges","(",")","for","dag","in","s.all_dags","(",")","]","[","[","]",",","[","(","'Humidity","'",",","'Temperature","'",")","]",",","[","(","'Humidity","'",",","'Weather","'",")","]",",","[","(","'Temperature","'",",","'Weather","'",")","]",",","[","(","'Temperature","'",",","'Humidity","'",")","]",",","....","[","(","'Weather","'",",","'Humidity","'",")",",","(","'Weather","'",",","'Temperature","'",")",",","(","'Temperature","'",",","'Humidity","'",")","]","]"]
code: def all_dags(self, nodes=None):
      """
      Computes all possible directed acyclic graphs with a given set of nodes,
      sparse ones first. `2**(n*(n-1))` graphs need to be searched, given `n` nodes,
      so this is likely not feasible for n>6. This is a generator.
  
      Parameters
      ----------
      nodes: list of nodes for the DAGs (optional)
          A list of the node names that the generated DAGs should have.
          If not provided, nodes are taken from data.
  
      Returns
      -------
      dags: Generator object for nx.DiGraphs
          Generator that yields all acyclic nx.DiGraphs, ordered by number of edges. Empty DAG first.
  
      Examples
      --------
      >>> import pandas as pd
      >>> from pgmpy.estimators import ExhaustiveSearch
      >>> s = ExhaustiveSearch(pd.DataFrame(data={'Temperature': [23, 19],
                                                  'Weather': ['sunny', 'cloudy'],
                                                  'Humidity': [65, 75]}))
      >>> list(s.all_dags())
      [<networkx.classes.digraph.DiGraph object at 0x7f6955216438>,
       <networkx.classes.digraph.DiGraph object at 0x7f6955216518>,
      ....
      >>> [dag.edges() for dag in s.all_dags()]
      [[], [('Humidity', 'Temperature')], [('Humidity', 'Weather')],
      [('Temperature', 'Weather')], [('Temperature', 'Humidity')],
      ....
      [('Weather', 'Humidity'), ('Weather', 'Temperature'), ('Temperature', 'Humidity')]]
  
      """
      if nodes is None:
          nodes = sorted(self.state_names.keys())
      if len(nodes) > 6:
          logger.info(
              "Generating all DAGs of n nodes likely not feasible for n>6!"
          )
          logger.info(
              "Attempting to search through {n} graphs".format(
                  n=2 ** (len(nodes) * (len(nodes) - 1))
              )
          )
  
      edges = list(
          combinations(nodes, 2)
      )  # n*(n-1) possible directed edges
      edges.extend([(y, x) for x, y in edges])
      all_graphs = powerset(edges)  # 2^(n*(n-1)) graphs
  
      for graph_edges in all_graphs:
          graph = nx.DiGraph(graph_edges)
          graph.add_nodes_from(nodes)
          if nx.is_directed_acyclic_graph(graph):
              yield graph
  
file_path: pgmpy/pgmpy/estimators/ExhaustiveSearch.py
imports: from itertools import combinations
  import networkx
  from pgmpy.base import DAG
  from pgmpy.estimators import K2Score, ScoreCache, StructureEstimator
  from pgmpy.global_vars import logger
  from pgmpy.utils.mathext import powerset
label_desc: Use image node_id 2 for calling the ExhaustiveSearch obj's underlying member method code with example usage: obj.all_dags(nodes) without return types