Thanks for the prompt response Prof JPfeifer,
When I modify the example provided earlier, I have the following:
% find position of variables in variable_weights
pie_pos=strmatch(‘pie’,M_.endo_names,‘exact’);
l_pos=strmatch(‘l’,M_.endo_names,‘exact’);
y_pos=strmatch(‘y’,M_.endo_names,‘exact’);
% find position of variables in M_.endo_names
pie_pos_M_.endo_names=strmatch(‘pie’,M_.endo_names,‘exact’);
l_pos_M_.endo_names=strmatch(‘l’,M_.endo_names,‘exact’);
y_pos_M_.endo_names=strmatch(‘y’,M_.endo_names,‘exact’);
weight_grid_pie = 1:1:1; %weight on pie is fixed at 1. Not sure whether I have done it correctly !! Please help !
weight_grid_l = 0:0.05:0.5;
weight_grid_y = 0:0.1:1;
n_grid_points = length(weight_grid_pie)*length(weight_grid_l)*length(weight_grid_y);
var_pie = NaN(n_grid_points,1);
var_l = NaN(n_grid_points,1);
var_y = NaN(n_grid_points,1);
for grid_iter = 1:n_grid_points
M_.osr.variable_weights(pie_pos,pie_pos) = weight_grid_pie(grid_iter);
M_.osr.variable_weights(l_pos,l_pos) = weight_grid_l(grid_iter);
M_.osr.variable_weights(y_pos,y_pos) = weight_grid_y(grid_iter);
oo_.osr = osr(M_.endo_names,M_.osr.param_names,M_.osr.variable_indices,M_.osr.variable_weights);
if oo_.osr.error_indicator==0
var_pie(grid_iter) = oo_.var(pie_pos_M_.endo_names,pie_pos_M_.endo_names);
var_l(grid_iter) = oo_.var(l_pos_M_.endo_names,l_pos_M_.endo_names);
var_y(grid_iter) = oo_.var(y_pos_M_.endo_names,y_pos_M_.endo_names);
end
end
Will this make sense ?
In the above code, I am not really sure about the size of the vectors var_pie, var_l and var_y. I think,
n_grid_points = length(weight_grid_pie)*length(weight_grid_l)*length(weight_grid_y)
which represents the combinations of weights in the Loss function. Am I correct ?
The loss function is as follows:
L = var(pie) + lambda_yvar(y) + lambda_lvar(l)
I only allow the weights, lambda_y and lambda_l to vary and fixed the weight on pie at 1. How do I incorporate the fact that lambda_pie = 1 in the above code ?
Regards,
Ernest