📄 dimredlayout.m
字号:
function dimredlayout
% This function will layout the gui controls. Eventually, this will be
% included in the complete function. Just have it now for simplicity.
% First get the user data from the root. See if anything is stored there.
% H.fig Handle to the GUI figure window
% H.plots Handles to plots opened with this GUI.
%
% H.pcadim Handle to edit box that specifies the number of dimensions for PCA
% H.isodim Handle to edit box that specifies the number of dimensions for ISOMAP.
% H.isok Handle to edit box that specifies the number of nearest neighbors for ISOMAP
% H.llek Handle to edit box that specifies the number of nearest neighbors for LLE
% H.lledim Handle to edit box that specifies the number of dimensions for LLE
% H.pcatype Handle to popupmenu for type of PCA
% {'Covariance','Correlation'}
% H.isodist Handle to popupmenu for type of distance - ISOMAP
% {'euclidean';'seuclidean';'cityblock';'mahalanobis';'minkowski'}
% H.lletype Handle to popupmenu for type of LLE
% {'LLE','Hessian LLE'});
% H.pcapv Handle to radio button: Percent variance explained
% H.pcacv Handle to radio button: Cumulative Variance
% H.pcabs Handle to radio button: Broken stick
% H.pcascree Handle to radio button: Scree plot
% H.isoscree Handle to scree plot for ISOMAP
ud = get(0,'userdata');
H.fig = figure('Tag','dimredgui',...
'position',[150 150 726 524],...
'resize','off',...
'toolbar','none',...
'menubar','none',...
'numbertitle','off',...
'name','Dimensionality Reduction GUI',...
'CloseRequestFcn','dimredgui(''close'')');
if strcmp(version('-release'),'14')
set(0,'DefaultUicontrolFontname','Sans Serif');
end
% Keep track of GUI plots in this array. So, we can close when the gui is
% closed.
H.plots = [];
if ~isempty(ud)
% Then something is there already. Add necessary handles to the
% structure.
ud.guis = [ud.guis(:); H.fig];
else
% Set the usual stuff and save in root.
ud = userdata;
set(0,'userdata',ud)
end
%%%%%%% FRAMES %%%%%%%%%%%%%%%
% set up all of the frames first.
uicontrol(H.fig, 'style','frame',...
'position',[21 306 680 140]);
uicontrol(H.fig, 'style','frame',...
'position',[21 160 680 140]);
uicontrol(H.fig, 'style','frame',...
'position',[21 15 680 140]);
%%%%%%%%%%%%%%%%%%
uicontrol(H.fig, 'style','frame',...
'position',[140 310 220 95]);
% uicontrol(H.fig, 'style','frame',...
% 'position',[460 170 225 95]);
%%%%%%%%%%%%%%%%%%%%
% uicontrol(H.fig, 'style','frame',...
% 'position',[460 310 225 95]);
%%%%%%% TEXT BOXES %%%%%%%%%%%%%%
% set up all of the text boxes
uicontrol(H.fig,'style','text',...
'position',[170 495 330 27],...
'fontweight','bold',...
'fontsize',14,...
'backgroundcolor',[.8 .8 .8],...
'string','Dimensionality Reduction')
% Title boxes
uicontrol(H.fig,'style','text',...
'position',[40 405 250 34],...
'fontweight','bold',...
'fontsize',10,...
'horizontalalignment','left',...
'string','Principal Component Analysis (PCA)')
uicontrol(H.fig,'style','text',...
'position',[40 260 200 34],...
'fontweight','bold',...
'fontsize',10,...
'horizontalalignment','left',...
'string','Isometric Feature Mapping (ISOMAP)')
uicontrol(H.fig,'style','text',...
'position',[40 115 200 34],...
'fontweight','bold',...
'fontsize',10,...
'horizontalalignment','left',...
'string','Locally Linear Methods (LLE/HLLE)')
% Instruction text boxes:
uicontrol(H.fig,'style','text',...
'position',[130 455 475 35],...
'horizontalalignment','left',...
'backgroundcolor',[.8 .8 .8],...
'string','Use these methods to find reduced-dimensional representations of the data. PCA is a linear mapping; the others are nonlinear. See the command window for progress (some methods).')
% Steps - text in frame 1
uicontrol(H.fig,'style','text',...
'position',[40 355 95 30],...
'fontsize',9,...
'horizontalalignment','left',...
'string','1. Choose type:')
uicontrol(H.fig,'style','text',...
'position',[150 320 90 80],...
'fontsize',9,...
'horizontalalignment','left',...
'string','2. Select methods to choose the number of dimensions:')
uicontrol(H.fig,'style','text',...
'position',[370 355 82 30],...
'fontsize',9,...
'horizontalalignment','left',...
'string','3. Push for PCA:')
uicontrol(H.fig,'style','text',...
'position',[575 400 100 25],...
'fontsize',8,...
'horizontalalignment','left',...
'string','Choose number of dimensions:')
% Steps - text in frame 2
uicontrol(H.fig,'style','text',...
'position',[40 220 105 30],...
'fontsize',9,...
'horizontalalignment','left',...
'string','1. Calculate distances:')
uicontrol(H.fig,'style','text',...
'position',[150 220 105 30],...
'fontsize',9,...
'horizontalalignment','left',...
'string','2. Number of neighbors:')
uicontrol(H.fig,'style','text',...
'position',[365 220 95 30],...
'fontsize',9,...
'horizontalalignment','left',...
'string','4. Push for ISOMAP:')
uicontrol(H.fig,'style','text',...
'position',[575 255 100 25],...
'fontsize',8,...
'horizontalalignment','left',...
'string','Choose number of dimensions:')
% Steps - text in frame 3
uicontrol(H.fig,'style','text',...
'position',[40 75 105 30],...
'fontsize',9,...
'horizontalalignment','left',...
'string','1. Choose type:')
uicontrol(H.fig,'style','text',...
'position',[150 75 105 30],...
'fontsize',9,...
'horizontalalignment','left',...
'string','2. Number of neighbors:')
uicontrol(H.fig,'style','text',...
'position',[260 75 105 30],...
'fontsize',9,...
'horizontalalignment','left',...
'string','3. Number of dimensions:')
uicontrol(H.fig,'style','text',...
'position',[365 75 95 30],...
'fontsize',9,...
'horizontalalignment','left',...
'string','4. Push for LLEs:')
%%%%%%% BUTTONS %%%%%%%%%%%%%%%%%%%%
uicontrol(H.fig,'style','pushbutton',...
'position',[14 491 88 23],...
'string','LOAD DATA',...
'tooltipstring','This will bring up the Load Data GUI',...
'callback','loadgui')
uicontrol(H.fig,'style','pushbutton',...
'position',[14 463 88 23],...
'string','TRANSFORM',...
'tooltipstring','This will bring up the Transform Data GUI.',...
'callback','transformgui')
%%%%%%%%%%%%%%%%%%
uicontrol(H.fig,'style','pushbutton',...
'position',[375 325 55 22],...
'string','DO PCA',...
'tooltipstring','This will obtain the PCA calculations.',...
'callback','dimredgui(''dopca'')')
uicontrol(H.fig,'style','pushbutton',...
'position',[470 325 100 25],...
'string','GRAPHICAL EDA',...
'tooltipstring','This will let you visually explore your data using all p dimensions.',...
'callback','dimredgui(''geda'',''PCA'')')
uicontrol(H.fig,'style','pushbutton',...
'position',[575 325 100 25],...
'string','OUTPUT DATA',...
'tooltipstring','This will output the transformed d-dimensional data to the workspace.',...
'callback','dimredgui(''pcaout'')')
%%%%%%%%%%%%%%%%%%%%%%%
uicontrol(H.fig,'style','pushbutton',...
'position',[360 180 70 22],...
'string','DO ISOMAP',...
'tooltipstring','This will obtain the ISOMAP coordinates.',...
'callback','dimredgui(''doisomap'')')
uicontrol(H.fig,'style','pushbutton',...
'position',[470 180 100 25],...
'string','GRAPHICAL EDA',...
'tooltipstring','This will let you visually explore your data using all p dimensions.',...
'callback','dimredgui(''geda'',''ISOMAP'')')
uicontrol(H.fig,'style','pushbutton',...
'position',[575 180 100 25],...
'string','OUTPUT DATA',...
'tooltipstring','This will output the transformed d-dimensional data to the workspace.',...
'callback','dimredgui(''isomapout'')')
%%%%%%%%%%%%%%%%%%%%%%%
uicontrol(H.fig,'style','pushbutton',...
'position',[370 40 55 22],...
'string','DO LLEs',...
'tooltipstring','This will obtain the LLE coordinates.',...
'callback','dimredgui(''dolle'')')
uicontrol(H.fig,'style','pushbutton',...
'position',[470 40 100 25],...
'string','GRAPHICAL EDA',...
'tooltipstring','This will let you visually explore your d-dimensional data.',...
'callback','tg = findobj(''tag'',''dimredgui'');H = get(tg,''userdata'');tmp = get(H.lletype,''string'');v = get(H.lletype,''value'');if strcmp(tmp{v}(1),''L'');typ = ''LLE'';else;typ = ''HLLE'';end;dimredgui(''geda'',typ)')
% tg = findobj('tag','dimredgui');
% H = get(tg,'userdata');
% tmp = get(H.lletype,'string');
% v = get(H.lletype,''value'');
% if strcmp(tmp{v}(1),''L'');
% typ = ''LLE'';
% else;
% typ = ''HLLE'';
% end;
uicontrol(H.fig,'style','pushbutton',...
'position',[575 40 100 25],...
'string','OUTPUT DATA',...
'tooltipstring','This will output the transformed d-dimensional data to the workspace.',...
'callback','dimredgui(''lleout'')')
% Close button
uicontrol(H.fig,'style','pushbutton',...
'position',[620 485 66 25],...
'string','CLOSE',...
'callback','dimredgui(''close'')',...
'tooltipstring','Push this button to close the GUI window.')
%%%%%% EDIT BOXES %%%%%%%%%%%%%%%%%%%%%%
% First frame
if ~isempty(ud.X)
[n,p] = size(ud.X);
if p <=10
% then just use that number.
boxstr = int2str(p);
else
boxstr = int2str(10);
end
else
boxstr = '2';
end
H.pcadim = uicontrol('style','edit',...
'string',boxstr,...
'position',[628 373 40 20],...
'backgroundcolor','white',...
'tooltipstring','The number of dimensions viewed in the Graphical EDA GUI and for the data sent to the workspace.');
% Second Frame
H.isodim = uicontrol('style','edit',...
'string',boxstr,...
'position',[628 230 40 20],...
'backgroundcolor','white',...
'tooltipstring','The number of dimensions viewed in the Graphical EDA GUI and for the data sent to the workspace.');
H.isok = uicontrol('style','edit',...
'string','10',...
'position', [155 190 40 20] ,...
'backgroundcolor','white',...
'tooltipstring','This governs the neighborhood size.');
% Third Frame
H.llek = uicontrol('style','edit',...
'string','10',...
'position',[155 40 40 20],...
'backgroundcolor','white',...
'tooltipstring','This governs the neighborhood size.');
H.lledim = uicontrol('style','edit',...
'string','2',...
'position',[260 40 40 20],...
'backgroundcolor','white',...
'tooltipstring','The number of dimensions viewed in the Graphical EDA GUI and for the data sent to the workspace.');
%%%%%%%%% POPUPMENU %%%%%%%%%%%%%%%%%
H.pcatype = uicontrol('style','popupmenu',...
'position',[45 330 80 20],...
'backgroundcolor','white',...
'String',{'Covariance','Correlation'},...
'tooltipstring','PCA can use either the covariance matrix or the correlation matrix.');
H.isodist= uicontrol('style','popupmenu',...
'position',[40 188 80 20],...
'backgroundcolor','white',...
'String',{'euclidean';'seuclidean';'cityblock';'mahalanobis';'minkowski'},...
'tooltipstring','You must find the interpoint distances for ISOMAP.');
H.lletype = uicontrol('style','popupmenu',...
'position',[40 40 80 20],...
'backgroundcolor','white',...
'String',{'LLE','Hessian LLE'});
%%%%%%%% RADIO BUTTON %%%%%%%%%%%%%%%%
H.pcapv = uicontrol('style','radio',...
'position',[245 378 95 20],...
'String','% Variance',...
'fontsize',8,...
'tooltipstring','Estimates number of dimensions based on 90% percent of variance explained.');
H.pcacv = uicontrol('style','radio',...
'position',[245 356 95 20],...
'String','Size of Var',...
'fontsize',8,...
'tooltipstring','Recommended number of dimensions is the number of eigenvalues above the average.');
H.pcabs = uicontrol('style','radio',...
'position',[245 335 95 20],...
'String','Broken Stick',...
'fontsize',8,...
'tooltipstring','Estimates number of dimensions based on broken stick test.');
H.pcascree = uicontrol('style','radio',...
'position',[245 313 95 20],...
'String','Scree plot',...
'fontsize',8,...
'tooltipstring','Produces a scree plot - look for the elbow.');
H.isoscree = uicontrol('style','radio',...
'position',[230 210 110 27],...
'String','3. View Scree plot',...
'tooltipstring','Produces a scree plot - look for the elbow.');
% Save Handles for THIS GUI in the UserData for this figure.
set(gcf,'userdata',H)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -