Skip to content

Commit 0c58f16

Browse files
committed
clean
1 parent e4a8d86 commit 0c58f16

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

EvaluateFnOnAgentDist/EvalFnOnAgentDist_AllStats_Case1.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
StationaryDistVec=gpuArray(StationaryDistVec);
8080
PolicyIndexes=gpuArray(PolicyIndexes);
8181

82-
PolicyValues=PolicyInd2Val_Case1(PolicyIndexes,n_d,n_a,n_z,d_grid,a_grid);
82+
PolicyValues=PolicyInd2Val_Case1(PolicyIndexes,n_d,n_a,n_z,d_grid,a_grid,simoptions);
8383
% permuteindexes=[1+(1:1:(l_a+l_z)),1];
8484
% PolicyValuesPermute=permute(PolicyValues,permuteindexes); %[n_a,n_s,l_d+l_a]
8585
PolicyValuesPermute=permute(reshape(PolicyValues,[size(PolicyValues,1),N_a,N_z]),[2,3,1]); %[N_a,N_z,l_d+l_a]

HeterogeneousAgent/FHorz/HeteroAgentStationaryEqm_Case1_FHorz.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
heteroagentoptions.toleranceGEcondns=10^(-4); % Accuracy of general eqm eqns
7373
heteroagentoptions.fminalgo=1; % use fminsearch
7474
heteroagentoptions.verbose=0;
75-
heteroagentoptions.maxiter=1000;
75+
heteroagentoptions.maxiter=1000; % =0 just evaluate (rather than solves for) GE condns
7676
% heteroagentoptions.outputGEform=0; % For internal use only
7777
heteroagentoptions.outputGEstruct=1; % output GE conditions as a structure (=2 will output as a vector)
7878
heteroagentoptions.outputgather=1; % output GE conditions on CPU [some optimization routines only work on CPU, some can handle GPU]
@@ -381,6 +381,13 @@
381381
GeneralEqmConditionsFnOpt=@(p) HeteroAgentStationaryEqm_Case1_FHorz_subfn(p, jequaloneDist,AgeWeightParamNames, n_d, n_a, n_z, N_j, l_p, pi_z, d_grid, a_grid, z_grid, ReturnFn, FnsToEvaluate, GeneralEqmEqns, Parameters, DiscountFactorParamNames, ReturnFnParamNames, FnsToEvaluateParamNames, GeneralEqmEqnParamNames, GEPriceParamNames, heteroagentoptions, simoptions, vfoptions); % update based on new heteragentoptions
382382
GeneralEqmConditions=GeneralEqmConditionsFnOpt(p_eqm_vec);
383383
end
384+
if heteroagentoptions.outputGEstruct==1
385+
% put GeneralEqmConditions structure on cpu for purely cosmetic reasons
386+
GEeqnNames=fieldnames(GeneralEqmEqns);
387+
for gg=1:length(GEeqnNames)
388+
GeneralEqmConditions.(GEeqnNames{gg})=gather(GeneralEqmConditions.(GEeqnNames{gg}));
389+
end
390+
end
384391

385392

386393

HeterogeneousAgent/FHorz/PType/HeteroAgentStationaryEqm_Case1_FHorz_PType.m

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
heteroagentoptions.multiGEweights=ones(1,length(fieldnames(GeneralEqmEqns)));
8080
heteroagentoptions.toleranceGEprices=10^(-4); % Accuracy of general eqm prices
8181
heteroagentoptions.toleranceGEcondns=10^(-4); % Accuracy of general eqm eqns
82-
heteroagentoptions.maxiter=200*length(GEPriceParamNames); % this is roughly the matlab default (for fminsearch(), or would be if all GEPriceParamNames are scalar)
82+
heteroagentoptions.maxiter=200*length(GEPriceParamNames); % =0 just evaluate (rather than solves for) GE condns
8383
heteroagentoptions.verbose=0;
8484
heteroagentoptions.parallel=1+(gpuDeviceCount>0); % GPU where available, otherwise parallel CPU.
8585
heteroagentoptions.fminalgo=1; % use fminsearch
@@ -96,7 +96,7 @@
9696
heteroagentoptions.multiGEweights=ones(1,length(fieldnames(GeneralEqmEqns)));
9797
end
9898
if ~isfield(heteroagentoptions,'maxiter')
99-
heteroagentoptions.maxiter=200*length(GEPriceParamNames); % this is roughly the matlab default (for fminsearch(), or would be if all GEPriceParamNames are scalar)
99+
heteroagentoptions.maxiter=200*length(GEPriceParamNames); % =0 just evaluate (rather than solves for) GE condns
100100
end
101101
if N_p~=0
102102
if ~isfield(heteroagentoptions,'p_grid')
@@ -190,6 +190,8 @@
190190
end
191191
elseif length(heteroagentoptions.multiGEweights)~=length(fieldnames(GeneralEqmEqns))
192192
error('length(heteroagentoptions.multiGEweights)~=length(fieldnames(GeneralEqmEqns)) (the length of the GE weights is not equal to the number of general eqm equations')
193+
else
194+
heteroagentoptions.GEptype_vectoroutput=0;
193195
end
194196

195197

@@ -711,7 +713,7 @@
711713
elseif heteroagentoptions.GEptype_vectoroutput==0
712714
temp=p_eqm_vec(GEpriceindexes(pp,1):GEpriceindexes(pp,2));
713715
for ii=1:N_i
714-
p_eqm.(GEPriceParamNames{pp}).(Names_i{ii})=temp(ii);
716+
p_eqm.(GEPriceParamNames{pp}).(PTypeStructure.Names_i{ii})=temp(ii);
715717
end
716718
end
717719
end
@@ -749,6 +751,13 @@
749751
end
750752
GeneralEqmConditions=GeneralEqmConditionsFnOpt(p_eqm_vec);
751753
end
754+
if heteroagentoptions.outputGEstruct==1
755+
% put GeneralEqmConditions structure on cpu for purely cosmetic reasons
756+
GEeqnNames=fieldnames(GeneralEqmEqns);
757+
for gg=1:length(GEeqnNames)
758+
GeneralEqmConditions.(GEeqnNames{gg})=gather(GeneralEqmConditions.(GEeqnNames{gg}));
759+
end
760+
end
752761

753762

754763

ValueFnIter/FHorz/ExoticPrefs/EpsteinZin/ValueFnIter_Case1_FHorz_EpsteinZin_raw.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@
223223
temp=VKronNext_j;
224224
temp(isfinite(VKronNext_j))=(ezc4*VKronNext_j(isfinite(VKronNext_j))).^ezc5(jj);
225225
temp(VKronNext_j==0)=0;
226+
temp(~isfinite(VKronNext_j))=ezc4*VKronNext_j(~isfinite(VKronNext_j)); % ezc4 is 1 or -1, When it is -1 need to flip the sign of the -Inf, so that ezc3 below (which will also be -1) flips it back
226227

227228
if vfoptions.lowmemory==0
228229

@@ -242,6 +243,7 @@
242243

243244
entireEV=repelem(EV,N_d,1,1);
244245
temp4=entireEV;
246+
245247
if warmglow==1
246248
becareful=logical(isfinite(temp4).*isfinite(WGmatrix)); % both are finite
247249
temp4(becareful)=(sj(jj)*temp4(becareful).^ezc8(jj)+(1-sj(jj))*WGmatrix(becareful).^ezc8(jj)).^ezc6(jj);

ValueFnIter/FHorz/ExoticPrefs/GulPesendorfer/ValueFnIter_Case1_FHorz_GulPesendorfer_raw.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@
219219
EV(isnan(EV))=0; %multilications of -Inf with 0 gives NaN, this replaces them with zeros (as the zeros come from the transition probabilites)
220220
EV=sum(EV,2); % sum over z', leaving a singular second dimension
221221

222-
entireEV=kron(EV,ones(N_d,1));
223-
% entireEV=repelem(EV,N_d,1,1); % I tried this instead but appears repelem() is slower than kron()
222+
entireEV=repelem(EV,N_d,1,1);
224223

225224
entireRHS=ReturnMatrix+TemptationMatrix-ones(N_d*N_a,1).*MostTempting+DiscountFactorParamsVec*entireEV; %*repmat(entireEV,1,N_a,1);
226225

0 commit comments

Comments
 (0)