class_docstr: An ``InferenceEngine`` provides methods to query marginals based on observations and
  make interventions (Do-Calculus) on a ``BayesianNetwork``.
  
  Example:
  ::
      >>> # Create a Bayesian Network with a manually defined DAG
      >>> from causalnex.structure.structuremodel import StructureModel
      >>> from causalnex.network import BayesianNetwork
      >>> from causalnex.inference import InferenceEngine
      >>>
      >>> sm = StructureModel()
      >>> sm.add_edges_from([
      >>>                    ('rush_hour', 'traffic'),
      >>>                    ('weather', 'traffic')
      >>>                    ])
      >>> data = pd.DataFrame({
      >>>                      'rush_hour': [True, False, False, False, True, False, True],
      >>>                      'weather': ['Terrible', 'Good', 'Bad', 'Good', 'Bad', 'Bad', 'Good'],
      >>>                      'traffic': ['heavy', 'light', 'heavy', 'light', 'heavy', 'heavy', 'heavy']
      >>>                      })
      >>> bn = BayesianNetwork(sm)
      >>> # Inference can only be performed on the `BayesianNetwork` with learned nodes states and CPDs
      >>> bn = bn.fit_node_states_and_cpds(data)
      >>>
      >>> # Create an `InferenceEngine` to query marginals and make interventions
      >>> ie = InferenceEngine(bn)
      >>> # Query the marginals as learned from data
      >>> ie.query()['traffic']
      {'heavy': 0.7142857142857142, 'light': 0.2857142857142857}
      >>> # Query the marginals given observations
      >>> ie.query({'rush_hour': True, 'weather': 'Terrible'})['traffic']
      {'heavy': 1.0, 'light': 0.0}
      >>> # Make an intervention on the `BayesianNetwork`
      >>> ie.do_intervention('rush_hour', False)
      >>> # Query marginals on the intervened `BayesianNetwork`
      >>> ie.query()['traffic']
      {'heavy': 0.5, 'light': 0.5}
      >>> # Reset interventions
      >>> ie.reset_do('rush_hour')
      >>> ie.query()['traffic']
      {'heavy': 0.7142857142857142, 'light': 0.2857142857142857}
class_docstr_tok: ["An","``","InferenceEngine","``","provides","methods","to","query","marginals","based","on","observations","and","make","interventions","(","Do-Calculus",")","on","a","``","BayesianNetwork","``",".","Example",":",":",":",">",">",">","#","Create","a","Bayesian","Network","with","a","manually","defined","DAG",">",">",">","from","causalnex.structure.structuremodel","import","StructureModel",">",">",">","from","causalnex.network","import","BayesianNetwork",">",">",">","from","causalnex.inference","import","InferenceEngine",">",">",">",">",">",">","sm","=","StructureModel","(",")",">",">",">","sm.add_edges_from","(","[",">",">",">","(","'rush_hour","'",",","'traffic","'",")",",",">",">",">","(","'weather","'",",","'traffic","'",")",">",">",">","]",")",">",">",">","data","=","pd.DataFrame","(","{",">",">",">","'rush_hour","'",":","[","True",",","False",",","False",",","False",",","True",",","False",",","True","]",",",">",">",">","'weather","'",":","[","'Terrible","'",",","'Good","'",",","'Bad","'",",","'Good","'",",","'Bad","'",",","'Bad","'",",","'Good","'","]",",",">",">",">","'traffic","'",":","[","'heavy","'",",","'light","'",",","'heavy","'",",","'light","'",",","'heavy","'",",","'heavy","'",",","'heavy","'","]",">",">",">","}",")",">",">",">","bn","=","BayesianNetwork","(","sm",")",">",">",">","#","Inference","can","only","be","performed","on","the","`","BayesianNetwork","`","with","learned","nodes","states","and","CPDs",">",">",">","bn","=","bn.fit_node_states_and_cpds","(","data",")",">",">",">",">",">",">","#","Create","an","`","InferenceEngine","`","to","query","marginals","and","make","interventions",">",">",">","ie","=","InferenceEngine","(","bn",")",">",">",">","#","Query","the","marginals","as","learned","from","data",">",">",">","ie.query","(",")","[","'traffic","'","]","{","'heavy","'",":","0.7142857142857142",",","'light","'",":","0.2857142857142857","}",">",">",">","#","Query","the","marginals","given","observations",">",">",">","ie.query","(","{","'rush_hour","'",":","True",",","'weather","'",":","'Terrible","'","}",")","[","'traffic","'","]","{","'heavy","'",":","1.0",",","'light","'",":","0.0","}",">",">",">","#","Make","an","intervention","on","the","`","BayesianNetwork","`",">",">",">","ie.do_intervention","(","'rush_hour","'",",","False",")",">",">",">","#","Query","marginals","on","the","intervened","`","BayesianNetwork","`",">",">",">","ie.query","(",")","[","'traffic","'","]","{","'heavy","'",":","0.5",",","'light","'",":","0.5","}",">",">",">","#","Reset","interventions",">",">",">","ie.reset_do","(","'rush_hour","'",")",">",">",">","ie.query","(",")","[","'traffic","'","]","{","'heavy","'",":","0.7142857142857142",",","'light","'",":","0.2857142857142857","}"]
docstr: Creates a new function that describes a node in the ``BayesianNetwork``.
docstr_tok: ["Creates","a","new","function","that","describes","a","node","in","the","``","BayesianNetwork","``","."]
code: def _create_node_function(self, name: str, args: Tuple[str]):
      """Creates a new function that describes a node in the ``BayesianNetwork``."""
  
      def template() -> float:
          """Template node function."""
          # use inspection to determine arguments to the function
          # initially there are none present, but caller will add appropriate arguments to the function
          # getargvalues was "inadvertently marked as deprecated in Python 3.5"
          # https://docs.python.org/3/library/inspect.html#inspect.getfullargspec
          arg_spec = inspect.getargvalues(
              inspect.currentframe()
          )  # pragma: no cover
  
          return self._cpds[arg_spec.args[0]][  # target name
              arg_spec.locals[arg_spec.args[0]]
          ][  # target state
              tuple(
                  (arg, arg_spec.locals[arg])
                  for arg in arg_spec.args[1:]
              )
          ]  # conditions
  
      code = template.__code__
      pos_count = (
          [code.co_posonlyargcount]
          if hasattr(code, "co_posonlyargcount")
          else []
      )
      template.__code__ = types.CodeType(
          len(args),
          *pos_count,
          code.co_kwonlyargcount,
          len(args),
          code.co_stacksize,
          code.co_flags,
          code.co_code,
          code.co_consts,
          code.co_names,
          args,
          code.co_filename,
          name,
          code.co_firstlineno,
          code.co_lnotab,
          code.co_freevars,
          code.co_cellvars,
      )
      template.__name__ = name
      return template
  
imports: import copy
  import inspect
  import math
  import re
  import types
  from typing import Any, Callable, Dict, Hashable, List, Optional, Tuple, Union
  import networkx
  import pandas
  from pathos import multiprocessing
  from causalnex.ebaybbn import build_bbn
  from causalnex.network import BayesianNetwork
label_desc: Use image node_id 10 for calling the InferenceEngine obj's underlying member method code with example usage: obj._create_node_function(name, args) and returns: template, self