From 809a832cf8ba2d75606c70a7b3f4e7bf4b5aaa17 Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Wed, 31 Jul 2019 14:24:26 -0400 Subject: [PATCH] stoch_simul: add initval options --- src/+gui_tools/menu_options.m | 2 +- src/gui_stoch_simulation.m | 140 +++++++++++++++++++++++++--------- 2 files changed, 105 insertions(+), 37 deletions(-) diff --git a/src/+gui_tools/menu_options.m b/src/+gui_tools/menu_options.m index f0d9341..10fdc60 100644 --- a/src/+gui_tools/menu_options.m +++ b/src/+gui_tools/menu_options.m @@ -55,10 +55,10 @@ switch oid handles.estimation_observed_variables.Enable = status; handles.estimation_parameters_shocks.Enable = status; handles.estimation_run_calibrated_smoother.Enable = status; + handles.estimation_run.Enable = status; if project_info.estimation_run handles.estimation_run_smoother2histval.Enable = status; end - handles.estimation_run.Enable = status; case 'stochastic' handles.model_export.Enable = status; diff --git a/src/gui_stoch_simulation.m b/src/gui_stoch_simulation.m index 6779376..8b72b07 100644 --- a/src/gui_stoch_simulation.m +++ b/src/gui_stoch_simulation.m @@ -39,8 +39,10 @@ gui_size = gui_tools.get_gui_elements_size(tabId); % --- PANELS ------------------------------------- handles.uipanelShocks = uipanel( ... 'Parent', tabId, ... - 'Tag', 'uipanelShocks', 'BackgroundColor', special_color,... - 'Units', 'normalized', 'Position', [0.01 0.18 0.48 0.73], ... + 'Tag', 'uipanelShocks', ... + 'BackgroundColor', special_color, ... + 'Units', 'normalized', ... + 'Position', [0.01 0.18 0.48 0.73], ... 'Title', '', ... 'BorderType', 'none'); @@ -49,17 +51,22 @@ uipanelShocks_CreateFcn; handles.uipanelVars = uipanel( ... 'Parent', tabId, ... 'Tag', 'uipanelVars', ... - 'UserData', zeros(1,0), 'BackgroundColor', special_color,... - 'Units', 'normalized', 'Position', [0.51 0.18 0.48 0.73], ... - 'Title', '', 'BorderType', 'none'); + 'UserData', zeros(1,0), ... + 'BackgroundColor', special_color, ... + 'Units', 'normalized', ... + 'Position', [0.51 0.18 0.48 0.7], ... + 'Title', '', ... + 'BorderType', 'none'); handles = gui_tabs.create_endo_vars(handles, 'stoch_simul'); handles.uipanelComm = uipanel( ... 'Parent', tabId, ... 'Tag', 'uipanelCommOptions', ... - 'UserData', zeros(1,0), 'BackgroundColor', bg_color, ... - 'Units', 'normalized', 'Position', [0.01 0.09 0.98 0.09], ... + 'UserData', zeros(1,0), ... + 'BackgroundColor', bg_color, ... + 'Units', 'normalized', ... + 'Position', [0.01 0.09 0.98 0.09], ... 'Title', 'Current command options:'); @@ -67,8 +74,8 @@ handles.uipanelComm = uipanel( ... handles.text7 = uicontrol( ... 'Parent', tabId, ... 'Tag', 'text7', ... - 'Style', 'text', 'BackgroundColor', bg_color,... - 'Units','normalized','Position',[0.51 0.92 0.48 0.05],... + 'Style', 'text', 'BackgroundColor', bg_color, ... + 'Units','normalized','Position',[0.51 0.92 0.48 0.05], ... 'FontWeight', 'bold', ... 'String', 'Select variables for simulation:', ... 'HorizontalAlignment', 'left'); @@ -76,8 +83,8 @@ handles.text7 = uicontrol( ... handles.text8 = uicontrol( ... 'Parent', tabId, ... 'Tag', 'text8', ... - 'Style', 'text', 'BackgroundColor', bg_color,... - 'Units','normalized','Position',[0.01 0.92 0.48 0.05],... + 'Style', 'text', 'BackgroundColor', bg_color, ... + 'Units','normalized','Position',[0.01 0.92 0.48 0.05], ... 'FontWeight', 'bold', ... 'String', 'Select structural shocks:', ... 'HorizontalAlignment', 'left'); @@ -90,18 +97,53 @@ comm_str = gui_tools.command_string('stoch_simul', model_settings.stoch_simul); handles.stoch_simul = uicontrol( ... 'Parent', handles.uipanelComm, ... 'Tag', 'stoch_simul', ... - 'Style', 'text', 'BackgroundColor', bg_color,... + 'Style', 'text', 'BackgroundColor', bg_color, ... 'Units', 'normalized', 'Position', [0.01 0.01 0.98 0.98], ... 'FontAngle', 'italic','String', comm_str, ... 'TooltipString', comm_str, ... 'HorizontalAlignment', 'left'); +% --- Radio Buttons ------------------------------------- +handles.buttongroup = uibuttongroup( ... + 'Parent', tabId, ... + 'Position', [0.51 0.88 0.36 0.05], ... + 'Units', 'normalized', ... + 'SelectionChangedFcn', {@init_val, handles}); + +uicontrol(handles.buttongroup, ... + 'Style', 'text', ... + 'Units', 'normalized', ... + 'Position', [0 -.2 1 1], ... + 'FontWeight', 'bold', ... + 'String', 'Initial value: ', ... + 'HorizontalAlignment', 'left'); + +uicontrol(handles.buttongroup, ... + 'Style', 'radiobutton', ... + 'String', 'zero', ... + 'Units', 'normalized', ... + 'Position', [0.2 0 1 1]); + +uicontrol(handles.buttongroup, ... + 'Style', 'radiobutton', ... + 'String', 'steady state', ... + 'Units', 'normalized', ... + 'Position', [0.3 0 1 1]); + +uicontrol(handles.buttongroup, ... + 'Style', 'radiobutton', ... + 'String', 'smoother', ... + 'Units', 'normalized', ... + 'Position', [0.5 0 1 1]); + + % --- PUSHBUTTONS ------------------------------------- handles.pushbuttonSimulation = uicontrol( ... 'Parent', tabId, ... 'Tag', 'pushbuttonSimulation', ... 'Style', 'pushbutton', ... - 'Units','normalized','Position',[gui_size.space gui_size.bottom gui_size.button_width_small gui_size.button_height],... + 'Units','normalized', ... + 'Position', [gui_size.space gui_size.bottom gui_size.button_width_small gui_size.button_height], ... 'String', 'Run simulation', ... 'Callback', @pushbuttonSimulation_Callback); @@ -109,51 +151,56 @@ handles.pushbuttonReset = uicontrol( ... 'Parent', tabId, ... 'Tag', 'pushbuttonReset', ... 'Style', 'pushbutton', ... - 'Units','normalized','Position',[gui_size.space*2+gui_size.button_width_small gui_size.bottom gui_size.button_width_small gui_size.button_height],... + 'Units','normalized', ... + 'Position', [gui_size.space*2+gui_size.button_width_small gui_size.bottom gui_size.button_width_small gui_size.button_height], ... 'String', 'Reset', ... - 'Callback', @pushbuttonReset_Callback); + 'Callback', @reset); -handles.pushbuttonClose = uicontrol( ... +uicontrol( ... 'Parent', tabId, ... 'Tag', 'pushbuttonReset', ... 'Style', 'pushbutton', ... - 'Units','normalized','Position',[gui_size.space*3+gui_size.button_width_small*2 gui_size.bottom gui_size.button_width_small gui_size.button_height],... + 'Units', 'normalized', ... + 'Position', [gui_size.space*3+gui_size.button_width_small*2 gui_size.bottom gui_size.button_width_small gui_size.button_height], ... 'String', 'Close this tab', ... - 'Callback',{@close_tab,tabId}); + 'Callback', {@close_tab,tabId}); -handles.pushbuttonResults = uicontrol( ... +uicontrol( ... 'Parent', tabId, ... 'Tag', 'pushbuttonSimulation', ... 'Style', 'pushbutton', ... - 'Units','normalized','Position',[gui_size.space*4+gui_size.button_width_small*3 gui_size.bottom gui_size.button_width_small gui_size.button_height],... + 'Units','normalized', ... + 'Position', [gui_size.space*4+gui_size.button_width_small*3 gui_size.bottom gui_size.button_width_small gui_size.button_height], ... 'String', 'Browse results...', ... - 'Enable', 'on',... - 'Callback', @pushbuttonResults_Callback); + 'Enable', 'on', ... + 'Callback', @results); -handles.pushbuttonCloseAll = uicontrol( ... +uicontrol( ... 'Parent', tabId, ... 'Tag', 'pushbuttonSimulation', ... 'Style', 'pushbutton', ... - 'Units','normalized','Position',[gui_size.space*5+gui_size.button_width_small*4 gui_size.bottom gui_size.button_width_small gui_size.button_height],... + 'Units','normalized', ... + 'Position', [gui_size.space*5+gui_size.button_width_small*4 gui_size.bottom gui_size.button_width_small gui_size.button_height], ... 'String', 'Close all output figures', ... - 'Enable', 'on',... - 'Callback', @pushbuttonCloseAll_Callback); + 'Enable', 'on', ... + 'Callback', @close_all); -handles.pushbuttonCommandDefinition = uicontrol( ... +uicontrol( ... 'Parent', tabId, ... 'Tag', 'pushbuttonCommandDefinition', ... 'Style', 'pushbutton', ... - 'Units','normalized','Position',[1-gui_size.space-gui_size.button_width_small gui_size.bottom gui_size.button_width_small gui_size.button_height],... + 'Units', 'normalized', ... + 'Position', [1-gui_size.space-gui_size.button_width_small gui_size.bottom gui_size.button_width_small gui_size.button_height], ... 'String', 'Define command options ...', ... - 'Callback', @pushbuttonCommandDefinition_Callback); + 'Callback', @define_command); function uipanelShocks_CreateFcn() data = cell(size(model_settings.shocks, 1), 2); data(:,1) = {false}; data(:,2) = model_settings.shocks(:,1); - handles.shocksTabGroup = uitabgroup(handles.uipanelShocks,'Position',[0 0 1 1]); + handles.shocksTabGroup = uitabgroup(handles.uipanelShocks, 'Position', [0 0 1 1]); new_tab = uitab(handles.shocksTabGroup, 'Title', 'Shocks' , 'UserData', 1); - currentPanel = uipanel('Parent', new_tab,'BackgroundColor', 'white', 'BorderType', 'none'); + currentPanel = uipanel('Parent', new_tab, 'BackgroundColor', 'white', 'BorderType', 'none'); handles.shocksTable = uitable(currentPanel, ... 'Data', data, ... 'Units', 'normalized', ... @@ -163,7 +210,7 @@ handles.pushbuttonCommandDefinition = uicontrol( ... 'Position', [0 0 1 1]); end - function pushbuttonSimulation_Callback(hObject, ~) + function pushbuttonSimulation_Callback(~, ~) old_oo_ = oo_; try backup = gui_auxiliary.backup_options(options_); @@ -210,7 +257,7 @@ handles.pushbuttonCommandDefinition = uicontrol( ... delete(guiObj); end - function pushbuttonReset_Callback(~, ~) + function reset(~, ~) handles.endoTable.Data(:, 1) = {false}; handles.shocksTable.Data(:,1) = {false}; model_settings.stoch_simul = struct(); @@ -219,7 +266,7 @@ handles.pushbuttonCommandDefinition = uicontrol( ... handles.stoch_simul.TooltipString = comm_str; end - function pushbuttonCommandDefinition_Callback(~, ~) + function define_command(~, ~) h = gui_define_comm_options(dynare_gui_.stoch_simul, 'stoch_simul'); uiwait(h); try @@ -234,11 +281,11 @@ handles.pushbuttonCommandDefinition = uicontrol( ... end end - function pushbuttonResults_Callback(~, ~) + function results(~, ~) gui_results('stoch_smulation', dynare_gui_.stoch_simulation_results); end - function pushbuttonCloseAll_Callback(~, ~) + function close_all(~, ~) gui_tools.close_all_figures(); end @@ -246,3 +293,24 @@ handles.pushbuttonCommandDefinition = uicontrol( ... gui_tabs.delete_tab(hTab); end end + +function init_val(~, evt, handles) +global M_ oo_ model_settings +if strcmp(evt.NewValue.String, 'zero') + handles.endoTable.Data(:,3) = num2cell(zeros(M_.orig_endo_nbr, 1)); +elseif strcmp(evt.NewValue.String, 'steady state') + if ~isfield(oo_, 'steady_state') + gui_tools.show_warning('Must first calculate the steady state') + evt.OldValue.Value = 1; + return + end + handles.endoTable.Data(:,3) = num2cell(oo_.steady_state([model_settings.variables{:, 4}])); +elseif strcmp(evt.NewValue.String, 'smoother') + if ~isfield(oo_, 'SmoothedVariables') + gui_tools.show_warning('Must first run smoother') + evt.OldValue.Value = 1; + return + end + handles.endoTable.Data(:,3) = num2cell(oo_.SmoothedVariables); +end +end -- GitLab