Values on Grid with semi-exogenous shocks

I would like to compute the values on grid for all functions to evaluate in the case of a model with semi-exogenous shocks. When I call the function EvalFnOnAgentDist_ValuesOnGrid_FHorz_Case1_PType, it returns with the following error message:

Error using gpuArray/reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for
that dimension.

Error in EvalFnOnAgentDist_ValuesOnGrid_FHorz_Case1_PType (line 271)
                        ValuesOnGrid.(FnNames{kk}).(Names_i{ii})=gather(reshape(ValuesOnGrid_ii.(FnNames{kk}),[n_a_temp,n_ze_temp,N_j_temp]));
                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in fun_model_moments (line 54)
Values_struct=EvalFnOnAgentDist_ValuesOnGrid_FHorz_Case1_PType(StatDist_in,Policy_in,FnsToEval,Params,n_d,n_a,n_z,N_j,N_i,d_grid,a_grid,z_grid,simoptions);
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in solve_model (line 147)
    mom = fun_model_moments(Params,FnsToEval,V,StatDist,Policy,Gr,flag,simoptions);
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in main (line 35)
    [sol,sol_cpu,mom] = solve_model(Params,Gr,flag,vfoptions,simoptions,FnsToEval);
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The reason is that it does not seem to recognize the presence of semi-exogenous shocks: when it does the reshape,

reshape(ValuesOnGrid_ii.(FnNames{kk}),[n_a_temp,n_ze_temp,N_j_temp]

it puts the z and e shocks together in n_ze_temp but it forgets about the semiz!

Any help with this issue is really appreciated! Thanks in advance :slight_smile:

2 Likes

Will be an easy fix, but Iā€™m not back to my computer until start of Jan so will have to wait until then. Thanks for letting me know.

1 Like

Perfect, thanks! I find this function very useful when I want to use the toolkit to solve the model (computing policy functions, distribution) but then write my own code to calculate moments of interest

1 Like