code: def compute_marginals(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:`MarginalAssignment` for args and problem description.
      """
      num_detections, num_objects = assign_logits.shape
      assert exists_logits.shape == (num_objects,)
      dtype = exists_logits.dtype
      device = exists_logits.device
  
      exists_probs = torch.zeros(
          2, num_objects, dtype=dtype, device=device
      )  # [not exist, exist]
      assign_probs = torch.zeros(
          num_detections, num_objects + 1, dtype=dtype, device=device
      )
      for assign in itertools.product(
          range(num_objects + 1), repeat=num_detections
      ):
          assign_part = sum(
              assign_logits[j, i]
              for j, i in enumerate(assign)
              if i < num_objects
          )
          for exists in itertools.product(
              *[
                  [1] if i in assign else [0, 1]
                  for i in range(num_objects)
              ]
          ):
              exists_part = sum(
                  exists_logits[i] for i, e in enumerate(exists) if e
              )
              prob = _exp(exists_part + assign_part)
              for i, e in enumerate(exists):
                  exists_probs[e, i] += prob
              for j, i in enumerate(assign):
                  assign_probs[j, i] += prob
  
      # Convert from probs to logits.
      exists = exists_probs.log()
      assign = assign_probs.log()
      exists = exists[1] - exists[0]
      assign = assign[:, :-1] - assign[:, -1:]
      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 3 for calling a global function with example usage: compute_marginals(exists_logits, assign_logits) and returns: exists,  assign