I am writing a code to update parameters. The code involves a total of BURNIN+N
iterations, and in each iteration, the parameters are updated. The main program code is as follows:
@jit(nopython=True)
def MCMC(Y, V, mu, omega, psi, kappa, theta):
for i in range(1, BURNIN + N):
mu = update_mu(deltat, i, T, Y, V, mu, omega, psi, kappa, theta)
omega, psi = update_omega_psi(deltat, i, T, Y, V, mu, omega, psi, kappa, theta)
theta = update_theta(deltat, i, T, Y, V, mu, omega, psi, kappa, theta)
kappa = update_kappa(deltat, i, T, Y, V, mu, omega, psi, kappa, theta)
V = update_V(i, T, Y, V, mu, omega, psi, kappa, theta)
The code for parameter updates is as follows:
@guvectorize([(float64, int64, int64, float64[:], float64[:,:], float64[:], float64[:], float64[:], float64[:], float64[:], float64[:])],
'(),(),(),(n),(m,n),(m),(m),(m),(m),(m)->(m)',
nopython=True)
def update_mu(deltat, i, T, Y, V, mu, omega, psi, kappa, theta, res):
mustara = sum((omega[i-1] + psi[i-1]**2) * (Y[1:T+1] + 0.5 * V[i-1, :T] * deltat) / (omega[i-1] * V[i-1, :T]))
mustarb = sum(psi[i-1] * (V[i-1, 1:T+1] - kappa[i-1] * theta[i-1] * deltat - (1 - kappa[i-1] * deltat) * V[i-1, :T]) / (omega[i-1] * V[i-1, :T]))
mustar = (mustara - mustarb + (mu0 / sigma0**2)) / (deltat * sum((omega[i-1] + psi[i-1]**2) / (omega[i-1] * V[i-1, :T])) + 1 / sigma0**2)
sigstar = np.sqrt(1 / (deltat * sum((omega[i-1] + psi[i-1]**2) / (omega[i-1] * V[i-1, :T])) + 1 / sigma0**2))
res[i] = np.random.normal(mustar, sigstar)
For the parameter mu
, the updated value from each iteration is stored in res
and then reassigned to mu
, which facilitates the next iteration. However, I encountered the following error:
TypingError: Cannot determine Numba type of <class 'numba.core.ir.UndefinedType'>
How to address this problem? Thanks in advance !