Obviously, caliboptions does not exist.
I replaced caliboptions with heteroagentoptions and the routine works. It calls fminsearch and all is fine, until we reach the following block:
if heteroagentoptions.constrainAtoB(pp)==1
% Constrain parameter to be A to B
p_eqm_vec(pp)=heteroagentoptions.constrainAtoBlimits(pp,1)+(heteroagentoptions.constrainAtoBlimits(pp,2)-heteroagentoptions.constrainAtoBlimits(pp,1))*GEprices(pp);
% Note, this parameter will have first been converted to 0 to 1 already, so just need to further make it A to B
% y=A+(B-A)*x, converts 0-to-1 x, into A-to-B y
end
The error is now:
Unrecognized function or variable 'GEprices'.
Error in HeteroAgentStationaryEqm_Case1 (line 591)
p_eqm_vec(pp)=heteroagentoptions.constrainAtoBlimits(pp,1)+(heteroagentoptions.constrainAtoBlimits(pp,2)-heteroagentoptions.constrainAtoBlimits(pp,1))*GEprices(pp);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Bound between 0 and 1: heteroagentoptions.constrain0to1={'r'};
Constrain to be positive: heteroagentoptions.constrainpositive={'r'};
There is nowhere with a full list of options (although if you open any command, there are often a bunch of lines near the beginning that are setting the default options so you can see what most options are there).
Between the Workshop and the Intro to Life-Cycle Models, how to use most options are covered somewhere.
Should be fixed now. Update toolkit to latest github.
I have switched the ‘transform’ and ‘untransform’ used to change the constrained parameters to unconstrained parameters into two subfunctions:
I have switched the Stationary General Eqm commands over to use these subfunctions. Will do the same for the calibration/estimation commands early next week. Makes it all a bit cleaner and neater internally.
PS. End-user does not need these functions for anything, nor to understand them. I mention them here for those interested in what is happening internally.
I think there is a typo in your post. The second line should read as
heteroagentoptions.constrainAtoBlimits.r = [0,3];
@jake88 I tried setting heteroagentoptions.constrainAtoBlimits.r = [0,Inf]; as you asked but the code goes crazy. If you want to restrict r to be positive, you should use heteroagentoptions.constrainpositive={'r'};
@robertdkirkby: I think constrainAtoBlimits requires the bounds to be finite numbers, right? I ask this since Matlab built-in minimization routines such as fmincon do accept Inf or -Inf as bounds. (I’m not suggesting to implement this feature).
Yes, constrainAtoBlimits must both be finite numbers. [Internally, it will switch x to y=(x-A)/(B-A) and then treat y like it does for numbers that are bound from zero to one.]
At some point I want to go through each of the optimization routines one by one and set it so that those with such bounds already implemented are done using their specific setups, while those without their own way to handle bounds use the current transform/untransform approach. But for the moment I have just taken the easy/lazy approach of using the same transform/untransform for all of them.
Also you can always cobble together an [A,Inf] using the current options. Just replace where ‘r’ appears in model with ‘rmod+A’, and then constrain ‘rmod’ to be [0,Inf]. Once the model is solved in terms of ‘rmod’ you can get ‘r’ back from ‘r=rmod+A’. Bit of a pain, but nothing too difficult.