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: Generalized calibration of junction tree or clique using belief propagation. This method can be used for both
  calibrating as well as max-calibrating.
  Uses Lauritzen-Spiegelhalter algorithm or belief-update message passing.
  
  Parameters
  ----------
  operation: str ('marginalize' | 'maximize')
      The operation to do for passing messages between nodes.
  
  Reference
  ---------
  Algorithm 10.3 Calibration using belief propagation in clique tree
  Probabilistic Graphical Models: Principles and Techniques
  Daphne Koller and Nir Friedman.
docstr_tok: ["Generalized","calibration","of","junction","tree","or","clique","using","belief","propagation",".","This","method","can","be","used","for","both","calibrating","as","well","as","max-calibrating",".","Uses","Lauritzen-Spiegelhalter","algorithm","or","belief-update","message","passing",".","Parameters","--","--","--","--","--","operation",":","str","(","'marginalize","'","|","'maximize","'",")","The","operation","to","do","for","passing","messages","between","nodes",".","Reference","--","--","--","--","-","Algorithm","10.3","Calibration","using","belief","propagation","in","clique","tree","Probabilistic","Graphical","Models",":","Principles","and","Techniques","Daphne","Koller","and","Nir","Friedman","."]
code: def _calibrate_junction_tree(self, operation):
      """
      Generalized calibration of junction tree or clique using belief propagation. This method can be used for both
      calibrating as well as max-calibrating.
      Uses Lauritzen-Spiegelhalter algorithm or belief-update message passing.
  
      Parameters
      ----------
      operation: str ('marginalize' | 'maximize')
          The operation to do for passing messages between nodes.
  
      Reference
      ---------
      Algorithm 10.3 Calibration using belief propagation in clique tree
      Probabilistic Graphical Models: Principles and Techniques
      Daphne Koller and Nir Friedman.
      """
      # Initialize clique beliefs as well as sepset beliefs
      self.clique_beliefs = {
          clique: self.junction_tree.get_factors(clique)
          for clique in self.junction_tree.nodes()
      }
      self.sepset_beliefs = {
          frozenset(edge): None for edge in self.junction_tree.edges()
      }
  
      for clique in self.junction_tree.nodes():
          if not self._is_converged(operation=operation):
              neighbors = self.junction_tree.neighbors(clique)
              # update root's belief using neighbor clique's beliefs
              # upward pass
              for neighbor_clique in neighbors:
                  self._update_beliefs(
                      neighbor_clique, clique, operation=operation
                  )
              bfs_edges = nx.algorithms.breadth_first_search.bfs_edges(
                  self.junction_tree, clique
              )
              # update the beliefs of all the nodes starting from the root to leaves using root's belief
              # downward pass
              for edge in bfs_edges:
                  self._update_beliefs(
                      edge[0], edge[1], operation=operation
                  )
          else:
              break
  
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 7 for calling the BeliefPropagation obj's underlying member method code with example usage: obj._calibrate_junction_tree(operation) without return types