Hello Robert,
I am a user of the VFI Toolkit and am trying to replicate the main results from the GourinchasParker2002.m example.
The script runs for a while, but eventually terminates with a gpuArray/arrayfun error related to a POWER operation. The full error message and call stack are as follows (matlab2004b)
可能存在局部最小值。
lsqnonlin 已停止,因为当前步长小于
步长容差的值。错误使用 gpuArray/arrayfun
POWER: needs to return a complex result, but this is not supported for real input X and Y on the GPU. Use POWER(COMPLEX(X),COMPLEX(Y,0)) instead.出错 CreateReturnFnMatrix_Case1_Disc_DC1_nod_Par2e (第 33 行)
Fmatrix=arrayfun(ReturnFn, aprime_grid, shiftdim(a_grid,-1), shiftdim(z_gridvals(:,1),-2), shiftdim(e_gridvals(:,1),-3), ParamCell{:});
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
出错 ValueFnIter_FHorz_DC1_nod_e_raw (第 38 行)
ReturnMatrix_ii=CreateReturnFnMatrix_Case1_Disc_DC1_nod_e_raw(ReturnFn, n_z, n_e, a_grid, a_grid(level1ii), z_gridvals_J(:,:,N_j), e_gridvals_J(:,:,N_j), ReturnFnParamsVec,1);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
… (rest of the call stack)
Analysis:
Based on the error message, it appears that a POWER operation (e.g., x^y) is being applied on the GPU, where the base x is a negative real number and the exponent y is a non-integer. This would require a complex result, which the GPU does not support in this context.
The traceback points to CreateReturnFnMatrix_Case1_Disc_DC1_nod_Par2e calling ReturnFn. My hypothesis is that this error originates from the GourinchasParker2002_ReturnFn.m function, likely when the consumption c = R*a + z*e - aprime becomes a very small or negative value, causing the utility calculation c^(1-rho) to fail, as 1-rho is a non-integer.
The lsqnonlin warning about a potential local minimum also suggests that the optimization process is exploring regions of the parameter space that may lead to these numerical issues.
Question:
Could you please advise on how to handle this? Is there a common fix for this issue within the GP2002 model? I suspect the problem is that some combination of parameters or grid points is leading to negative consumption.
Is there a recommended way to:
- Adjust the grids (
a_grid,z_grid) to prevent negative consumption? - Add a small value (e.g.,
epsilon) to consumption, such as(c + 1e-6)^(1-rho), to prevent it from going to zero or negative?
Any guidance on how to resolve this numerical instability would be greatly appreciated.
Thank you very much for your help!