class_docstr: Class for performing inference using Belief Propagation method.
  
  Creates a Junction Tree or Clique Tree (JunctionTree class) for the input
  probabilistic graphical model and performs calibration of the junction tree
  so formed using belief propagation.
  
  Parameters
  ----------
  model: BayesianNetwork, MarkovNetwork, FactorGraph, JunctionTree
      model for which inference is to performed
docstr: Query method using belief propagation.
  
  Parameters
  ----------
  variables: list
      list of variables for which you want to compute the probability
  
  evidence: dict
      a dict key, value pair as {var: state_of_var_observed}
      None if no evidence
  
  virtual_evidence: list (default:None)
      A list of pgmpy.factors.discrete.TabularCPD representing the virtual
      evidences.
  
  joint: boolean
      If True, returns a Joint Distribution over `variables`.
      If False, returns a dict of distributions over each of the `variables`.
  
  show_progress: boolean
      If True shows a progress bar.
  
  Examples
  --------
  >>> from pgmpy.factors.discrete import TabularCPD
  >>> from pgmpy.models import BayesianNetwork
  >>> from pgmpy.inference import BeliefPropagation
  >>> bayesian_model = BayesianNetwork([('A', 'J'), ('R', 'J'), ('J', 'Q'),
  ...                                 ('J', 'L'), ('G', 'L')])
  >>> cpd_a = TabularCPD('A', 2, [[0.2], [0.8]])
  >>> cpd_r = TabularCPD('R', 2, [[0.4], [0.6]])
  >>> cpd_j = TabularCPD('J', 2,
  ...                    [[0.9, 0.6, 0.7, 0.1],
  ...                     [0.1, 0.4, 0.3, 0.9]],
  ...                    ['R', 'A'], [2, 2])
  >>> cpd_q = TabularCPD('Q', 2,
  ...                    [[0.9, 0.2],
  ...                     [0.1, 0.8]],
  ...                    ['J'], [2])
  >>> cpd_l = TabularCPD('L', 2,
  ...                    [[0.9, 0.45, 0.8, 0.1],
  ...                     [0.1, 0.55, 0.2, 0.9]],
  ...                    ['G', 'J'], [2, 2])
  >>> cpd_g = TabularCPD('G', 2, [[0.6], [0.4]])
  >>> bayesian_model.add_cpds(cpd_a, cpd_r, cpd_j, cpd_q, cpd_l, cpd_g)
  >>> belief_propagation = BeliefPropagation(bayesian_model)
  >>> belief_propagation.query(variables=['J', 'Q'],
  ...                          evidence={'A': 0, 'R': 0, 'G': 0, 'L': 1})
docstr_tok: ["Query","method","using","belief","propagation",".","Parameters","--","--","--","--","--","variables",":","list","list","of","variables","for","which","you","want","to","compute","the","probability","evidence",":","dict","a","dict","key",",","value","pair","as","{","var",":","state_of_var_observed","}","None","if","no","evidence","virtual_evidence",":","list","(","default",":","None",")","A","list","of","pgmpy.factors.discrete.TabularCPD","representing","the","virtual","evidences",".","joint",":","boolean","If","True",",","returns","a","Joint","Distribution","over","`","variables","`",".","If","False",",","returns","a","dict","of","distributions","over","each","of","the","`","variables","`",".","show_progress",":","boolean","If","True","shows","a","progress","bar",".","Examples","--","--","--","--",">",">",">","from","pgmpy.factors.discrete","import","TabularCPD",">",">",">","from","pgmpy.models","import","BayesianNetwork",">",">",">","from","pgmpy.inference","import","BeliefPropagation",">",">",">","bayesian_model","=","BayesianNetwork","(","[","(","'","A","'",",","'","J","'",")",",","(","'","R","'",",","'","J","'",")",",","(","'","J","'",",","'","Q","'",")",",","...","(","'","J","'",",","'","L","'",")",",","(","'","G","'",",","'","L","'",")","]",")",">",">",">","cpd_a","=","TabularCPD","(","'","A","'",",","2",",","[","[","0.2","]",",","[","0.8","]","]",")",">",">",">","cpd_r","=","TabularCPD","(","'","R","'",",","2",",","[","[","0.4","]",",","[","0.6","]","]",")",">",">",">","cpd_j","=","TabularCPD","(","'","J","'",",","2",",","...","[","[","0.9",",","0.6",",","0.7",",","0.1","]",",","...","[","0.1",",","0.4",",","0.3",",","0.9","]","]",",","...","[","'","R","'",",","'","A","'","]",",","[","2",",","2","]",")",">",">",">","cpd_q","=","TabularCPD","(","'","Q","'",",","2",",","...","[","[","0.9",",","0.2","]",",","...","[","0.1",",","0.8","]","]",",","...","[","'","J","'","]",",","[","2","]",")",">",">",">","cpd_l","=","TabularCPD","(","'","L","'",",","2",",","...","[","[","0.9",",","0.45",",","0.8",",","0.1","]",",","...","[","0.1",",","0.55",",","0.2",",","0.9","]","]",",","...","[","'","G","'",",","'","J","'","]",",","[","2",",","2","]",")",">",">",">","cpd_g","=","TabularCPD","(","'","G","'",",","2",",","[","[","0.6","]",",","[","0.4","]","]",")",">",">",">","bayesian_model.add_cpds","(","cpd_a",",","cpd_r",",","cpd_j",",","cpd_q",",","cpd_l",",","cpd_g",")",">",">",">","belief_propagation","=","BeliefPropagation","(","bayesian_model",")",">",">",">","belief_propagation.query","(","variables=","[","'","J","'",",","'","Q","'","]",",","...","evidence=","{","'","A","'",":","0",",","'","R","'",":","0",",","'","G","'",":","0",",","'","L","'",":","1","}",")"]
code: def query(
      self,
      variables,
      evidence=None,
      virtual_evidence=None,
      joint=True,
      show_progress=True,
  ):
      """
      Query method using belief propagation.
  
      Parameters
      ----------
      variables: list
          list of variables for which you want to compute the probability
  
      evidence: dict
          a dict key, value pair as {var: state_of_var_observed}
          None if no evidence
  
      virtual_evidence: list (default:None)
          A list of pgmpy.factors.discrete.TabularCPD representing the virtual
          evidences.
  
      joint: boolean
          If True, returns a Joint Distribution over `variables`.
          If False, returns a dict of distributions over each of the `variables`.
  
      show_progress: boolean
          If True shows a progress bar.
  
      Examples
      --------
      >>> from pgmpy.factors.discrete import TabularCPD
      >>> from pgmpy.models import BayesianNetwork
      >>> from pgmpy.inference import BeliefPropagation
      >>> bayesian_model = BayesianNetwork([('A', 'J'), ('R', 'J'), ('J', 'Q'),
      ...                                 ('J', 'L'), ('G', 'L')])
      >>> cpd_a = TabularCPD('A', 2, [[0.2], [0.8]])
      >>> cpd_r = TabularCPD('R', 2, [[0.4], [0.6]])
      >>> cpd_j = TabularCPD('J', 2,
      ...                    [[0.9, 0.6, 0.7, 0.1],
      ...                     [0.1, 0.4, 0.3, 0.9]],
      ...                    ['R', 'A'], [2, 2])
      >>> cpd_q = TabularCPD('Q', 2,
      ...                    [[0.9, 0.2],
      ...                     [0.1, 0.8]],
      ...                    ['J'], [2])
      >>> cpd_l = TabularCPD('L', 2,
      ...                    [[0.9, 0.45, 0.8, 0.1],
      ...                     [0.1, 0.55, 0.2, 0.9]],
      ...                    ['G', 'J'], [2, 2])
      >>> cpd_g = TabularCPD('G', 2, [[0.6], [0.4]])
      >>> bayesian_model.add_cpds(cpd_a, cpd_r, cpd_j, cpd_q, cpd_l, cpd_g)
      >>> belief_propagation = BeliefPropagation(bayesian_model)
      >>> belief_propagation.query(variables=['J', 'Q'],
      ...                          evidence={'A': 0, 'R': 0, 'G': 0, 'L': 1})
      """
      evidence = evidence if evidence is not None else dict()
      orig_model = self.model.copy()
  
      # Step 1: Parameter Checks
      common_vars = set(
          evidence if evidence is not None else []
      ).intersection(set(variables))
      if common_vars:
          raise ValueError(
              f"Can't have the same variables in both `variables` and `evidence`. Found in both: {common_vars}"
          )
  
      # Step 2: If virtual_evidence is provided, modify model and evidence.
      if isinstance(self.model, BayesianNetwork) and (
          virtual_evidence is not None
      ):
          self._virtual_evidence(virtual_evidence)
          virt_evidence = {
              "__" + cpd.variables[0]: 0 for cpd in virtual_evidence
          }
          return self.query(
              variables=variables,
              evidence={**evidence, **virt_evidence},
              virtual_evidence=None,
              joint=joint,
              show_progress=show_progress,
          )
  
      # Step 3: Do network pruning.
      if isinstance(self.model, BayesianNetwork):
          self.model, evidence = self._prune_bayesian_model(
              variables, evidence
          )
      self._initialize_structures()
  
      # Step 4: Run inference.
      result = self._query(
          variables=variables,
          operation="marginalize",
          evidence=evidence,
          joint=joint,
          show_progress=show_progress,
      )
      self.__init__(orig_model)
  
      if joint:
          return result.normalize(inplace=False)
      else:
          return result
  
imports: import copy
  import itertools
  import networkx
  import numpy
  from opt_einsum import contract
  from tqdm.auto import tqdm
  from pgmpy import config
  from pgmpy.factors import factor_product
  from pgmpy.factors.discrete import DiscreteFactor
  from pgmpy.inference import Inference
  from pgmpy.inference.EliminationOrder import MinFill, MinNeighbors, MinWeight, WeightedMinFill
  from pgmpy.models import BayesianNetwork, DynamicBayesianNetwork, JunctionTree, MarkovNetwork
  from pgmpy.utils import compat_fns
label_desc: Use image node_id 11 for calling the BeliefPropagation obj's underlying member method code with example usage: obj.query(variables, evidence, virtual_evidence, joint, show_progress) and returns: self, result, result