diff --git a/HeterogeneousAgent/FHorz/PType/HeteroAgentStationaryEqm_Case1_FHorz_PType.m b/HeterogeneousAgent/FHorz/PType/HeteroAgentStationaryEqm_Case1_FHorz_PType.m index 76707ce8..02e34481 100644 --- a/HeterogeneousAgent/FHorz/PType/HeteroAgentStationaryEqm_Case1_FHorz_PType.m +++ b/HeterogeneousAgent/FHorz/PType/HeteroAgentStationaryEqm_Case1_FHorz_PType.m @@ -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 diff --git a/HeterogeneousAgent/InfHorz/PType/HeteroAgentStationaryEqm_InfHorz_PType.m b/HeterogeneousAgent/InfHorz/PType/HeteroAgentStationaryEqm_InfHorz_PType.m index 47fc36e5..ebcfdd96 100644 --- a/HeterogeneousAgent/InfHorz/PType/HeteroAgentStationaryEqm_InfHorz_PType.m +++ b/HeterogeneousAgent/InfHorz/PType/HeteroAgentStationaryEqm_InfHorz_PType.m @@ -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 @@ -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 @@ -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); diff --git a/HeterogeneousAgent/MixHorz/HeteroAgentStationaryEqm_MixHorz_PType.m b/HeterogeneousAgent/MixHorz/HeteroAgentStationaryEqm_MixHorz_PType.m index d21ec281..1e3eada7 100644 --- a/HeterogeneousAgent/MixHorz/HeteroAgentStationaryEqm_MixHorz_PType.m +++ b/HeterogeneousAgent/MixHorz/HeteroAgentStationaryEqm_MixHorz_PType.m @@ -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 @@ -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) @@ -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') @@ -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=[]; @@ -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']) diff --git a/StationaryDist/TransPathMixHorz/AgentDistOnTransPath_MixHorz_PType.m b/StationaryDist/TransPathMixHorz/AgentDistOnTransPath_MixHorz_PType.m index a98caba2..70320f22 100644 --- a/StationaryDist/TransPathMixHorz/AgentDistOnTransPath_MixHorz_PType.m +++ b/StationaryDist/TransPathMixHorz/AgentDistOnTransPath_MixHorz_PType.m @@ -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