Skip to content

Commit ef80e1c

Browse files
committed
fminalgo=5 minor improve
1 parent aee25bb commit ef80e1c

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

HeterogeneousAgent/FHorz/HeteroAgentStationaryEqm_Case1_FHorz.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,16 +326,16 @@
326326
[p_eqm_vec,GeneralEqmConditions,counteval,stopflag,out,bestever] = cmaes_vfitoolkit(GeneralEqmConditionsFnOpt,p0,heteroagentoptions.insigma,heteroagentoptions.inopts); % ,varargin);
327327
elseif heteroagentoptions.fminalgo==5
328328
% Update based on rules in heteroagentoptions.fminalgo5.howtoupdate
329-
GeneralEqmEqnsNames=fieldnames(GeneralEqmEqns);
330-
GeneralEqmConditions=Inf;
331329
% Get initial prices, p
332330
p=nan(1,length(GEPriceParamNames));
333331
for ii=1:length(GEPriceParamNames)
334332
p(ii)=Parameters.(GEPriceParamNames{ii});
335333
end
336334
% Given current prices solve the model to get the general equilibrium conditions as a structure
335+
itercounter=0;
337336
p_change=Inf;
338-
while any(p_change>heteroagentoptions.heteroagentoptions.toleranceGEprices) || GeneralEqmConditions>heteroagentoptions.toleranceGEcondns
337+
GeneralEqmConditions=Inf;
338+
while (any(p_change>heteroagentoptions.toleranceGEprices) || GeneralEqmConditions>heteroagentoptions.toleranceGEcondns) && itercounter<heteroagentoptions.maxiter
339339

340340
p_i=GeneralEqmConditionsFnOpt(p); % using heteroagentoptions.outputGEform=1, so this is a vector (note the transpose)
341341

@@ -365,6 +365,7 @@
365365
% p_percentchange(p==0)=abs(p_new(p==0)); %-p(p==0)); but this is just zero anyway
366366
% Update p for next iteration
367367
p=p_new;
368+
itercounter=itercounter+1; % increment iteration counter
368369
end
369370
p_eqm_vec=p_new; % Need to put it in p_eqm_vec so that it can be used to create the final output
370371
elseif heteroagentoptions.fminalgo==6

HeterogeneousAgent/FHorz/PType/HeteroAgentStationaryEqm_Case1_FHorz_PType.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,17 +634,16 @@
634634
[p_eqm_vec,GeneralEqmConditions,counteval,stopflag,out,bestever] = cmaes_vfitoolkit(GeneralEqmConditionsFnOpt,p0,heteroagentoptions.insigma,heteroagentoptions.inopts); % ,varargin);
635635
elseif heteroagentoptions.fminalgo==5
636636
% Update based on rules in heteroagentoptions.fminalgo5.howtoupdate
637-
GeneralEqmEqnsNames=fieldnames(GeneralEqmEqns);
638-
GeneralEqmConditions=Inf;
639637
% Get initial prices, p
640638
p=nan(1,length(GEPriceParamNames));
641639
for ii=1:length(GEPriceParamNames)
642640
p(ii)=Parameters.(GEPriceParamNames{ii});
643641
end
644642
% Given current prices solve the model to get the general equilibrium conditions as a structure
645-
itercount=0;
643+
itercounter=0;
646644
p_change=Inf;
647-
while any(p_change>heteroagentoptions.heteroagentoptions.toleranceGEprices) || GeneralEqmConditions>heteroagentoptions.toleranceGEcondns
645+
GeneralEqmConditions=Inf;
646+
while (any(p_change>heteroagentoptions.toleranceGEprices) || GeneralEqmConditions>heteroagentoptions.toleranceGEcondns) && itercounter<heteroagentoptions.maxiter
648647

649648
p_i=GeneralEqmConditionsFnOpt(p); % using heteroagentoptions.outputGEform=1, so this is a vector
650649

@@ -673,6 +672,7 @@
673672
% p_percentchange(p==0)=abs(p_new(p==0)); %-p(p==0)); but this is just zero anyway
674673
% Update p for next iteration
675674
p=p_new;
675+
itercounter=itercounter+1; % increment iteration counter
676676
end
677677
p_eqm_vec=p_new; % Need to put it in p_eqm_vec so that it can be used to create the final output
678678
elseif heteroagentoptions.fminalgo==6

HeterogeneousAgent/HeteroAgentStationaryEqm_Case1.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,16 @@
299299
[p_eqm_vec,GeneralEqmConditions,counteval,stopflag,out,bestever] = cmaes_vfitoolkit(GeneralEqmConditionsFnOpt,p0,heteroagentoptions.insigma,heteroagentoptions.inopts); % ,varargin);
300300
elseif heteroagentoptions.fminalgo==5
301301
% Update based on rules in heteroagentoptions.fminalgo5.howtoupdate
302-
GeneralEqmConditions=Inf;
303302
% Get initial prices, p
304303
p=nan(1,length(GEPriceParamNames));
305304
for ii=1:length(GEPriceParamNames)
306305
p(ii)=Parameters.(GEPriceParamNames{ii});
307306
end
308307
% Given current prices solve the model to get the general equilibrium conditions as a structure
308+
itercounter=0;
309309
p_change=Inf;
310-
while any(p_change>heteroagentoptions.heteroagentoptions.toleranceGEprices) || GeneralEqmConditions>heteroagentoptions.toleranceGEcondns
310+
GeneralEqmConditions=Inf;
311+
while (any(p_change>heteroagentoptions.toleranceGEprices) || GeneralEqmConditions>heteroagentoptions.toleranceGEcondns) && itercounter<heteroagentoptions.maxiter
311312

312313
p_i=GeneralEqmConditionsFnOpt(p); % using heteroagentoptions.outputGEform=1, so this is a vector (note the transpose)
313314

@@ -337,6 +338,7 @@
337338
% p_percentchange(p==0)=abs(p_new(p==0)); %-p(p==0)); but this is just zero anyway
338339
% Update p for next iteration
339340
p=p_new;
341+
itercounter=itercounter+1; % increment iteration counter
340342
end
341343
p_eqm_vec=p_new; % Need to put it in p_eqm_vec so that it can be used to create the final output
342344
elseif heteroagentoptions.fminalgo==7 % Matlab fsolve()

HeterogeneousAgent/PType/HeteroAgentStationaryEqm_Case1_PType.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,16 +568,16 @@
568568
[p_eqm_vec,GeneralEqmConditions,counteval,stopflag,out,bestever] = cmaes_vfitoolkit(GeneralEqmConditionsFnOpt,p0,heteroagentoptions.insigma,heteroagentoptions.inopts); % ,varargin);
569569
elseif heteroagentoptions.fminalgo==5
570570
% Update based on rules in heteroagentoptions.fminalgo5.howtoupdate
571-
GeneralEqmEqnsNames=fieldnames(GeneralEqmEqns);
572-
GeneralEqmConditions=Inf;
573571
% Get initial prices, p
574572
p=nan(1,length(GEPriceParamNames));
575573
for ii=1:length(GEPriceParamNames)
576574
p(ii)=Parameters.(GEPriceParamNames{ii});
577575
end
578576
% Given current prices solve the model to get the general equilibrium conditions as a structure
577+
itercounter=0;
579578
p_change=Inf;
580-
while any(p_change>heteroagentoptions.heteroagentoptions.toleranceGEprices) || GeneralEqmConditions>heteroagentoptions.toleranceGEcondns
579+
GeneralEqmConditions=Inf;
580+
while (any(p_change>heteroagentoptions.toleranceGEprices) || GeneralEqmConditions>heteroagentoptions.toleranceGEcondns) && itercounter<heteroagentoptions.maxiter
581581

582582
p_i=GeneralEqmConditionsFnOpt(p); % using heteroagentoptions.outputGEform=1, so this is a vector
583583

@@ -606,6 +606,7 @@
606606
% p_percentchange(p==0)=abs(p_new(p==0)); %-p(p==0)); but this is just zero anyway
607607
% Update p for next iteration
608608
p=p_new;
609+
itercounter=itercounter+1; % increment iteration counter
609610
end
610611
p_eqm_vec=p_new; % Need to put it in p_eqm_vec so that it can be used to create the final output
611612
elseif heteroagentoptions.fminalgo==6

0 commit comments

Comments
 (0)