📄 mani.m
字号:
function varargout = mani(varargin)
% mani: MANIfold learning demonstration GUI
% by Todd Wittman, Department of Mathematics, University of Minnesota
% E-mail wittman@math.umn.edu with comments & questions.
% MANI Website: http://www.math.umn.edu/~wittman/mani/index.html
% Last Modified by GUIDE v2.5 10-Apr-2005 13:28:36%
% Methods obtained from various authors.
% MDS -- Michael Lee
% ISOMAP -- J. Tenenbaum, de Silva, & Langford
% LLE -- Sam Roweis & Lawrence Saul
% Hessian LLE -- D. Donoho & C. Grimes
% Laplacian -- M. Belkin & P. Niyogi
% Diffusion Map -- R. Coifman & S. Lafon
% LTSA -- Zhenyue Zhang & Hongyuan Zha
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @mani_OpeningFcn, ...
'gui_OutputFcn', @mani_OutputFcn, ...
'gui_LayoutFcn', @mani_LayoutFcn, ... 'gui_Callback', []);
if nargin & isstr(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before mani is made visible.
function mani_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
axes(handles.maniAXES);
axis off;
axes(handles.embedAXES);
axis off;
handles.X = 0;
handles.ColorVector = 0;
handles.Y = 0;
handles.isExample = 0;
handles.K = 12;
handles.d = 2;
handles.sigma = 1.45;
handles.runTime = 0;
handles.alpha = 0;
guidata(hObject, handles);
warning off;
% --- Outputs from this function are returned to the command line.
function varargout = mani_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function MatrixEdit_CreateFcn(hObject, eventdata, handles)% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction MatrixEdit_Callback(hObject, eventdata, handles)% Hints: get(hObject,'String') returns contents of MatrixEdit as text% str2double(get(hObject,'String')) returns contents of MatrixEdit as a doublefunction FileEdit_CreateFcn(hObject, eventdata, handles)% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction FileEdit_Callback(hObject, eventdata, handles)% Hints: get(hObject,'String') returns contents of FileEdit as text% str2double(get(hObject,'String')) returns contents of FileEdit as a double% --- Executes on button press in LoadMatrix.function LoadMatrix_Callback(hObject, eventdata, handles)handles.X = evalin ('base', get(handles.MatrixEdit,'String'));
handles.isExample = 0;
guidata(hObject, handles);
PlotManifold(hObject,eventdata,handles,0);
updateString{1} = ['Matrix ',get(handles.MatrixEdit,'String'),' loaded.'];
set(handles.UpdatesText,'String',updateString);
guidata(hObject, handles);
% --- Executes on button press in LoadFile.function LoadFile_Callback(hObject, eventdata, handles)
Xtemp = dlmread(get(handles.FileEdit,'String'),' ');
[m,n] = size(Xtemp);
% Check if last column is all zeros. Reading error.
if max(abs(Xtemp(:,n))) == 0
Xtemp = Xtemp(1:m,1:n-1);
end;
handles.X = Xtemp;
handles.isExample = 0;
guidata(hObject, handles);
PlotManifold(hObject,eventdata,handles,0);
updateString{1} = ['File ',get(handles.FileEdit,'String'),' loaded.'];
set(handles.UpdatesText,'String',updateString);
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.function ExampleMenu_CreateFcn(hObject, eventdata, handles)% Hint: popupmenu controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end% --- Executes on selection change in ExampleMenu.function ExampleMenu_Callback(hObject, eventdata, handles)% Hints: contents = get(hObject,'String') returns ExampleMenu contents as cell array% contents{get(hObject,'Value')} returns selected item from ExampleMenu
exampleValue = get(handles.ExampleMenu,'Value');
switch exampleValue
case 1 % Swiss Roll
set(handles.text19,'String','Z Scaling =');
set(handles.ParamEdit,'String','1.0');
case 2 % Swiss Hole
set(handles.text19,'String','Z Scaling =');
set(handles.ParamEdit,'String','1.0');
case 3 % Corner Planes
set(handles.text19,'String','Lift Angle =');
set(handles.ParamEdit,'String','45.0');
case 4 % Punctured Sphere
set(handles.text19,'String','Z Scaling =');
set(handles.ParamEdit,'String','1.0');
case 5 % Twin Peaks
set(handles.text19,'String','Z Scaling =');
set(handles.ParamEdit,'String','1.0');
case 6 % 3D Clusters
set(handles.text19,'String','# Clusters =');
set(handles.ParamEdit,'String','3');
case 7 % Toroidal Helix
set(handles.text19,'String','Sample Rate =');
set(handles.ParamEdit,'String','1.0');
case 8 % Gaussian
set(handles.text19,'String','Sigma =');
set(handles.ParamEdit,'String','1.0');
case 9 % Occluded Disks
set(handles.text19,'String','Occluder r =');
set(handles.ParamEdit,'String','1.0');
end;
guidata(hObject,handles);% --- Executes during object creation, after setting all properties.function DimEdit_CreateFcn(hObject, eventdata, handles)% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction DimEdit_Callback(hObject, eventdata, handles)% Hints: get(hObject,'String') returns contents of DimEdit as text% str2double(get(hObject,'String')) returns contents of DimEdit as a double% --- Executes during object creation, after setting all properties.function KEdit_CreateFcn(hObject, eventdata, handles)% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction KEdit_Callback(hObject, eventdata, handles)% Hints: get(hObject,'String') returns contents of KEdit as text% str2double(get(hObject,'String')) returns contents of KEdit as a double% --- Executes during object creation, after setting all properties.function REdit_CreateFcn(hObject, eventdata, handles)% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end% --- Executes during object creation, after setting all properties.function SigmaEdit_CreateFcn(hObject, eventdata, handles)% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction SigmaEdit_Callback(hObject, eventdata, handles)% Hints: get(hObject,'String') returns contents of SigmaEdit as text% str2double(get(hObject,'String')) returns contents of SigmaEdit as a double% --- Executes on button press in PCAButton.function PCAButton_Callback(hObject, eventdata, handles)
handles.d = round(str2double(get(handles.DimEdit,'String')));
handles.d = max(1,handles.d);
updateString{1} = 'Running PCA.';
set(handles.UpdatesText,'String',updateString);
tic;
handles.Y = pca(handles.X,handles.d);
runTime = toc;
guidata(hObject, handles);
PlotEmbedding(hObject,eventdata,handles,0);
assignin ('base','maniY',handles.Y);
updateString{2} = ['PCA complete: ',num2str(runTime),'s'];
updateString{3} = 'Embedding data written to matrix "maniY"';
set(handles.UpdatesText,'String',updateString);% --- Executes on button press in LLEButton.function LLEButton_Callback(hObject, eventdata, handles)
handles.K = round(str2double(get(handles.KEdit,'String')));
handles.K = max(1,handles.K);
handles.d = round(str2double(get(handles.DimEdit,'String')));
handles.d = max(1,handles.d);
updateString{1} = 'Running LLE.';
set(handles.UpdatesText,'String',updateString);
tic;handles.Y = lle(handles.X',handles.K,handles.d)';
runTime = toc;guidata(hObject, handles);
PlotEmbedding(hObject,eventdata,handles,0);
assignin ('base','maniY',handles.Y);
updateString{2} = ['LLE complete: ',num2str(runTime),'s'];
updateString{3} = 'Embedding data written to matrix "maniY"';
set(handles.UpdatesText,'String',updateString);
% --- Executes on button press in MDSButton.function MDSButton_Callback(hObject, eventdata, handles)
handles.d = round(str2double(get(handles.DimEdit,'String')));
handles.d = max(1,handles.d);
updateString{1} = 'Running MDS.';
set(handles.UpdatesText,'String',updateString);
tic;
D = L2_distance(handles.X',handles.X',1);
handles.Y = mdsFast(D, handles.d);
runTime = toc;
guidata(hObject, handles);
PlotEmbedding(hObject,eventdata,handles,0);assignin ('base','maniY',handles.Y);
updateString{2} = ['MDS complete: ',num2str(runTime),'s'];
updateString{3} = 'Embedding data written to matrix "maniY"';
set(handles.UpdatesText,'String',updateString);
% --- Executes on button press in LaplacianButton.function LaplacianButton_Callback(hObject, eventdata, handles)
handles.K = round(str2double(get(handles.KEdit,'String')));
handles.K = max(1,handles.K);
handles.d = round(str2double(get(handles.DimEdit,'String')));
updateString{1} = 'Running Laplacian Eigenmap.';
set(handles.UpdatesText,'String',updateString);
tic;
[E,V] = leigs(handles.X, 'nn', handles.K, handles.d+1);
handles.Y = E(:,1:handles.d);
runTime = toc;guidata(hObject, handles);
PlotEmbedding(hObject,eventdata,handles,0);
assignin ('base','maniY',handles.Y);
updateString{2} = ['Laplacian complete: ',num2str(runTime),'s'];
updateString{3} = 'Embedding data written to matrix "maniY"';
set(handles.UpdatesText,'String',updateString);% --- Executes on button press in ISOMAPButton.function ISOMAPButton_Callback(hObject, eventdata, handles)handles.K = round(str2double(get(handles.KEdit,'String')));
handles.K = max(1,handles.K);
handles.d = round(str2double(get(handles.DimEdit,'String')));
handles.d = max(1,handles.d);
options.dims = handles.d;
updateString{1} = 'Running ISOMAP.';
set(handles.UpdatesText,'String',updateString);
tic;
D = L2_distance(handles.X',handles.X',1);
[Y, R] = Isomap(D, handles.K, options);
runTime = toc;
handles.Y = Y.coords{1}';
guidata(hObject, handles);
PlotEmbedding(hObject,eventdata,handles,0);
assignin ('base','maniY',handles.Y);
updateString{2} = ['ISOMAP complete: ',num2str(runTime),'s'];
updateString{3} = 'Embedding data written to matrix "maniY"';
set(handles.UpdatesText,'String',updateString);% --- Executes on button press in HessianButton.function HessianButton_Callback(hObject, eventdata, handles)
handles.K = round(str2double(get(handles.KEdit,'String')));
handles.K = max(1,handles.K);
handles.d = round(str2double(get(handles.DimEdit,'String')));
handles.d = max(1,handles.d);
updateString{1} = 'Running Hessian LLE.';
set(handles.UpdatesText,'String',updateString);
tic;
[Y, mse] = HLLE(handles.X',handles.K,handles.d);
handles.Y = Y';
runTime = toc;
guidata(hObject, handles);
PlotEmbedding(hObject,eventdata,handles,0);
assignin ('base','maniY',handles.Y);
updateString{2} = ['Hessian LLE complete: ',num2str(runTime),'s'];
updateString{3} = 'Embedding data written to matrix "maniY"';
set(handles.UpdatesText,'String',updateString);% --- Executes during object creation, after setting all properties.function ColorEdit_CreateFcn(hObject, eventdata, handles)% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction ColorEdit_Callback(hObject, eventdata, handles)% Hints: get(hObject,'String') returns contents of ColorEdit as text% str2double(get(hObject,'String')) returns contents of ColorEdit as a double% --- Executes on button press in ColorCheck.function ColorCheck_Callback(hObject, eventdata, handles)% Hint: get(hObject,'Value') returns toggle state of ColorCheck% --- Executes during object creation, after setting all properties.function PointsEdit_CreateFcn(hObject, eventdata, handles)% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction PointsEdit_Callback(hObject, eventdata, handles)% Hints: get(hObject,'String') returns contents of PointsEdit as text% str2double(get(hObject,'String')) returns contents of PointsEdit as a double% --- Executes on button press in RunAllButton.function RunAllButton_Callback(hObject, eventdata, handles)handles.K = round(str2double(get(handles.KEdit,'String')));
handles.K = max(1,handles.K);
handles.d = round(str2double(get(handles.DimEdit,'String')));
handles.d = max(1,handles.d);
handles.sigma = str2double(get(handles.SigmaEdit,'String'));
handles.sigma = max(100*eps,abs(handles.sigma));
handles.alpha = str2double(get(handles.AlphaEdit,'String'));
handles.alpha = abs(handles.alpha);
PlotManifold(hObject,eventdata,handles,1);
% Run MDS.
try
tic;
D = L2_distance(handles.X',handles.X',1);
handles.Y = mdsFast(D, handles.d);
handles.runTime = toc;
guidata(hObject, handles);
PlotEmbedding(hObject,eventdata,handles,1);
end;
% Run PCA.
try
tic;
handles.Y = pca(handles.X,handles.d);
handles.runTime = toc;
guidata(hObject, handles);
PlotEmbedding(hObject,eventdata,handles,2);
end;
% Run ISOMAP. Uses same D as above.
try
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -