code: def initialize_potentials(self, assignments, bbn, evidence={}):
      # Step 1, assign 1 to each cluster and sepset
      for node in self.nodes:
          tt = {}
  
          vals = []
          variables = node.variable_names
          # Lets sort the variables here so that
          # the variable names in the keys in
          # the tt are always sorted.
          variables.sort()
          for variable in variables:
              domain = bbn.domains.get(variable, [True, False])
              vals.append(list(product([variable], domain)))
          permutations = product(*vals)
          for permutation in permutations:
              tt[permutation] = 1
          node.potential_tt = tt
  
      # Step 2: Note that in H&D the assignments are
      # done as part of step 2 however we have
      # seperated the assignment algorithm out and
      # done these prior to step 1.
      # Now for each assignment we want to
      # generate a truth-table from the
      # values of the bbn truth-tables that are
      # assigned to the clusters...
  
      for clique, bbn_nodes in assignments.items():
          tt = {}
          vals = []
          variables = list(clique.variable_names)
          variables.sort()
          for variable in variables:
              domain = bbn.domains.get(variable, [True, False])
              vals.append(list(product([variable], domain)))
          permutations = product(*vals)
          for permutation in permutations:
              argvals = dict(permutation)
              potential = 1
              for bbn_node in bbn_nodes:
                  bbn_node.clique = clique
                  # We could handle evidence here
                  # by altering the potential_tt.
                  # This is slightly different to
                  # the way that H&D do it.
  
                  arg_list = []
                  for arg_name in get_args(bbn_node.func):
                      arg_list.append(argvals[arg_name])
  
                  potential *= bbn_node.func(*arg_list)
              tt[permutation] = potential
          clique.potential_tt = tt
  
      if not evidence:
          # We dont need to deal with likelihoods
          # if we dont have any evidence.
          return
  
      # Step 2b: Set each liklihood element ^V(v) to 1
      self.initial_likelihoods(assignments, bbn)
      for clique, bbn_nodes in assignments.items():
          for node in bbn_nodes:
              if node.variable_name in evidence:
                  for k, v in list(clique.potential_tt.items()):
                      # Encode the evidence in
                      # the clique potential...
                      for variable, value in k:
                          if variable == node.variable_name:
                              if value != evidence[variable]:
                                  clique.potential_tt[k] = 0
  
imports: import copy
  import heapq
  import logging
  from collections import defaultdict
  from io import StringIO
  from itertools import combinations, product
  from random import choice, random
  from .exceptions import VariableNotInGraphError, VariableValueNotInDomainError
  from .graph import Node, UndirectedGraph, UndirectedNode, connect
  from .utils import get_args, get_original_factors
label_desc: Use image node_id 4 for calling the JoinTree obj's underlying member method code with example usage: obj.initialize_potentials(assignments, bbn, evidence) without return types