code: def test_avoid_underflow():
      # See GH5380 for example and dataset demonstrating underflow. This test is
      # the "Example 1" given there.
  
      # The underlying problem was an underflow error in computing the smoothed
      # states, which resulted in NaN values in e.g. smoothed_joint_probabilities
      # This causes NaNs in the EM algorithm (e.g. _em_regime_transition), and
      # so the _fit_em method would return NaN parameters, as would the fit
      # method.
  
      # This test runs the smoother at the last set of good parameter values
      # (i.e. these parameters were generated by _fit_em and did not have any
      # NaN values in them, but the smoothed_joint_probabilities computed at
      # those parameters have NaNs in them, so that the next set of parameters
      # would have NaNs). The test then checks that the underflow problem has
      # been resolved, i.e. that there are no NaNs in the predicted, filtered,
      # and smoothed joint probabilities.
      m = markov_regression.MarkovRegression(
          gh5380_series, k_regimes=2, switching_variance=True
      )
      # To get these params, the following command was used:
      # params = m._fit_em(maxiter=1).params
      params = np.array(
          [
              6.97337611e-01,
              6.26116329e-01,
              -6.41266551e-06,
              3.81141202e-06,
              4.72462327e-08,
              4.45291473e-06,
          ]
      )
      res = m.smooth(params)
  
      assert not np.any(np.isnan(res.predicted_joint_probabilities))
      assert not np.any(np.isnan(res.filtered_joint_probabilities))
      assert not np.any(np.isnan(res.smoothed_joint_probabilities))
  
imports: import os
  import warnings
  import numpy
  from numpy.testing import assert_allclose, assert_raises
  import pandas
  import pytest
  from statsmodels.tsa.regime_switching import markov_switching, markov_regression
label_desc: Use image node_id 1 for calling a global function with example usage: test_avoid_underflow() without return types