diff --git a/src/+gui_tools/menu_options.m b/src/+gui_tools/menu_options.m index 56ef718ccf905bbb40220318ec50624e26fe3cd0..f0d93416537b3f310872207e6f5a0577c4d3badc 100644 --- a/src/+gui_tools/menu_options.m +++ b/src/+gui_tools/menu_options.m @@ -55,6 +55,9 @@ switch oid handles.estimation_observed_variables.Enable = status; handles.estimation_parameters_shocks.Enable = status; handles.estimation_run_calibrated_smoother.Enable = status; + if project_info.estimation_run + handles.estimation_run_smoother2histval.Enable = status; + end handles.estimation_run.Enable = status; case 'stochastic' diff --git a/src/dynare_gui.m b/src/dynare_gui.m index 4d624337106fc1743460a24e17a995db29a36cbe..a52ede96121d482d7ca83ce2ee8776e96981af92 100644 --- a/src/dynare_gui.m +++ b/src/dynare_gui.m @@ -287,6 +287,11 @@ possibly_create_model_settings(); gui_calib_smoother(addTab(hObject, 'Calib. smoother ', handles)); end +function estimation_run_smoother2histval_Callback(hObject, ~, handles) +possibly_create_model_settings(); +gui_smoother2histval(addTab(hObject, 'Smoother2Histval ', handles)); +end + function possibly_create_model_settings() if ~isappdata(0, 'model_settings') || isempty(getappdata(0, 'model_settings')) gui_create_model_settings(); @@ -625,6 +630,19 @@ uimenu(... 'Tag','estimation_run_calibrated_smoother',... 'CreateFcn', {@local_CreateFcn, blanks(0), appdata} ); + +appdata = []; +appdata.lastValidTag = 'estimation_run_smoother2histval'; + +uimenu(... + 'Parent',h18,... + 'Enable','off',... + 'Separator','on',... + 'Callback',@(hObject,eventdata)dynare_gui('estimation_run_smoother2histval_Callback',hObject,eventdata,guidata(hObject)),... + 'Label','Run smoother2histval',... + 'Tag','estimation_run_smoother2histval',... + 'CreateFcn', {@local_CreateFcn, blanks(0), appdata} ); + appdata = []; appdata.lastValidTag = 'estimation_run'; diff --git a/src/gui_smoother2histval.m b/src/gui_smoother2histval.m new file mode 100644 index 0000000000000000000000000000000000000000..cc41a264389677e9488f5d761dcd493c65eab7b3 --- /dev/null +++ b/src/gui_smoother2histval.m @@ -0,0 +1,284 @@ +function gui_smoother2histval(tabId) +% function gui_smoother2histval(tabId) +% interface for the DYNARE smoother2histval command +% +% INPUTS +% tabId: GUI tab element which displays smoother2histval command interface +% +% OUTPUTS +% none +% +% SPECIAL REQUIREMENTS +% none + +% Copyright (C) 2019 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + +global project_info options_ model_settings oo_ estim_params_ M_ bayestopt_ + +handles = []; +gui_size = gui_tools.get_gui_elements_size(tabId); + +model_settings.smoother2histval = struct(); +model_settings.smoother2histval.period = options_.nobs; +model_settings.smoother2histval.invars = [strjoin(M_.endo_names(1:M_.orig_endo_nbr), ',') ',' strjoin(M_.exo_names, ',')]; +model_settings.smoother2histval.outvars = model_settings.smoother2histval.invars; + +% --- PANELS ------------------------------------- +handles.uipanelVars = uipanel(tabId, ... + 'Units', 'normalized', ... + 'Position', [0.01 0.18 0.48 0.73], ... + 'Title', '', ... + 'BorderType', 'none'); + +handles = gui_tabs.create_endo_vars(handles, 'smoother2histval'); +handles.endoTable.Data(:, 1) = {true}; +handles.endoTable.CellEditCallback = @selectVar; + +handles.command_options = uipanel(tabId, ... + 'Units', 'normalized', ... + 'Position', [0.51 0.7 0.48 0.2], ... + 'Title', 'Command options:'); + +command_options_CreateFcn; + +handles.uipanelShocks = uipanel( ... + 'Parent', tabId, ... + 'Tag', 'uipanelShocks', ... + 'Units', 'normalized', ... + 'Position', [0.51 0.18 0.48 0.5], ... + 'Title', '', ... + 'BorderType', 'none'); + +uipanelShocks_CreateFcn; + + function uipanelShocks_CreateFcn() + data = cell(size(model_settings.shocks, 1), 2); + data(:,1) = {true}; + data(:,2) = model_settings.shocks(:,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'); + handles.shocksTable = uitable(currentPanel, ... + 'Data', data, ... + 'Units', 'normalized', ... + 'ColumnName', {'Active','Shock'}, ... + 'ColumnEditable', [true false], ... + 'RowName', [], ... + 'Position', [0 0 1 1], ... + 'CellEditCallback', @selectVar); + end + +handles.uipanelComm = uipanel(tabId, ... + 'UserData', zeros(1,0), ... + 'Units', 'normalized', ... + 'Position', [0.01 0.09 0.98 0.09], ... + 'Title', 'Current command options:'); + +uicontrol(tabId, ... + 'Style', 'text', ... + 'Units','normalized', ... + 'Position',[0.01 0.92 0.48 0.05], ... + 'FontWeight', 'bold', ... + 'String', 'Select variables to be used by smoother2histval:', ... + 'HorizontalAlignment', 'left'); + +comm_str = gui_tools.command_string('smoother2histval', model_settings.smoother2histval); + +handles.smoother2histval = uicontrol(handles.uipanelComm, ... + 'Style', 'text', ... + 'Units', 'normalized', ... + 'Position', [0.01 0.01 0.98 0.98], ... + 'FontAngle', 'italic', ... + 'String', comm_str, ... + 'HorizontalAlignment', 'left'); + +handles.RunSmoother2histval = uicontrol(tabId, ... + 'Style', 'pushbutton', ... + 'Units', 'normalized', ... + 'Position', [gui_size.space gui_size.bottom gui_size.button_width gui_size.button_height], ... + 'String', 'Run smoother2histval', ... + 'Callback', @RunSmoother2histvalCallback); + +handles.Reset = uicontrol(tabId, ... + 'Style', 'pushbutton', ... + 'Units','normalized', ... + 'Position', [gui_size.space*2+gui_size.button_width gui_size.bottom gui_size.button_width gui_size.button_height], ... + 'String', 'Reset', ... + 'Callback', @Reset_Callback); + +handles.Close = uicontrol(tabId, ... + 'Style', 'pushbutton', ... + 'Units', 'normalized', ... + 'Position', [gui_size.space*3+gui_size.button_width*2 gui_size.bottom gui_size.button_width gui_size.button_height], ... + 'String', 'Close tab', ... + 'Callback', {@close_tab, tabId}); + + function command_options_CreateFcn() + uicontrol(handles.command_options, ... + 'Style', 'text', ... + 'Units', 'normalized', ... + 'Position', [.05 .8 .3 .17], ... + 'String', 'infile:', ... + 'HorizontalAlignment', 'left'); + + handles.infile = uicontrol(handles.command_options, ... + 'Style', 'edit', ... + 'Units', 'normalized', ... + 'Position', [.12 .8 .7 .17], ... + 'HorizontalAlignment', 'left', ... + 'Callback', {@checkCommOption_Callback, 'infile'}); + + uicontrol(handles.command_options, ... + 'Style', 'text', ... + 'Units', 'normalized', ... + 'Position', [.05 .6 .3 .17], ... + 'String', 'outfile:', ... + 'HorizontalAlignment', 'left'); + + handles.outfile = uicontrol(handles.command_options, ... + 'Style', 'edit', ... + 'Units', 'normalized', ... + 'Position', [.12 .6 .7 .17], ... + 'HorizontalAlignment', 'left', ... + 'Callback', {@checkCommOption_Callback, 'outfile'}); + + uicontrol(handles.command_options, ... + 'Style', 'text', ... + 'Units', 'normalized', ... + 'Position', [.05 .4 .3 .17], ... + 'String', 'period:', ... + 'HorizontalAlignment', 'left'); + + handles.period = uicontrol(... + 'Parent', handles.command_options, ... + 'Style', 'edit', ... + 'Units', 'normalized', ... + 'Position', [.12 .4 .7 .17], ... + 'HorizontalAlignment', 'left', ... + 'String', num2str(options_.nobs), ... + 'Callback', {@checkCommOption_Callback, 'period'}); + + uicontrol(handles.command_options, ... + 'Style', 'checkbox', ... + 'Units', 'normalized', ... + 'Position', [.05 .2 .2 .17], ... + 'String', 'clear endogs', ... + 'Callback', @clearendogs); + + uicontrol(handles.command_options, ... + 'Style', 'checkbox', ... + 'Units', 'normalized', ... + 'Position', [.35 .2 .2 .17], ... + 'String', 'clear exogs', ... + 'Callback', @clearexogs); + + function checkCommOption_Callback(~, ~, option_name) + comm_options = model_settings.smoother2histval; + switch option_name + case 'infile' + comm_options.infile = handles.infile.String; + case 'outfile' + comm_options.outfile = handles.outfile.String; + case 'period' + period = str2double(handles.period.String); + if isnan(period) || ~isint(period) ... + || period < 1 || period > options_.nobs + gui_tools.show_error(['period must be an int between 1 and ' options_.nobs]) + return + end + comm_options.period = period; + end + comm_str = gui_tools.command_string('smoother2histval', comm_options); + handles.smoother2histval.String = comm_str; + model_settings.smoother2histval = comm_options; + end + end + + function RunSmoother2histvalCallback(hObject, ~) + try + options_smoother2histval = model_settings.smoother2histval; + + gui_tools.project_log_entry('Running smoother2histval ','...'); + [jObj, guiObj] = gui_tools.create_animated_screen('Running smoother2histval, please wait...', tabId); + + smoother2histval(options_smoother2histval); + + jObj.stop; + jObj.setBusyText('All done!'); + project_info.modified = true; + project_info.smoother2histval_run = true; + gui_set_menus(true); + catch ME + jObj.stop; + jObj.setBusyText('Done with errors!'); + gui_tools.show_error('Error in execution of smoother2histval command', ME, 'extended'); + uicontrol(hObject); + end + delete(guiObj); + end + + function Reset_Callback(~, ~) + handles.infile.String = ''; + handles.outfile.String = ''; + handles.periods.String = ''; + handles.endoTable.Data(:, 1) = {true}; + handles.shocksTable.Data(:,1) = {true}; + end + + function selectVar(~, ~) + comm_options = model_settings.smoother2histval; + if any([handles.endoTable.Data{:,1} handles.shocksTable.Data{:,1}]) + comm_options.invars = strjoin(handles.endoTable.Data([handles.endoTable.Data{:,1}], 2), ','); + if any([handles.shocksTable.Data{:,1}]) + if ~isempty(comm_options.invars) + comm_options.invars = [ comm_options.invars ',']; + end + comm_options.invars = ... + [ ... + comm_options.invars ... + strjoin(handles.shocksTable.Data([handles.shocksTable.Data{:,1}], 2), ',') ... + ]; + end + comm_options.outvars = comm_options.invars; + else + if isfield(comm_options, 'invars') + comm_options = rmfield(comm_options, 'invars'); + end + if isfield(comm_options, 'outvars') + comm_options = rmfield(comm_options, 'outvars'); + end + end + comm_str = gui_tools.command_string('smoother2histval', comm_options); + handles.smoother2histval.String = comm_str; + model_settings.smoother2histval = comm_options; + end + + function clearendogs(~, evt) + handles.endoTable.Data(:,1) = {~logical(evt.Source.Value)}; + selectVar(1, 1); + end + + function clearexogs(~, evt) + handles.shocksTable.Data(:,1) = {~logical(evt.Source.Value)}; + selectVar(1, 1); + end +end + +function close_tab(~, ~, hTab) +gui_tabs.delete_tab(hTab); +end