Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@
%% Parameter Structure
% Parameters are allowed to be given as structure, or as vector/matrix
% (in terms of their dependence on permanent type). So go through each of
% these in term.
% these in turn.
% ie. Parameters.alpha=[0;1]; or Parameters.alpha.ptype1=0; Parameters.alpha.ptype2=1;
PTypeStructure.(iistr).Parameters=Parameters;
FullParamNames=fieldnames(Parameters); % all the different parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@
%% Parameter Structure
% Parameters are allowed to be given as structure, or as vector/matrix
% (in terms of their dependence on permanent type). So go through each of
% these in term.
% these in turn.
% ie. Parameters.alpha=[0;1]; or Parameters.alpha.ptype1=0; Parameters.alpha.ptype2=1;
PTypeStructure.(iistr).Parameters=Parameters;
FullParamNames=fieldnames(Parameters); % all the different parameters
Expand Down Expand Up @@ -405,12 +405,26 @@
if isstruct(z_grid)
PTypeStructure.(iistr).z_grid=z_grid.(Names_i{ii});
else
PTypeStructure.(iistr).z_grid=z_grid;
% If the last dimension is of length N_i, this indicates dependence on ptype
nn=size(z_grid,ndims(z_grid));
if nn==N_i
otherdims = repmat({':'},1,ndims(z_grid)-1);
PTypeStructure.(iistr).z_grid=z_grid(otherdims{:},ii);
else
PTypeStructure.(iistr).z_grid=z_grid;
end
end
if isstruct(pi_z)
PTypeStructure.(iistr).pi_z=pi_z.(Names_i{ii});
else
PTypeStructure.(iistr).pi_z=pi_z;
% If the last dimension is of length N_i, this indicates dependence on ptype
nn=size(pi_z,ndims(pi_z));
if nn==N_i
otherdims = repmat({':'},1,ndims(pi_z)-1);
PTypeStructure.(iistr).pi_z=pi_z(otherdims{:},ii);
else
PTypeStructure.(iistr).pi_z=pi_z;
end
end

% Check if using ExogShockFn or EiidShockFn, and if so, do these use a
Expand All @@ -430,7 +444,7 @@
heteroagentoptions.gridsinGE(ii)=1;
end
end
% If z (and e) are not determined in GE, then compute z_gridvals_J and pi_z_J now (and e_gridvals_J and pi_e_J)
% If z (and e) are not determined in GE, then compute z_gridvals and pi_z now (and e_gridvals and pi_e)
if heteroagentoptions.gridsinGE(ii)==0
% Some of the shock grids depend on parameters that are determined in general eqm
[PTypeStructure.(iistr).z_grid, PTypeStructure.(iistr).pi_z, PTypeStructure.(iistr).vfoptions]=ExogShockSetup_InfHorz(PTypeStructure.(iistr).n_z,PTypeStructure.(iistr).z_grid,PTypeStructure.(iistr).pi_z,PTypeStructure.(iistr).Parameters,PTypeStructure.(iistr).vfoptions,3);
Expand Down
46 changes: 18 additions & 28 deletions HeterogeneousAgent/MixHorz/HeteroAgentStationaryEqm_MixHorz_PType.m
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@
PTypeStructure.(iistr).a_grid=a_grid;
end


%% Parameter Structure
% Parameters are allowed to be given as structure, or as vector/matrix
% (in terms of their dependence on permanent type). So go through each of
Expand All @@ -445,6 +446,7 @@
end
end


%% Set up exogenous shock grids now (so they can then just be reused every time)

if isstruct(z_grid)
Expand Down Expand Up @@ -472,32 +474,6 @@
end
end

%% Parameter Structure
% Parameters are allowed to be given as structure, or as vector/matrix
% (in terms of their dependence on permanent type). So go through each of
% these in term.
% ie. Parameters.alpha=[0;1]; or Parameters.alpha.ptype1=0; Parameters.alpha.ptype2=1;
% Need to establish this in PTypeStructure before we use it below.
PTypeStructure.(iistr).Parameters=Parameters;
FullParamNames=fieldnames(Parameters); % all the different parameters
nFields=length(FullParamNames);
for kField=1:nFields
if isa(Parameters.(FullParamNames{kField}), 'struct') % Check the current parameter for permanent type in structure form
% Check if this parameter is used for the current permanent type (it may or may not be, some parameters are only used be a subset of permanent types)
if isfield(Parameters.(FullParamNames{kField}),Names_i{ii})
PTypeStructure.(iistr).Parameters.(FullParamNames{kField})=Parameters.(FullParamNames{kField}).(Names_i{ii});
end
elseif sum(size(Parameters.(FullParamNames{kField}))==PTypeStructure.N_i)>=1 % Check for permanent type in vector/matrix form.
temp=Parameters.(FullParamNames{kField});
[~,ptypedim]=max(size(Parameters.(FullParamNames{kField}))==PTypeStructure.N_i); % Parameters as vector/matrix can be at most two dimensional, figure out which relates to PType, it should be the row dimension, if it is not then give a warning.
if ptypedim==1
PTypeStructure.(iistr).Parameters.(FullParamNames{kField})=temp(ii,:);
elseif ptypedim==2
PTypeStructure.(iistr).Parameters.(FullParamNames{kField})=temp(:,ii);
end
end
end

% Check if using ExogShockFn or EiidShockFn, and if so, do these use a parameter that is being determined in general eqm
heteroagentoptions.gridsinGE(ii)=0;
if isfield(PTypeStructure.(iistr).vfoptions,'ExogShockFn')
Expand Down Expand Up @@ -530,11 +506,25 @@
end
PTypeStructure.(iistr)=rmfield(PTypeStructure.(iistr),'z_grid'); % Should not be used, as now have z_gridvals_J
PTypeStructure.(iistr)=rmfield(PTypeStructure.(iistr),'pi_z'); % Should not be used, as now have pi_z_J
if isfield(PTypeStructure.(iistr).simoptions,'ExogShockFn') % Note: ExogShockSetup_FHorz() removed ExogShockFn from vfoptions but not from simoptions
if heteroagentoptions.useCustomModelStats==1
heteroagentoptions.CustomModelStatsInputs.z_grid=PTypeStructure.(iistr).z_gridvals_J;
heteroagentoptions.CustomModelStatsInputs.pi_z=PTypeStructure.(iistr).pi_z_J;
end
PTypeStructure.(iistr).simoptions=rmfield(simoptions,'ExogShockFn');
end
else % InfHorz
if heteroagentoptions.gridsinGE(ii)==0
[PTypeStructure.(iistr).z_gridvals, PTypeStructure.(iistr).pi_z, PTypeStructure.(iistr).vfoptions]=ExogShockSetup_InfHorz(PTypeStructure.(iistr).n_z,PTypeStructure.(iistr).z_grid,PTypeStructure.(iistr).pi_z,PTypeStructure.(iistr).Parameters,PTypeStructure.(iistr).vfoptions,3);
PTypeStructure.(iistr).simoptions.e_gridvals=PTypeStructure.(iistr).vfoptions.e_gridvals; % Note, will be [] if no e
PTypeStructure.(iistr).simoptions.pi_e=PTypeStructure.(iistr).vfoptions.pi_e; % Note, will be [] if no e
if isfield(PTypeStructure.(iistr).simoptions,'ExogShockFn') % Note: ExogShockSetup_InfHorz() removed ExogShockFn from vfoptions but not from simoptions
if heteroagentoptions.useCustomModelStats==1
heteroagentoptions.CustomModelStatsInputs.z_grid=PTypeStructure.(iistr).z_grid;
heteroagentoptions.CustomModelStatsInputs.pi_z=PTypeStructure.(iistr).pi_z;
end
PTypeStructure.(iistr).simoptions=rmfield(PTypeStructure.(iistr).simoptions,'ExogShockFn');
end
else
% % Create placeholders, as these will need to be created in general eqm since they depend on General eqm parameters
% PTypeStructure.(iistr).z_gridvals=[];
Expand Down Expand Up @@ -599,11 +589,11 @@
%% jequaloneDist and AgeWeightsParamNames
if isfinite(PTypeStructure.(iistr).N_j) % FHorz
if isstruct(jequaloneDist)
if isfield(jequaloneDist,PTypeStructure.Names_i{ii})
if isfield(jequaloneDist,iistr)
if isa(jequaloneDist, 'function_handle')
[PTypeStructure.(iistr).jequaloneDist,~,PTypeStructure.(iistr).Parameters]=jequaloneDist_PType(jequaloneDist.(iistr),PTypeStructure.(iistr).Parameters,PTypeStructure.(iistr).simoptions,PTypeStructure.(iistr).n_a,PTypeStructure.(iistr).n_z,PTypeStructure.(iistr).N_i,PTypeStructure.(iistr).PTypeDistParamNames,0);
else
PTypeStructure.(iistr).jequaloneDist=jequaloneDist.(PTypeStructure.Names_i{ii});
PTypeStructure.(iistr).jequaloneDist=jequaloneDist.(iistr);
end
else
error(['You must input jequaloneDist for permanent type ', PTypeStructure.Names_i{ii}, ' \n'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@
end
end

% Move d_grid and a_grid to GPU
if isfield(simoptions_temp,'d_grid') && iscolumn(simoptions_temp.d_grid)
simoptions_temp.d_grid=gpuArray(simoptions_temp.d_grid);
end
if isfield(simoptions_temp,'a_grid') && iscolumn(simoptions_temp.a_grid)
simoptions_temp.a_grid=gpuArray(simoptions_temp.a_grid);
end

if simoptions_temp.verboseparams==1
sprintf('Parameter values for the current permanent type')
Parameters_temp
Expand Down