Generate States, Choices and Shocks Grids and Get Functions
back to Fan's Dynamic Assets Repository Table of Content.
Contents
function [armt_map, func_map] = ffs_az_get_funcgrid(varargin)
FFS_AZ_GET_FUNCGRID get funcs, params, states choices shocks grids
centralized gateway for retrieving parameters, and solution grids and functions
@param param_map container parameter container
@param support_map container support container
@param bl_input_override boolean if true varargin contained param_map and support_map fully overrides local default. Local default is not invoked. This could be important for speed if this function is getting invoked within certain loops. Default is 0.
@return armt_map container container with states, choices and shocks grids that are inputs for grid based solution algorithm
@return func_map container container with function handles for consumption cash-on-hand etc.
@example
it_param_set = 2; bl_input_override = true; [param_map, support_map] = ffs_az_set_default_param(it_param_set); [armt_map, func_map] = ffs_az_get_funcgrid(param_map, support_map, bl_input_override);
@include
Default
if (~isempty(varargin)) % override when called from outside [param_map, support_map, ~] = varargin{:}; else % default internal run [param_map, support_map] = ffs_az_set_default_param(); support_map('bl_graph_funcgrids') = true; support_map('bl_display_funcgrids') = true; default_maps = {param_map, support_map}; % numvarargs is the number of varagin inputted [default_maps{1:length(varargin)}] = varargin{:}; param_map = [param_map; default_maps{1}]; support_map = [support_map; default_maps{2}]; end
----------------------------------------
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Begin: Show all key and value pairs from container
CONTAINER NAME: PARAM_MAP
----------------------------------------
Map with properties:
Count: 24
KeyType: char
ValueType: any
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
----------------------------------------
----------------------------------------
pos = 1 ; key = bl_loglin ; val = false
pos = 2 ; key = fl_a_max ; val = 50
pos = 3 ; key = fl_a_min ; val = 0
pos = 4 ; key = fl_b_bd ; val = 0
pos = 5 ; key = fl_beta ; val = 0.94
pos = 6 ; key = fl_crra ; val = 1.5
pos = 7 ; key = fl_loglin_threshold ; val = 1
pos = 8 ; key = fl_nan_replace ; val = -9999
pos = 9 ; key = fl_r_save ; val = 0.025
pos = 10 ; key = fl_tol_dist ; val = 1e-05
pos = 11 ; key = fl_tol_pol ; val = 1e-05
pos = 12 ; key = fl_tol_val ; val = 1e-05
pos = 13 ; key = fl_w ; val = 1.28
pos = 14 ; key = fl_z_mu ; val = 0
pos = 15 ; key = fl_z_rho ; val = 0.8
pos = 16 ; key = fl_z_sig ; val = 0.2
pos = 17 ; key = it_a_n ; val = 750
pos = 18 ; key = it_maxiter_dist ; val = 1000
pos = 19 ; key = it_maxiter_val ; val = 1000
pos = 20 ; key = it_tol_pol_nochange ; val = 25
pos = 21 ; key = it_trans_power_dist ; val = 1000
pos = 22 ; key = it_z_n ; val = 15
pos = 23 ; key = st_analytical_stationary_type ; val = eigenvector
pos = 24 ; key = st_model ; val = az
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Scalars in Container and Sizes and Basic Statistics
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
i idx value
__ ___ _____
bl_loglin 1 1 0
fl_a_max 2 2 50
fl_a_min 3 3 0
fl_b_bd 4 4 0
fl_beta 5 5 0.94
fl_crra 6 6 1.5
fl_loglin_threshold 7 7 1
fl_nan_replace 8 8 -9999
fl_r_save 9 9 0.025
fl_tol_dist 10 10 1e-05
fl_tol_pol 11 11 1e-05
fl_tol_val 12 12 1e-05
fl_w 13 13 1.28
fl_z_mu 14 14 0
fl_z_rho 15 15 0.8
fl_z_sig 16 16 0.2
it_a_n 17 17 750
it_maxiter_dist 18 18 1000
it_maxiter_val 19 19 1000
it_tol_pol_nochange 20 20 25
it_trans_power_dist 21 21 1000
it_z_n 22 22 15
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Strings in Container and Sizes and Basic Statistics
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
i idx
_ ___
st_analytical_stationary_type 1 23
st_model 2 24
----------------------------------------
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Begin: Show all key and value pairs from container
CONTAINER NAME: SUPPORT_MAP
----------------------------------------
Map with properties:
Count: 39
KeyType: char
ValueType: any
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
----------------------------------------
----------------------------------------
pos = 1 ; key = bl_display ; val = true
pos = 2 ; key = bl_display_defparam ; val = false
pos = 3 ; key = bl_display_dist ; val = false
pos = 4 ; key = bl_display_final ; val = false
pos = 5 ; key = bl_display_final_dist ; val = false
pos = 6 ; key = bl_display_final_dist_detail ; val = false
pos = 7 ; key = bl_display_funcgrids ; val = false
pos = 8 ; key = bl_graph ; val = false
pos = 9 ; key = bl_graph_coh_t_coh ; val = true
pos = 10 ; key = bl_graph_funcgrids ; val = false
pos = 11 ; key = bl_graph_onebyones ; val = true
pos = 12 ; key = bl_graph_pol_lvl ; val = true
pos = 13 ; key = bl_graph_pol_pct ; val = true
pos = 14 ; key = bl_graph_val ; val = true
pos = 15 ; key = bl_img_save ; val = false
pos = 16 ; key = bl_mat ; val = false
pos = 17 ; key = bl_post ; val = false
pos = 18 ; key = bl_profile ; val = false
pos = 19 ; key = bl_profile_dist ; val = false
pos = 20 ; key = bl_time ; val = true
pos = 21 ; key = it_display_every ; val = 5
pos = 22 ; key = it_display_final_colmax ; val = 12
pos = 23 ; key = it_display_final_rowmax ; val = 100
pos = 24 ; key = it_display_summmat_colmax ; val = 5
pos = 25 ; key = it_display_summmat_rowmax ; val = 5
pos = 26 ; key = st_img_name_main ; val = _default
pos = 27 ; key = st_img_path ; val = C:/Users/fan/CodeDynaAsset//m_az//solve/img/
pos = 28 ; key = st_img_prefix ; val =
pos = 29 ; key = st_img_suffix ; val = _p0.png
pos = 30 ; key = st_mat_name_main ; val = _default
pos = 31 ; key = st_mat_path ; val = C:/Users/fan/CodeDynaAsset//m_az//solve/mat/
pos = 32 ; key = st_mat_prefix ; val =
pos = 33 ; key = st_mat_suffix ; val = _p0
pos = 34 ; key = st_matimg_path_root ; val = C:/Users/fan/CodeDynaAsset//m_az/
pos = 35 ; key = st_profile_name_main ; val = _default
pos = 36 ; key = st_profile_path ; val = C:/Users/fan/CodeDynaAsset//m_az//solve/profile/
pos = 37 ; key = st_profile_prefix ; val =
pos = 38 ; key = st_profile_suffix ; val = _p0
pos = 39 ; key = st_title_prefix ; val =
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Scalars in Container and Sizes and Basic Statistics
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
i idx value
__ ___ _____
bl_display 1 1 1
bl_display_defparam 2 2 0
bl_display_dist 3 3 0
bl_display_final 4 4 0
bl_display_final_dist 5 5 0
bl_display_final_dist_detail 6 6 0
bl_display_funcgrids 7 7 0
bl_graph 8 8 0
bl_graph_coh_t_coh 9 9 1
bl_graph_funcgrids 10 10 0
bl_graph_onebyones 11 11 1
bl_graph_pol_lvl 12 12 1
bl_graph_pol_pct 13 13 1
bl_graph_val 14 14 1
bl_img_save 15 15 0
bl_mat 16 16 0
bl_post 17 17 0
bl_profile 18 18 0
bl_profile_dist 19 19 0
bl_time 20 20 1
it_display_every 21 21 5
it_display_final_colmax 22 22 12
it_display_final_rowmax 23 23 100
it_display_summmat_colmax 24 24 5
it_display_summmat_rowmax 25 25 5
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Strings in Container and Sizes and Basic Statistics
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
i idx
__ ___
st_img_name_main 1 26
st_img_path 2 27
st_img_prefix 3 28
st_img_suffix 4 29
st_mat_name_main 5 30
st_mat_path 6 31
st_mat_prefix 7 32
st_mat_suffix 8 33
st_matimg_path_root 9 34
st_profile_name_main 10 35
st_profile_path 11 36
st_profile_prefix 12 37
st_profile_suffix 13 38
st_title_prefix 14 39
Parse Parameters
params_group = values(param_map, {'it_z_n', 'fl_z_mu', 'fl_z_rho', 'fl_z_sig'});
[it_z_n, fl_z_mu, fl_z_rho, fl_z_sig] = params_group{:};
params_group = values(param_map, {'fl_b_bd', 'fl_a_min', 'fl_a_max', 'bl_loglin', 'fl_loglin_threshold', 'it_a_n'});
[fl_b_bd, fl_a_min, fl_a_max, bl_loglin, fl_loglin_threshold, it_a_n] = params_group{:};
params_group = values(param_map, {'fl_crra'});
[fl_crra] = params_group{:};
params_group = values(param_map, {'fl_r_save', 'fl_w'});
[fl_r_save, fl_w] = params_group{:};
params_group = values(support_map, {'bl_graph_funcgrids', 'bl_display_funcgrids'});
[bl_graph_funcgrids, bl_display_funcgrids] = params_group{:};
params_group = values(support_map, {'it_display_summmat_rowmax', 'it_display_summmat_colmax'});
[it_display_summmat_rowmax, it_display_summmat_colmax] = params_group{:};
Get Asset and Choice Grid
if (bl_loglin) % C:\Users\fan\M4Econ\asset\grid\ff_grid_loglin.m ar_a = fft_gen_grid_loglin(it_a_n, fl_a_max, fl_a_min, fl_loglin_threshold); else ar_a = linspace(fl_b_bd, fl_a_max, it_a_n); ar_a = [0 ar_a]; ar_a = sort(unique(ar_a)); end
Get Shock Grids
[~, mt_z_trans, ar_stationary, ar_z] = ffto_gen_tauchen_jhl(fl_z_mu,fl_z_rho,fl_z_sig,it_z_n);
Get Equations
[f_util_log, f_util_crra, f_util_standin, f_inc, f_coh, f_cons] = ffs_az_set_functions(fl_crra, fl_r_save, fl_w);
Store
armt_map = containers.Map('KeyType','char', 'ValueType','any'); armt_map('ar_a') = ar_a; armt_map('mt_z_trans') = mt_z_trans; armt_map('ar_stationary') = ar_stationary; armt_map('ar_z') = ar_z; func_map = containers.Map('KeyType','char', 'ValueType','any'); func_map('f_util_log') = f_util_log; func_map('f_util_crra') = f_util_crra; func_map('f_util_standin') = f_util_standin; func_map('f_inc') = f_inc; func_map('f_coh') = f_coh; func_map('f_cons') = f_cons;
Display
if (bl_display_funcgrids) disp('ar_z'); disp(size(ar_z)); disp(ar_z); disp('mt_z_trans'); disp(size(mt_z_trans)); disp(mt_z_trans); fft_container_map_display(armt_map, it_display_summmat_rowmax, it_display_summmat_colmax); fft_container_map_display(func_map, it_display_summmat_rowmax, it_display_summmat_colmax); end
ar_z
1 15
Columns 1 through 7
0.3474 0.4008 0.4623 0.5333 0.6152 0.7097 0.8186
Columns 8 through 14
0.9444 1.0894 1.2567 1.4496 1.6723 1.9291 2.2253
Column 15
2.5670
mt_z_trans
15 15
Columns 1 through 7
0.2602 0.2683 0.2555 0.1492 0.0534 0.0117 0.0016
0.1123 0.1962 0.2763 0.2386 0.1263 0.0410 0.0081
0.0371 0.1049 0.2185 0.2790 0.2185 0.1049 0.0309
0.0092 0.0410 0.1263 0.2386 0.2763 0.1962 0.0854
0.0017 0.0117 0.0534 0.1492 0.2555 0.2683 0.1728
0.0002 0.0024 0.0165 0.0682 0.1728 0.2683 0.2555
0.0000 0.0004 0.0037 0.0228 0.0854 0.1962 0.2763
0.0000 0.0000 0.0006 0.0056 0.0309 0.1049 0.2185
0.0000 0.0000 0.0001 0.0010 0.0081 0.0410 0.1263
0.0000 0.0000 0.0000 0.0001 0.0016 0.0117 0.0534
0.0000 0.0000 0.0000 0.0000 0.0002 0.0024 0.0165
0.0000 0.0000 0.0000 0.0000 0.0000 0.0004 0.0037
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0006
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
Columns 8 through 14
0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0010 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000
0.0056 0.0006 0.0000 0.0000 0.0000 0.0000 0.0000
0.0228 0.0037 0.0004 0.0000 0.0000 0.0000 0.0000
0.0682 0.0165 0.0024 0.0002 0.0000 0.0000 0.0000
0.1492 0.0534 0.0117 0.0016 0.0001 0.0000 0.0000
0.2386 0.1263 0.0410 0.0081 0.0010 0.0001 0.0000
0.2790 0.2185 0.1049 0.0309 0.0056 0.0006 0.0000
0.2386 0.2763 0.1962 0.0854 0.0228 0.0037 0.0004
0.1492 0.2555 0.2683 0.1728 0.0682 0.0165 0.0024
0.0682 0.1728 0.2683 0.2555 0.1492 0.0534 0.0117
0.0228 0.0854 0.1962 0.2763 0.2386 0.1263 0.0410
0.0056 0.0309 0.1049 0.2185 0.2790 0.2185 0.1049
0.0010 0.0081 0.0410 0.1263 0.2386 0.2763 0.1962
0.0001 0.0016 0.0117 0.0534 0.1492 0.2555 0.2683
Column 15
0
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0002
0.0017
0.0092
0.0371
0.1123
0.2602
----------------------------------------
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Begin: Show all key and value pairs from container
CONTAINER NAME: ARMT_MAP
----------------------------------------
Map with properties:
Count: 4
KeyType: char
ValueType: any
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
----------------------------------------
----------------------------------------
pos = 1 ; key = ar_a ;rown= 1 ,coln= 750
ar_a :mu= 25 ,sd= 14.4627 ,min= 0 ,max= 50
zi_1_C1 zi_2_C2 zi_375_c375 zi_749_c749 zi_750_c750
_______ ________ ___________ ___________ ___________
zi_1_r1 0 0.066756 24.967 49.933 50
pos = 2 ; key = ar_stationary ;rown= 1 ,coln= 15
ar_stationary :mu= 0.066667 ,sd= 0.060897 ,min= 0.0027089 ,max= 0.16757
zi_1_C1 zi_2_C2 zi_8_C8 zi_14_c14 zi_15_c15
_________ _________ _______ _________ _________
zi_1_r1 0.0027089 0.0069499 0.16757 0.0069499 0.0027089
pos = 3 ; key = ar_z ;rown= 1 ,coln= 15
ar_z :mu= 1.1347 ,sd= 0.69878 ,min= 0.34741 ,max= 2.567
zi_1_C1 zi_2_C2 zi_8_C8 zi_14_c14 zi_15_c15
_______ _______ _______ _________ _________
zi_1_r1 0.34741 0.40076 0.94436 2.2253 2.567
pos = 4 ; key = mt_z_trans ;rown= 15 ,coln= 15
mt_z_trans :mu= 0.066667 ,sd= 0.095337 ,min= 0 ,max= 0.27902
zi_1_C1 zi_2_C2 zi_8_C8 zi_14_c14 zi_15_c15
__________ __________ __________ __________ __________
zi_1_R1 0.26016 0.26831 0.00012823 1.1102e-15 0
zi_2_R2 0.11232 0.19622 0.00098855 9.3592e-14 3.3307e-16
zi_8_R8 1.7181e-06 4.1008e-05 0.27902 4.1008e-05 1.7181e-06
zi_14_r14 3.474e-16 9.3597e-14 0.00098855 0.19622 0.11232
zi_15_r15 2.7412e-18 1.1057e-15 0.00012823 0.26831 0.26016
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Matrix in Container and Sizes and Basic Statistics
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
i idx rowN colN mean std min max
_ ___ ____ ____ ________ ________ _________ _______
ar_a 1 1 1 750 25 14.463 0 50
ar_stationary 2 2 1 15 0.066667 0.060897 0.0027089 0.16757
ar_z 3 3 1 15 1.1347 0.69878 0.34741 2.567
mt_z_trans 4 4 15 15 0.066667 0.095337 0 0.27902
----------------------------------------
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Begin: Show all key and value pairs from container
CONTAINER NAME: FUNC_MAP
----------------------------------------
Map with properties:
Count: 6
KeyType: char
ValueType: any
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
----------------------------------------
----------------------------------------
pos = 1 ; key = f_coh ; val = @(z,b)(z*fl_w+b.*(1+fl_r_save))
pos = 2 ; key = f_cons ; val = @(z,b,bprime)(f_coh(z,b)-bprime)
pos = 3 ; key = f_inc ; val = @(z,b)(z*fl_w+b.*(fl_r_save))
pos = 4 ; key = f_util_crra ; val = @(c)(((c).^(1-fl_crra)-1)./(1-fl_crra))
pos = 5 ; key = f_util_log ; val = @(c)log(c)
pos = 6 ; key = f_util_standin ; val = @(z,b)f_util_log(f_coh(z,b))
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Scalars in Container and Sizes and Basic Statistics
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
i idx xFunction
_ ___ _________
f_coh 1 1 1
f_cons 2 2 2
f_inc 3 3 3
f_util_crra 4 4 4
f_util_log 5 5 5
f_util_standin 6 6 6
end
ans =
Map with properties:
Count: 4
KeyType: char
ValueType: any