Thanks for the tip!
I’m a bit wary of hardcoding
alreadygridvals_semiexo=0
though.
In my example I set semiz_grid as a stacked column grid, with size [sum(n_semiz),1], so it is ok to tell the code that semiz is not already in gridvals format.
But if I set semiz_grid as joint grid, with size [prod(n_semiz),length(n_semiz)]?
At line 79 we are filling in defaults. If you are doing non-default things, it’s on you to tell the toolkit what you are doing. My $0.02.
1 Like
I think we should do something like this:
Check if user’s provided semiz_grid is stacked column grid or joint grids.
If it is joint grids, set alreadygridvals_semiexo=1, otherwise equal to 0.
The only problem is that I didn’t find where options.alreadygridvals_semiexo is first set in the code. Maybe I should just see how this is done for the related variable alreadygridvals.
I solved the problem by adding the following code in LifeCycleProfiles_FHorz_Case1_PType around lines 163-165:
if ~isfield(simoptions,'alreadygridvals_semiexo')
simoptions.alreadygridvals_semiexo=0;
end
This is exactly the same logic as the existing
if ~isfield(simoptions,'alreadygridvals')
simoptions.alreadygridvals=0;
end
Thanks @MichaelTiemann for your suggestions.
@robertdkirkby Can you confirm that this change is correct?
1 Like
Just merged @aledinola pull request
master ← aledinola:ale
opened 07:22PM - 30 Mar 26 UTC
This PR fixes two bugs that arise in finite-horizon semi-exogenous (semiz) PType… workflows.
1. StationaryDist/FHorz/SemiExo/StationaryDist_FHorz_Iteration_SemiExo_noz_raw.m
The distribution recursion was indexing pi_semiz_J as
semiztransitions = gather(pi_semiz_J(semizindex(:,:,jj)));
but pi_semiz_J is age-dependent, with size [N_semiz, N_semiz, N_dsemiz, N_j], while semizindex(:,:,jj) only indexes the first three dimensions. This means the age slice was not being selected correctly.
The fix is to first select the age-jj slice
pi_semiz_J_jj = pi_semiz_J(:,:,:,jj);
and then apply semizindex(:,:,jj) to that 3D array.
2. EvaluateFnOnAgentDist/FHorz/PType/LifeCycleProfiles_FHorz_Case1_PType.m
This helper was missing a default for simoptions.alreadygridvals_semiexo. In semiexogenous finite-horizon PType calls, this can raise:
Unrecognized field name "alreadygridvals_semiexo".
The fix adds the missing default in both the branch where simoptions is created internally and the branch where it is supplied by the caller.
Verification
I verified these changes using a finite-horizon life-cycle model with semi-exogenous states and permanent types. After the fixes, the toolkit solution and a direct MATLAB implementation matched exactly for value functions, policy functions, stationary distributions, unconditional means, and life-cycle profiles by age and by age-permanent-type. All reported comparison errors were zero in this test case.
Pretty sure this solve all of this.
Everything looked right to me around setting the alreadygridvals_semiexo defaults.
Tell me if anything is still outstanding here, my impression is that pull request covers everything being discussed in this thread.
1 Like