I have discovered the ill effects of having a large-but-irrelevant GE term ruin the solution to an otherwise solvable GE system. For example in my case TargetCapitalRatio trying to equalize K/L with a target of 2.03. The fact that I’ve changed enough things to break that number means that disparity can prevent finding anything sane in the rest of the equations.
By highlighting the most unhappy general equilibrium equation, it greatly simplifies tracking what’s driving the solver. And I can do that with the free add-on cprintf.
fprintf('Current GeneralEqmEqns: \n')
[~,maxidx]=max(GeneralEqmConditionsVec.^2);
for gg=1:length(GEeqnNames)
if gg==maxidx
cprintf('err', heteroagentoptions.verboseaccuracy2,GEeqnNames{gg},GeneralEqmConditionsVec(gg))
else
fprintf(heteroagentoptions.verboseaccuracy2, GEeqnNames{gg},GeneralEqmConditionsVec(gg))
end
end
Just a thought…
You mean make it so that the ‘worst’ GE condn is highlighted (is in colour)?
1 Like
Exactly. That’s going to tell you where to GE solver paid the most attention (to the possible detriment of others).
1 Like
Interesting! Apparently cprintf is a matlab utility written by Yair Altman:
https://uk.mathworks.com/matlabcentral/fileexchange/24093-cprintf-display-formatted-colored-text-in-command-window
Worth checking compatibility issues with R2025, see discussion in the link above.
Since I’m just interested in rendering simple colored text, not HTML or such, no compatibility issues at all. It’s fun watching the red color bounce around some relatively evenly matched GE conditions as the solver does its work.
1 Like
Apparently the runtime for cprintf() is non-negligible (over one second)
https://au.mathworks.com/matlabcentral/answers/424450-is-it-possible-to-print-color-text-in-the-command-window
So unfortunately I am going to avoid implementing this. Idea is good, but one second is way to long for something that is non-necessary/convenience and has to be done at every iteration of which there are often hundreds.
PS. On large models you wouldn’t really notice the 1s, but on small models it is going to almost double runtimes.
My reading of that post is that it took 1.8 sec to do 100 (1e2) iterations, compared to negligible time to do 100 iterations of fprintf. Would a routine that takes 0.018 extra seconds per iteration score differently in your mind? In the course of printing GE prices, there’s no visible delay as the results are printed out.
Fair point, is 0.018s. This is fast enough per stationary general eqm iteration to be irrelevant.
From a practical perspective, looking at the license for cprintf it appears that it can be redistributed as part of VFI Toolkit. It gets updated roughly once a year, so would likely need to be kept up to the latest version (because it is ‘undocumented matlab’ it is the kind of thing liable to break). I guess I could create folder in /Other/cprintf and put both the m-file and the txt license file in there.
In terms of use in toolkit, I would be inclined to have it apply colour only when using heteroagentoptions.verbose=2. Maybe rather than the largest, it just applies to any/all that are more than an order of magnitude larger than the average.
Sound sensible? @MichaelTiemann @aledinola since you two are the ones who want the functionality does this seem like a good approach?
As with everything else, users will chime in with their suggestions. Right now I’m using the err color (a darker red) to indicate the long pole in the tent and the comment color (a sensible green) to show AggVars that are being forwarded from earlier PTypes before the final step. I’m sure others will find cool uses.
Regarding the verbose=2 option, I don’t know how much additional chatter that adds. If the extra chatter makes it difficult to observe the evolution of the GE, then it defeats the purpose that motivated me in the first place.
The toolkit does depend on cost-additional MATLAB add-ons, so I don’t see any downside to relying on a cost-free add-on that users install when they install the toolkit. But I’m new to the MATLAB user community, so don’t count my opinion too much.
I don’t want ‘dependencies’ beyond the Matlab with Toolboxes, so I would just provide a copy of cprintf() as part of the toolkit, or would not use it at all. [This is what is done with CMA-ES optimization]
1 Like
As far as I understand, cprintf relies on some undocumented matlab features and is likely to break at some point. This requires maintaince. I’m not sure it is worth it.
That said, maybe introducing this only if verbose=2 might be a good compromise.