code: def test_logistic():
      logistic = markov_switching._logistic
  
      # For a number, logistic(x) = np.exp(x) / (1 + np.exp(x))
      cases = [0, 10.0, -4]
      for x in cases:
          # Have to use allclose b/c logistic() actually uses logsumexp, so
          # they're not equal
          assert_allclose(logistic(x), np.exp(x) / (1 + np.exp(x)))
  
      # For a vector, logistic(x) returns
      # np.exp(x[i]) / (1 + np.sum(np.exp(x[:]))) for each i
      # but squeezed
      cases = [[1.0], [0, 1.0], [-2, 3.0, 1.2, -30.0]]
      for x in cases:
          actual = logistic(x)
          desired = [np.exp(i) / (1 + np.sum(np.exp(x))) for i in x]
          assert_allclose(actual, desired)
  
      # For a 2-dim, logistic(x) returns
      # np.exp(x[i, t]) / (1 + np.sum(np.exp(x[:, t]))) for each i, each t
      # but squeezed
      case = [[1.0]]
      actual = logistic(case)
      assert_equal(actual.shape, (1, 1))
      assert_allclose(actual, np.exp(1) / (1 + np.exp(1)))
  
      # Here, np.array(case) is 2x1, so it is interpreted as i=0, 1 and t=0
      case = [[0], [1.0]]
      actual = logistic(case)
      desired = [np.exp(i) / (1 + np.sum(np.exp(case))) for i in case]
      assert_allclose(actual, desired)
  
      # Here, np.array(case) is 1x2, so it is interpreted as i=0 and t=0, 1
      case = [[0, 1.0]]
      actual = logistic(case)
      desired = np.exp(case) / (1 + np.exp(case))
      assert_allclose(actual, desired)
  
      # For a 3-dim, logistic(x) returns
      # np.exp(x[i, j, t]) / (1 + np.sum(np.exp(x[:, j, t])))
      # for each i, each j, each t
      case = np.arange(2 * 3 * 4).reshape(2, 3, 4)
      actual = logistic(case)
      for j in range(3):
          assert_allclose(actual[:, j, :], logistic(case[:, j, :]))
  
file_path: statsmodels/statsmodels/tsa/regime_switching/tests/test_markov_switching.py
imports: import numpy
  from numpy.testing import assert_equal, assert_allclose, assert_raises
  import pandas
  from statsmodels.tools.numdiff import approx_fprime_cs
  from statsmodels.tsa.regime_switching import markov_switching
label_desc: Use image node_id 6 for calling a global function with example usage: test_logistic() without return types