def cy_kim_smoother(regime_transition, predicted_joint_probabilities, filtered_joint_probabilities):
 k_regimes = filtered_joint_probabilities.shape[0]
 nobs = filtered_joint_probabilities.shape[(-1)]
 order = (filtered_joint_probabilities.ndim - 2)
 dtype = filtered_joint_probabilities.dtype
 smoothed_joint_probabilities = np.zeros((((k_regimes,) * (order + 1)) + (nobs,)), dtype=dtype)
 if (regime_transition.shape[(-1)] == (nobs + order)):
  regime_transition = regime_transition[..., order:]
 (prefix, dtype, _) = find_best_blas_type((regime_transition, predicted_joint_probabilities, filtered_joint_probabilities))
 func = prefix_kim_smoother_map[prefix]
 func(nobs, k_regimes, order, regime_transition, predicted_joint_probabilities.reshape((k_regimes ** (order + 1)), nobs), filtered_joint_probabilities.reshape((k_regimes ** (order + 1)), nobs), smoothed_joint_probabilities.reshape((k_regimes ** (order + 1)), nobs))
 smoothed_marginal_probabilities = smoothed_joint_probabilities
 for i in range(1, (smoothed_marginal_probabilities.ndim - 1)):
  smoothed_marginal_probabilities = np.sum(smoothed_marginal_probabilities, axis=(-2))
 return (smoothed_joint_probabilities, smoothed_marginal_probabilities)

def cy_kim_smoother ( regime_transition , predicted_joint_probabilities , filtered_joint_probabilities ) : k_regimes = filtered_joint_probabilities . shape [ 0 ] nobs = filtered_joint_probabilities . shape [ ( - 1 ) ] order = ( filtered_joint_probabilities . ndim - 2 ) dtype = filtered_joint_probabilities . dtype smoothed_joint_probabilities = np . zeros ( ( ( ( k_regimes , ) * ( order + 1 ) ) + ( nobs , ) ) , dtype = dtype ) if ( regime_transition . shape [ ( - 1 ) ] == ( nobs + order ) ) : regime_transition = regime_transition [ ... , order : ] ( prefix , dtype , _ ) = find_best_blas_type ( ( regime_transition , predicted_joint_probabilities , filtered_joint_probabilities ) ) func = prefix_kim_smoother_map [ prefix ] func ( nobs , k_regimes , order , regime_transition , predicted_joint_probabilities . reshape ( ( k_regimes ** ( order + 1 ) ) , nobs ) , filtered_joint_probabilities . reshape ( ( k_regimes ** ( order + 1 ) ) , nobs ) , smoothed_joint_probabilities . reshape ( ( k_regimes ** ( order + 1 ) ) , nobs ) ) smoothed_marginal_probabilities = smoothed_joint_probabilities for i in range ( 1 , ( smoothed_marginal_probabilities . ndim - 1 ) ) : smoothed_marginal_probabilities = np . sum ( smoothed_marginal_probabilities , axis = ( - 2 ) ) return ( smoothed_joint_probabilities , smoothed_marginal_probabilities )
kim smoother using cython inner loop parameters regime_transition : array matrix of regime transition probabilities .