Skip to content

Commit

Permalink
Issues #51, #54, #55
Browse files Browse the repository at this point in the history
  • Loading branch information
yzontov committed Jul 21, 2019
1 parent 97cb293 commit 9a21355
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 84 deletions.
2 changes: 1 addition & 1 deletion PLSDAGUI.m
Expand Up @@ -110,7 +110,7 @@ function btnExistingModel_Callback(obj, ~)
assignin('base', Model.TrainingDataSet.Name, Model.TrainingDataSet);

win = GUIWindow(vect, tvarname{1}, Model);

win.modelTab.model_was_saved = true;
end

end
Expand Down
8 changes: 4 additions & 4 deletions classes/CVTab.m
Expand Up @@ -618,7 +618,7 @@ function SaveDatasets(self, src, param)
hbox222 = uix.Grid( 'Parent', vbox21,'Spacing', 1);
%obj.lblSelectedSplit = uicontrol('Parent', hbox222, 'Style', 'text', 'String', 'Split','Visible','off');

obj.lblSelectedPC = uicontrol('Parent', hbox222, 'Style', 'text', 'String', 'Number of PLS components','Visible','on');
obj.lblSelectedPC = uicontrol('Parent', hbox222, 'Style', 'text', 'String', 'PLS components','Visible','on');
obj.ddlSelectedPC = uicontrol('Parent', hbox222, 'Style', 'popupmenu', 'String', {'-'},...
'Value',1, 'BackgroundColor', 'white', 'callback', @obj.Callback_SelectedPC,'Visible','on');

Expand All @@ -629,7 +629,7 @@ function SaveDatasets(self, src, param)
if ispc
hbox222.Widths = [60,50,60,50];
else
hbox222.Widths = [50,70,50,70];
hbox222.Widths = [60,65,45,70];
end

hboxp24 = uix.HButtonBox( 'Parent', vbox21, 'ButtonSize', [120 25]);
Expand Down Expand Up @@ -751,9 +751,9 @@ function SaveDatasets(self, src, param)

hboxp7 = uiextras.HButtonBox( 'Parent', vbox_cv, 'ButtonSize', [120 25]);
obj.btnCVSave = uicontrol('Parent', hboxp7, 'Style', 'pushbutton', 'String', 'Save CV Task',...
'callback', @obj.Callback_SaveCVTask, 'enable', 'off');
'callback', @obj.Callback_SaveCVTask, 'enable', 'off', 'visible', 'off');
uicontrol('Parent', hboxp7, 'Style', 'pushbutton', 'String', 'Load CV Task',...
'callback', @obj.Callback_LoadCVTask);
'callback', @obj.Callback_LoadCVTask, 'visible', 'off');

if ispc
obj.vbox.Heights=[40,130,150,0,0,0];
Expand Down
36 changes: 20 additions & 16 deletions classes/DataTab.m
Expand Up @@ -81,32 +81,36 @@ function RefreshDatasetList(self)
self.FillDataSetList();
self.RefreshModel();

allvars = evalin('base','whos');
varnames = {allvars.name};

idx = find(cellfun(@(x)isequal(x,'DataSet'),{allvars.class}));

idx_data = arrayfun(@(x)GUIWindow.filter_data(x), allvars);
if(isempty(self.parent.cvTab) && sum(idx_data) > 0)
self.parent.cvTab = CVTab(self.parent.tgroup, self.parent);
end

if(~isempty(self.parent.cvTab) && sum(idx_data) == 0)
if(~isempty(self.parent.cvTab) && isempty(self.parent.modelTab))
ind = arrayfun(@(x)isequal(x.Title ,'Cross-validation'),self.parent.tgroup.Children);
cvtab = self.parent.tgroup.Children(ind);
delete(cvtab);
delete(self.parent.cvTab);
self.parent.cvTab = [];
end

if (~isempty(self.parent.cvTab) && sum(idx_data) > 0)
self.parent.cvTab.FillDataSetList(true);
end

end

function RefreshDatasetListCallback(self, src, param)
self.RefreshDatasetList();

if ~isempty(self.parent.modelTab) && ~isempty(self.parent.modelTab.Model) && ~self.parent.modelTab.model_was_saved
selection = questdlg(sprintf('The current model will be lost!\nYou may want to save it on the Model tab first.\nDo you want to proceed?'),...
'Warning',...
'Yes','No','No');
switch selection
case 'Yes'
self.RefreshDatasetList();
case 'No'
return
end
else
if ~isempty(self.parent.modelTab) && ~isempty(self.parent.modelTab.Model) && self.parent.modelTab.model_was_saved
opts = struct('WindowStyle','modal','Interpreter','none','Icon','info');
warndlg(sprintf('The current model was reset.\nChoose the ''Existing model'' option on the start screen.'),'Info',opts);
end
self.RefreshDatasetList();
end

end

function ttab = DataTab(tabgroup, parent)
Expand Down
26 changes: 24 additions & 2 deletions classes/GUIWindow.m
Expand Up @@ -44,6 +44,24 @@

methods

function my_closereq(self,src,callbackdata)
% Close request function
% to display a question dialog box
if ~isempty(self.modelTab) && ~isempty(self.modelTab.Model) && ~self.modelTab.model_was_saved
selection = questdlg(sprintf('The current model will be lost!\nDo want to exit without saving it?'),...
'Confirm Close',...
'Yes','No','No');
switch selection
case 'Yes'
delete(gcf)
case 'No'
return
end
else
delete(gcf)
end
end

function deleteDataset(obj, src)
obj.dataTab.FillDataSetList();

Expand Down Expand Up @@ -169,13 +187,16 @@ function ActiveTabSelected(self, obj, param)
switch obj.SelectedTab.Title
case 'Classification plot'
self.selected_panel = GUIWindow.ModelGraph;
case 'Classification table'
self.selected_panel = GUIWindow.ModelTable;
% case 'Classification table'
% self.selected_panel = GUIWindow.ModelTable;
case 'Allocation table'
self.selected_panel = GUIWindow.ModelTable;
self.selected_text_panel = GUIWindow.ModelTableAllocation;
case 'Confusion matrix'
self.selected_panel = GUIWindow.ModelTable;
self.selected_text_panel = GUIWindow.ModelTableConfusion;
case 'Figures of merit'
self.selected_panel = GUIWindow.ModelTable;
self.selected_text_panel = GUIWindow.ModelTableFoM;
end
case GUIWindow.PredictTabSelected
Expand Down Expand Up @@ -438,6 +459,7 @@ function Help_Callback(self, obj, param)

%gui
f = figure;
set(f,'CloseRequestFcn',@win.my_closereq);
set(f,'Visible','on');
set(f, 'MenuBar', 'none');
set(f, 'ToolBar', 'none');
Expand Down
123 changes: 62 additions & 61 deletions classes/ModelTab.m
Expand Up @@ -2,6 +2,7 @@

properties
Model;
model_was_saved = false;

pnlDataSettings;
pnlModelSettings
Expand Down Expand Up @@ -209,7 +210,7 @@ function enablePanel(self, panel, param)

if(strcmp('off',param))
tg.SelectedTab = tg.Children(1);
self.tbl_tabgroup.SelectedTab = self.tbl_tabgroup.Children(1);
%self.tbl_tabgroup.SelectedTab = self.tbl_tabgroup.Children(1);

if self.parent.selected_tab == GUIWindow.ModelTabSelected
%self.parent.selected_tab = GUIWindow.ModelTabSelected;
Expand Down Expand Up @@ -329,20 +330,20 @@ function enablePanel(self, panel, param)

tg = uitabgroup('Parent', ttab.middle_panel);
ttab.tab_img = uitab('Parent', tg, 'Title', 'Classification plot');
tab_txt = uitab('Parent', tg, 'Title', 'Classification table');
%tab_txt = uitab('Parent', tg, 'Title', 'Classification table');

w = ttab.parent;
set(tg, 'SelectionChangedFcn', @w.ActiveTabSelected);

tg2 = uitabgroup('Parent', tab_txt);
tab_alloc = uitab('Parent', tg2, 'Title', 'Allocation table');
tab_confusion = uitab('Parent', tg2, 'Title', 'Confusion matrix');
tab_fom = uitab('Parent', tg2, 'Title', 'Figures of merit');
%tg2 = uitabgroup('Parent', tab_txt);
tab_alloc = uitab('Parent', tg, 'Title', 'Allocation table');
tab_confusion = uitab('Parent', tg, 'Title', 'Confusion matrix');
tab_fom = uitab('Parent', tg, 'Title', 'Figures of merit');

ttab.tbl_tabgroup = tg2;
%ttab.tbl_tabgroup = tg2;

w = ttab.parent;
set(tg2, 'SelectionChangedFcn', @w.ActiveTabSelected);
%w = ttab.parent;
%set(tg2, 'SelectionChangedFcn', @w.ActiveTabSelected);

ttab.tblTextConfusion = uitable(tab_confusion);
ttab.tblTextConfusion.Units = 'normalized';
Expand Down Expand Up @@ -455,63 +456,62 @@ function Redraw(self)

function Recalibrate(self, src, ~)

self.model_was_saved = false;
index_selected = get(self.ddlCalibrationSet,'Value');

if index_selected > 1
self.ClearModel();


index_selected = get(self.ddlCalibrationSet,'Value');
names = get(self.ddlCalibrationSet,'String');%fieldnames(ttab.Data);
selected_name = names{index_selected};

d = evalin('base', selected_name);

numPC = str2double(get(self.tbNumPCpls,'string'));

if get(self.ddlModelType,'value') == 2
mode = 'soft';
else
mode = 'hard';
end

alpha = str2double(get(self.tbAlpha,'string'));
gamma = str2double(get(self.tbGamma,'string'));

h = waitbar(0, 'Please wait...');

waitbar(2.5/10, h);
m = PLSDAModel(d, numPC, alpha, gamma);

if strcmp(mode, 'hard')
m.Mode = mode;
m.Rebuild();
end
waitbar(5/10, h);
self.Model = m;
waitbar(7.5/10, h);
set(self.chkFinalizeModel,'enable','on');
set(self.btnSaveModel,'enable','on');

waitbar(10/10, h);
%pause(.5);
delete(h);

self.Redraw();
self.enablePanel(self.pnlPlotSettings, 'on');
self.enablePanel(self.pnlTableSettings, 'on');

tg = self.tab_img.Parent;
tg.Visible = 'on';
self.ClearModel();


index_selected = get(self.ddlCalibrationSet,'Value');
names = get(self.ddlCalibrationSet,'String');%fieldnames(ttab.Data);
selected_name = names{index_selected};

d = evalin('base', selected_name);

numPC = str2double(get(self.tbNumPCpls,'string'));

if get(self.ddlModelType,'value') == 2
mode = 'soft';
else
mode = 'hard';
end

alpha = str2double(get(self.tbAlpha,'string'));
gamma = str2double(get(self.tbGamma,'string'));

h = waitbar(0, 'Please wait...');

waitbar(2.5/10, h);
m = PLSDAModel(d, numPC, alpha, gamma);

if strcmp(mode, 'hard')
m.Mode = mode;
m.Rebuild();
end
waitbar(5/10, h);
self.Model = m;
waitbar(7.5/10, h);
set(self.chkFinalizeModel,'enable','on');
set(self.btnSaveModel,'enable','on');

waitbar(10/10, h);
%pause(.5);
delete(h);

self.Redraw();
self.enablePanel(self.pnlPlotSettings, 'on');
self.enablePanel(self.pnlTableSettings, 'on');

tg = self.tab_img.Parent;
tg.Visible = 'on';

win = self.parent;
if isempty(win.cvTab)
win.cvTab = CVTab(win.tgroup, win);
end



if isempty(win.cvTab)
win.cvTab = CVTab(win.tgroup, win);
end


end
end

Expand All @@ -534,7 +534,7 @@ function SaveModel(self, src, ~)

extra_title = [' - Model: ' self.Model.Name];
set(self.parent.fig ,'name',['PLS-DA Tool' extra_title],'numbertitle','off');

self.model_was_saved = true;
catch
opts = struct('WindowStyle','modal','Interpreter','none');
errordlg('The invalid characters have been replaced. Please use only latin characters, numbers and underscore!','Error',opts);
Expand All @@ -545,6 +545,7 @@ function SaveModel(self, src, ~)

extra_title = [' - Model: ' self.Model.Name];
set(self.parent.fig ,'name',['PLS-DA Tool' extra_title],'numbertitle','off');
self.model_was_saved = true;
end
end

Expand Down

0 comments on commit 9a21355

Please sign in to comment.