Error with discretizeAR1_Tauchen part II

Hi everyone and thanks Robert for all your hard work on the VFI toolkit (from one Robert to another).

When I first downloaded the VFI toolkit last year and tried out the examples, everything worked fine with no issues. This summer, I wanted to give it a proper go, but since then I have upgraded my MATLAB version to 2024b. I’ve just returned to the VFI toolkit (I downloaded the latest version from GitHub), but I am now encountering the same problem as described in this post - getting the “Unrecognized function or variable ‘discretizeAR1_Tauchen’” error, as well as the same issue with discretizeAR1_FarmerToda() and discretizeAR1_Rouwenhorst(). These errors showed up when I was trying to run the Aiyagari1994.m file.

I guess the easiest workaround would be to reinstall MATLAB 2023b, but the problem is that I upgraded to the newer version for other projects. Is there an easy fix that doesn’t involve swapping between MATLAB versions? Unless I’m the only one getting this error, which would mean I’m probably doing something wrong.

Thanks,
Rob

1 Like

Hi @robertF,

Can you please copy and paste the error message that you get?

I get an error if I run the example Aiyagari1994 available on VFItoolkit-matlab-examples/HeterogeneousAgentModels at master · vfitoolkit/VFItoolkit-matlab-examples · GitHub

@robertF Is it the same error that you have found?

Grid sizes are: 512 points for assets, and 11 points for exogenous shock 
Calculating price vector corresponding to the stationary general eqm 
Error using ValueFnIter_Case1 (line 167)
Problem with pi_z in ValueFnIter_Case1: rows do not sum to one \n

Error in HeteroAgentStationaryEqm_Case1_subfn (line 18)
[~,Policy]=ValueFnIter_Case1(n_d,n_a,n_z,d_grid,a_grid,z_grid, pi_z, ReturnFn, Parameters, DiscountFactorParamNames,ReturnFnParamNames,vfoptions);
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in HeteroAgentStationaryEqm_Case1>@(p)HeteroAgentStationaryEqm_Case1_subfn(p,n_d,n_a,n_z,l_p,pi_z,d_grid,a_grid,z_grid,ReturnFn,FnsToEvaluate,GeneralEqmEqns,Parameters,DiscountFactorParamNames,ReturnFnParamNames,FnsToEvaluateParamNames,GeneralEqmEqnParamNames,GEPriceParamNames,heteroagentoptions,simoptions,vfoptions) (line 268)
        GeneralEqmConditionsFnOpt=@(p) HeteroAgentStationaryEqm_Case1_subfn(p, n_d, n_a, n_z, l_p, pi_z, d_grid, a_grid, z_grid, ReturnFn, FnsToEvaluate, GeneralEqmEqns, Parameters, DiscountFactorParamNames, ReturnFnParamNames, FnsToEvaluateParamNames, GeneralEqmEqnParamNames, GEPriceParamNames, heteroagentoptions, simoptions, vfoptions);
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in fminsearch (line 209)
fv(:,1) = funfcn(x,varargin{:});
          ^^^^^^^^^^^^^^^^^^^^^
Error in HeteroAgentStationaryEqm_Case1 (line 291)
        [p_eqm_vec,GeneralEqmConditions]=fminsearch(GeneralEqmConditionsFnOpt,p0,minoptions);
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in Aiyagari1994 (line 103)
[p_eqm,~,GeneralEqmCondn]=HeteroAgentStationaryEqm_Case1(n_d, n_a, n_z, 0, pi_z, d_grid, a_grid, z_grid, ReturnFn, FnsToEvaluate, GeneralEqmEqns, Params, DiscountFactorParamNames, [], [], [], GEPriceParamNames,heteroagentoptions, simoptions, vfoptions);
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The program is complaining that the rows of pi_z, the transition matrix of the shock, do not sum to one. pi_z is generated by the Tauchen discretization routine

Hi @aledinola, thanks for checking that’s the error I am getting:

Unrecognized function or variable ‘discretizeAR1_Tauchen’.

Error in Aiyagari1994 (line 33)
[z_grid,pi_z]=discretizeAR1_Tauchen(0,Params.rho,sqrt((1-Params.rho^2)*Params.sigma^2),n_z,Tauchen_q);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

which is different to yours. I re-downloaded all the examples from GitHub, so we should be using the same file. In your case, it can find the function but runs into the summation problem, whereas in my case, it seems can’t find the function. I am adding the path to the toolkit via:

addpath(“C:\Users...\VFIToolkit”)

They are still there, e.g.,

What will be happening is that Matlab cannot find them. Unrecognized function or variable 'X' is Matlab’s way of saying it cannot find X. There are two possible reasons, either it does not exists, or Matlab simply does not know where it is.

Since we know it exists, the issue in this case is that Matlab cannot find it. Matlab only looks for things in the ‘workspace’ and in the ‘active path’. The problem in this instance is that ‘discretizeAR1_Tauchen’ exists, but it is not on the active path. Likely you are missing the whole of VFI Toolkit from the active path, and so you need to add it.
Tell Matlab where the Toolkit is by adding it to the Matlab path.

I expect this will solve it, let me know if not.

PS. Looking at your later post. The error is because you use addpath() which only adds that folder, not any subfolders. You need to use addpath(genpath()) so that it adds that folder and all subfolders.

2 Likes

Thanks Robert, all good. No idea what I was doing.

2 Likes

Can you try running the file Aiyagari1994.m? I think now you should get the error message that I had reported
Thanks!

I’m getting now:

Grid sizes are: 512 points for assets, and 11 points for exogenous shock
Calculating price vector corresponding to the stationary general eqm
Error using zeros
Unable to find a supported GPU device.

Error in ExogShockSetup (line 62)
z_gridvals=zeros(prod(n_z),length(n_z),‘gpuArray’);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in HeteroAgentStationaryEqm_Case1 (line 182)
[z_grid, pi_z, vfoptions]=ExogShockSetup(n_z,z_grid,pi_z,Parameters,vfoptions,3);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in Aiyagari1994 (line 100)
[p_eqm,~,GeneralEqmCondn]=HeteroAgentStationaryEqm_Case1(n_d, n_a, n_z, 0, pi_z, d_grid, a_grid, z_grid, ReturnFn, FnsToEvaluate, GeneralEqmEqns, Params, DiscountFactorParamNames, , , , GEPriceParamNames,heteroagentoptions, simoptions, vfoptions);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Related documentation

Let me have a look and report back (I don’t have a GPU so would have run with CPU).

1 Like

I made some changes last week, they have broken “without GPU” (I didn’t notice as I never use the without GPU version).

I will fix this in next day or two and let you know once done.

1 Like

Hi Rob, there is still an error even with GPU though

Both gpu and cpu are fixed now.

(I was doing some internal reworking to allow ExogShockFn in infinite horizon. Left minor typo in there for the usual cases.)

1 Like

Thanks, Robert. I’ve re-downloaded the toolkit.

@aledinola - everything runs fine on my CPU now. I just ran the Aiyagari1994.m file and no error messages came up. Are you still getting the error when running Aiyagari1994.m with MATLAB 2024b?

1 Like