Take 3: OLG Model14 mixed horizon fixes#57
Open
MichaelTiemann wants to merge 14 commits intovfitoolkit:masterfrom
Open
Take 3: OLG Model14 mixed horizon fixes#57MichaelTiemann wants to merge 14 commits intovfitoolkit:masterfrom
MichaelTiemann wants to merge 14 commits intovfitoolkit:masterfrom
Conversation
OLGModel14 attempts to solve a GE for households (with finite horizons) and firms (with infinite horizons). While there are plenty of functions for solving for one type of horizon or another, we must make some accommodations for mixtures of the two. Given there is already some code in the FHorz cases for the occasional infinite horizon, I attempted to flesh that out until the GE could be solved without throwing errors. I took the liberty of keeping InfHorz grids named without the _J suffix, just so we'd get an error if we sent the wrong parameters to the wrong function. I also saw what appeared to be minor drifts in the implementations of the two types of functions, and I copy/pasted what appeared to be the more elaborated code to the side that seemed to be missing it.
As an alternative to getInterpMatrix function, use the value exp(-500) as a zero-like value. When added to any "normal" floating point value it will read as zero, and when multiplied by an +/-Inf value it will preserve the +/-Inf value instead of converting it to NaN (which happens when multiplied by actual zero). Also, give a warning when Howards-greedy is given a `ReturnMatrix` containing an infinite value (it cannot handle that). And clean up some typos we found.
Return to resolving OLGModel14 changes needed to run. To wit: HeteroAgentStationaryEqm_Case1_FHorz_PType: add some clarifying comments about how we have moved code around to reduce duplication between FHorz and InfHorz cases that can be mixed together (as OLGModel14 does). HeteroAgentStationaryEqm_Case1_PType: Mostly clean and comment. Also remove error message related to no implemented functionality. Is it now implemented? ValueFnIter_nod_HowardGreedy_raw: if we should call this function without ever evaluating the return function (because `maxiter` was zero or some such, then `Ftemp` would never have been initialized. I restored the test for non-finite values inside the loop because testing a matrix that's `n_a` by `n_z` is relatively cheap, and it's very valuable for people to see the moment the bad value pops up (for easier debugging).
MichaelTiemann
added a commit
to MichaelTiemann/OLG-Electrify
that referenced
this pull request
Feb 8, 2026
Adapted changes from ElectrifyHousehold into Electrify (the OLG model). Requires this Pull Request to work: vfitoolkit/VFIToolkit-matlab#57
In my particular case, the toolkit was trying to allocate overly large arrays when `lowmemory==2` was selected. Specifically: ``` DiscountedEV=DiscountFactorParamsVec*repelem(EV,N_d1,N_a1,1); ``` Replicated a large `EV` N_d1 times N_a1 times is unnecessary, as the loop for `lowmemory==2` doesn't use all of EV, but iterates across the `z`s (as well as the `e`s. I noticed that other ExpAsset codes already had the fixes I am proposing herein (namely, replicate based on `EV(:,:,z_c)` rather than all of EV and then selecting the `z` elements from that). I also noticed that other codes had optimizations like lifting some array constructions out of loops, etc. I attempted to therefore coalesce the best of all across all in this directory. There's obviously more work to be done for more code cases, but I thought I'd start with this bite-sized chunk. Normally I'd create a fresh branch for these changes and a clean pull request. But I need these changes in the OLGModel14-mixed-horizon-fixes branch, which might need a while before its merged. So I'm leaving it to you to decide whether you want to `git cherry-pick` this commit and merge into the main branch ahead of that decision.
This change implements support for CustomModelStats when `heteroagentoptions` has PType specifiers (i.e., `heteroagentoptions.household.CustomModelStats`). In this implementation, we can support CustomModelStats for each different PType, separately. This is a simple case because each PType is only either FHorz or InfHorz. It does not yet support a overarching PType implementation whereby a single CustomModelStats can see all PTypes at once. This case is more difficult, as different PTypes can have different horizons, thus a universal CustomModelStats function would have to unpack that before calling magical subfunctions.
…ichaelTiemann/VFIToolkit-matlab into OLGModel14-mixed-horizon-fixes
Contributor
|
Is it possible to split this pull request into parts? I am happy to merge the changes to: But I want to take some more time to look over the others. If you can put this two as a separate pull request I am happy to just merge that directly. |
Contributor
Author
|
I can look at doing so when I return from a trip in about a week's time. I don't have a computer I can use for this purpose while I'm travelling, alas. |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These changes allow OLGModel14 to find the equilibrium we've seen before. It remains a bit wide (equations getting to about +/- 1-6%, not three sig figs of zeros), but I don't think that's the fault of these changes.
As you will see below, I've added comments in places to make it more clear that the changes are not as big as they appear. There are also more comments in the recent individual commits making up these changes.