code: def thetacalc(
      y: np.ndarray,
      states: np.ndarray,  # states
      modeltype: int,
      initial_smoothed: float,
      alpha: float,
      theta: float,
      e: np.ndarray,
      amse: np.ndarray,
      nmse: int,
  ) -> float:
      denom = np.zeros(nmse)
      f = np.zeros(nmse)
      # update first state
      states[0, :] = initstate(
          y=y,
          modeltype=modeltype,
          initial_smoothed=initial_smoothed,
          alpha=alpha,
          theta=theta,
      )
  
      amse[:nmse] = 0.0
      e[0] = y[0] - states[0, 4]
      n = len(y)
      for i in range(1, n):
          # one step forecast
          thetafcst(
              states=states,
              i=i,
              modeltype=modeltype,
              f=f,
              h=nmse,
              alpha=alpha,
              theta=theta,
          )
          if math.fabs(f[0] - NA) < TOL:
              mse = NA
              return mse
          e[i] = y[i] - f[0]
          for j in range(nmse):
              if (i + j) < n:
                  denom[j] += 1.0
                  tmp = y[i + j] - f[j]
                  amse[j] = (
                      amse[j] * (denom[j] - 1.0) + (tmp * tmp)
                  ) / denom[j]
          # update state
          thetaupdate(
              states=states,
              i=i,
              modeltype=modeltype,
              alpha=alpha,
              theta=theta,
              y=y[i],
              usemu=0,
          )
      mean_y = np.mean(np.abs(y))
      if math.fabs(mean_y - 0.0) < TOL:
          mean_y = TOL
      mse = np.sum(e[3:] ** 2) / mean_y
      return mse
  
imports: import math
  from typing import Tuple
  import numpy
  from numba import njit
  from scipy.stats import norm
  from statsmodels.tsa.seasonal import seasonal_decompose
  from statsmodels.tsa.stattools import acf
  from .ets import restrict_to_bounds, results
  from .utils import _seasonal_naive, _repeat_val_seas, CACHE, NOGIL
label_desc: Use image node_id 2 for calling a global function with example usage: thetacalc(y, states, modeltype, initial_smoothed, alpha, theta, e, amse, nmse) and returns: mse, mse