code: def test_viterbi_discriminative_multi():
      # A pre-baked example with coin tosses
  
      transition = np.asarray([[0.75, 0.25], [0.25, 0.75]])
  
      # Joint XY model
      p_joint = np.asarray([[0.25, 0.25], [0.1, 0.4]])
  
      # marginals
      p_obs_marginal = p_joint.sum(axis=0)
      p_state_marginal = p_joint.sum(axis=1)
  
      p_init = p_state_marginal
  
      # Make the Y|X distribution
      p_state_given_obs = (p_joint / p_obs_marginal).T
  
      # Let's make a test observation sequence
      seq = np.asarray([1, 1, 0, 1, 1, 1, 0, 0])
  
      # Then our conditional probability table can be constructed directly as
      prob_d = np.asarray([p_state_given_obs[i] for i in seq]).T
  
      # Make a three-channel stack
      prob_mc = np.stack([prob_d, 1 - prob_d, prob_d[:, ::-1]])
      path, logp = librosa.sequence.viterbi_discriminative(
          prob_mc,
          transition,
          p_state=p_state_marginal,
          p_init=p_init,
          return_logp=True,
      )
  
      # Check the second code path
      path2 = librosa.sequence.viterbi_discriminative(
          prob_mc,
          transition,
          p_state=p_state_marginal,
          p_init=p_init,
          return_logp=False,
      )
      assert np.array_equal(path, path2)
  
      path0, logp0 = librosa.sequence.viterbi_discriminative(
          prob_mc[0],
          transition,
          p_state=p_state_marginal,
          p_init=p_init,
          return_logp=True,
      )
      assert np.allclose(path0, path[0])
      assert np.allclose(logp0, logp[0])
  
      path1, logp1 = librosa.sequence.viterbi_discriminative(
          prob_mc[1],
          transition,
          p_state=p_state_marginal,
          p_init=p_init,
          return_logp=True,
      )
      assert np.allclose(path1, path[1])
      assert np.allclose(logp1, logp[1])
  
      path2, logp2 = librosa.sequence.viterbi_discriminative(
          prob_mc[2],
          transition,
          p_state=p_state_marginal,
          p_init=p_init,
          return_logp=True,
      )
      assert np.allclose(path2, path[2])
      assert np.allclose(logp2, logp[2])
  
imports: import numpy
  import pytest
  from test_core import srand
  import librosa
label_desc: Use image node_id 8 for calling a global function with example usage: test_viterbi_discriminative_multi() without return types