Pure discretization with refinement

I am using the toolkit to solve an infinite horizon model with endogenous labor supply (similar to Pijoan-Mas RED 2006) with the method ‘pure_discretization_refine’.

This method turns out to be 50% faster than the standard without refinement. As far as I understand it precomputes the optimal d choice for each triplet (a’,a,z) so that there is no need to optimize over d in each VF iteration.

I think there is a bug in the following code, though:

When calling the function we pass as inputs n_d,n_a,n_z but in the function we use sometimes N_a and N_z instead of n_a, n_z. Since Matlab is case sensitive, this throws an error. I have replaced N_a with n_a and N_z with n_z and all is fine.

This is why ‘refine’ is not yet a publicly documented feature :wink:

Your understanding is exactly right. That is also why this ‘refine’ made solving the Kitao (2008) stationary eqm easy, but did not help for the transition path (in the infinite horizon you can presolve for d, and then use this at every iteration, but for the transition path the d has to be different in every period, so even if you presolve for d you then would only use this once).

Nice that it also speeds up notably for a model similar to Pijoan-Mas (2006). I haven’t actually yet tried using it anywhere except on that Kitao (2008) code so good to know it is something I should maybe think about making the default.

I corrected this by putting,

N_a=prod(n_a);
N_z=prod(n_z);

near start of this function.

VFI Toolkit uses n_a to be a vector of the number of points in each dimension (e.g., if you have two endogenous states with 201 and 101 points respectively, then n_a=[201,101]), whereas when everything then gets vectorized internally N_a is used (so would have N_a=20301, which is 201*101). In your case as there was just one dimension for n_a, you were able to just set N_a=n_a with no issues. Same for n_d vs N_d, n_z vs N_z etc., the lower case is the vector of number of points in each dimension and the upper case is the product of this vector (awkward wording, but it is the number of points in the vectorized problem). All of this is normally hidden from the user, but since you are looking inside you are seeing it all :slight_smile:

1 Like

Hi Robert,
Thanks for your answer! To me it makes sense using ‘refine’ as default. It should also be better in terms of memory requirements: during each VF iteration, the returnMatrix is na * na * nz instead of nd* na * na * nz.

Hi Robert,

I checked the updated code on github

and there is a typo:

N_a=prod(n_a);
N_a=prod(n_z); %It should be N_z=prod(n_z);

I realized it because I got an error when I tried to run the code :slight_smile:

I fixed it manually in my local copy and it works smooth and fast!

Oops, fixed, thanks!

1 Like

The refinement option works really well… I’ve tested on the Pijoan-Mas model (baseline parametrization with possibly some tax function added) and it speeds up the code by 50%. I attach the codes which may be useful for some user

In the file change the following options:

vfoptions.solnmethod = ‘purediscretization_refinement’;
%vfoptions.solnmethod = ‘purediscretization’;

The method ‘purediscretization’ is the toolkit default, while ‘purediscretization_refinement’ is the refinement with precomputation of optimal d

Refinement is now the default for infinite horizon value function problems. So everyone can benefit from code running a little bit faster :slight_smile:

1 Like