code: def compute_marginals_bp(exists_logits, assign_logits, bp_iters):
      """
      This implements approximate inference of pairwise marginals via
      loopy belief propagation, adapting the approach of [1].
  
      See :class:`MarginalAssignment` for args and problem description.
  
      [1] Jason L. Williams, Roslyn A. Lau (2014)
          Approximate evaluation of marginal association probabilities with
          belief propagation
          https://arxiv.org/abs/1209.6299
      """
      message_e_to_a = torch.zeros_like(assign_logits)
      message_a_to_e = torch.zeros_like(assign_logits)
      for i in range(bp_iters):
          message_e_to_a = (
              -(
                  message_a_to_e
                  - message_a_to_e.sum(0, True)
                  - exists_logits
              )
              .exp()
              .log1p()
          )
          joint = (assign_logits + message_e_to_a).exp()
          message_a_to_e = (
              (assign_logits - torch.log1p(joint.sum(1, True) - joint))
              .exp()
              .log1p()
          )
          warn_if_nan(
              message_e_to_a, "message_e_to_a iter {}".format(i)
          )
          warn_if_nan(
              message_a_to_e, "message_a_to_e iter {}".format(i)
          )
  
      # Convert from probs to logits.
      exists = exists_logits + message_a_to_e.sum(0)
      assign = assign_logits + message_e_to_a
      warn_if_nan(exists, "exists")
      warn_if_nan(assign, "assign")
      return exists, assign
  
file_path: pyro/pyro/contrib/tracking/assignment.py
imports: import itertools
  import math
  import numbers
  import torch
  import pyro.distributions
  from pyro.util import warn_if_nan
label_desc: Use image node_id 4 for calling a global function with example usage: compute_marginals_bp(exists_logits, assign_logits, bp_iters) and returns: exists,  assign