code: def indiv_map_states(a0, a, e, x):
      # Viterbi algorithm, implemented without batching or vector operations.
  
      delta = torch.zeros((x.shape[0], a0.shape[0]))
      for j in range(a0.shape[0]):
          vec = a0[j]
          if torch.sum(x[0, :]) > 0.5:
              vec = vec * torch.dot(x[0, :], e[j, :])
          delta[0, j] = vec
      traceback = torch.zeros(
          (x.shape[0], a0.shape[0]), dtype=torch.long
      )
      for t in range(1, x.shape[0]):
          for j in range(a0.shape[0]):
              vec = delta[t - 1, :] * a[:, j]
              if torch.sum(x[t, :]) > 0.5:
                  vec = vec * torch.dot(x[t, :], e[j, :])
              delta[t, j] = torch.max(vec)
              traceback[t, j] = torch.argmax(vec)
      expected_map_states = torch.zeros(x.shape[0], dtype=torch.long)
      expected_map_states[-1] = torch.argmax(delta[-1, :])
      for t in range(x.shape[0] - 1, 0, -1):
          expected_map_states[t - 1] = traceback[
              t, expected_map_states[t]
          ]
  
      return expected_map_states
  
file_path: pyro/tests/contrib/mue/test_missingdatahmm.py
imports: import pytest
  import torch
  from pyro.contrib.mue.missingdatahmm import MissingDataDiscreteHMM
  from pyro.distributions import Categorical, DiscreteHMM
label_desc: Use image node_id 7 for calling a global function with example usage: indiv_map_states(a0, a, e, x) and returns: expected_map_states