code: def compute_marginals_persistent(exists_logits, assign_logits):
      """
      This implements exact inference of pairwise marginals via
      enumeration. This is very expensive and is only useful for testing.
  
      See :class:`MarginalAssignmentPersistent` for args and problem description.
      """
      num_frames, num_detections, num_objects = assign_logits.shape
      assert exists_logits.shape == (num_objects,)
      dtype = exists_logits.dtype
      device = exists_logits.device
  
      total = 0
      exists_probs = torch.zeros(
          num_objects, dtype=dtype, device=device
      )
      assign_probs = torch.zeros(
          num_frames,
          num_detections,
          num_objects,
          dtype=dtype,
          device=device,
      )
      for exists in itertools.product([0, 1], repeat=num_objects):
          exists = [i for i, e in enumerate(exists) if e]
          exists_part = _exp(sum(exists_logits[i] for i in exists))
  
          # The remaining variables are conditionally independent conditioned on exists.
          assign_parts = []
          assign_sums = []
          for t in range(num_frames):
              assign_map = {}
              for n in range(1 + min(len(exists), num_detections)):
                  for objects in itertools.combinations(exists, n):
                      for detections in itertools.permutations(
                          range(num_detections), n
                      ):
                          assign = tuple(zip(objects, detections))
                          assign_map[assign] = _exp(
                              sum(
                                  assign_logits[t, j, i]
                                  for i, j in assign
                              )
                          )
              assign_parts.append(assign_map)
              assign_sums.append(sum(assign_map.values()))
  
          prob = exists_part * _product(assign_sums)
          total += prob
          for i in exists:
              exists_probs[i] += prob
          for t in range(num_frames):
              other_part = exists_part * _product(
                  assign_sums[:t] + assign_sums[t + 1 :]
              )
              for assign, assign_part in assign_parts[t].items():
                  prob = other_part * assign_part
                  for i, j in assign:
                      assign_probs[t, j, i] += prob
  
      # Convert from probs to logits.
      exists = exists_probs.log() - (total - exists_probs).log()
      assign = (
          assign_probs.log()
          - (total - assign_probs.sum(-1, True)).log()
      )
      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 6 for calling a global function with example usage: compute_marginals_persistent(exists_logits, assign_logits) and returns: exists,  assign