📄 demossl.m
字号:
%ALLDATA_SSL.x = [xtrain', xtest'];
%ALLDATA_SSL.y = [ytrain; ytest];
ALLDATA_SSL.x = [xtest'];
ALLDATA_SSL.y = [ytest+1];
ALLDATA_SSL.Num = length(ALLDATA_SSL.y);
cla(handles.axes2);
cla(handles.axes3);
cla(handles.axes4);
end
% update slider for labeled data
set(handles.SldNumLabels,'SliderStep',[1/ALLDATA_SSL.MaxLabels,10/ALLDATA_SSL.MaxLabels]);
ALLDATA_SSL.Labeled = randperm(ALLDATA_SSL.Num);
ALLDATA_SSL.Labeled = ALLDATA_SSL.Labeled(1:ALLDATA_SSL.NumLabels);
UpdateALL(handles);
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% 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
%set(hObject, 'String', {'plot(rand(5))', 'plot(sin(1:0.01:25))', 'bar(1:.5:10)', 'plot(membrane)', 'surf(peaks)'});
x=0;
% --- Executes on slider movement.
function SldNumNeighbors_Callback(hObject, eventdata, handles)
% hObject handle to SldNumNeighbors (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global ALLDATA_SSL;
value = get(hObject,'Value');
if(ALLDATA_SSL.GraphType<2)
ALLDATA_SSL.NumKNN = floor(value*(ALLDATA_SSL.MaxKNN-ALLDATA_SSL.MinKNN) + ALLDATA_SSL.MinKNN);
set(handles.TxtNumNeighbors,'String',num2str(ALLDATA_SSL.NumKNN));
else
ALLDATA_SSL.Eps = value*(ALLDATA_SSL.MaxEps-ALLDATA_SSL.MinEps) + ALLDATA_SSL.MinEps;
set(handles.TxtNumNeighbors,'String',num2str(ALLDATA_SSL.Eps,'%2.2f'));
end
%UpdateALL(handles);
% --- Executes during object creation, after setting all properties.
function SldNumNeighbors_CreateFcn(hObject, eventdata, handles)
% hObject handle to SldNumNeighbors (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function SldDim_Callback(hObject, eventdata, handles)
% hObject handle to SldDim (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of
% slider
global ALLDATA_SSL;
value = get(hObject,'Value');
ALLDATA_SSL.Dim = floor(value*(ALLDATA_SSL.MaxDim-ALLDATA_SSL.MinDim) + ALLDATA_SSL.MinDim);
set(handles.TxtDim,'String',num2str(ALLDATA_SSL.Dim));
popup_sel_index = get(handles.popupmenu1, 'Value');
switch popup_sel_index
case 1 % Two Moons with balanced classes [0.5,0.5]
ALLDATA_SSL.Density=2;
% generate data
ALLDATA_SSL.Num=500;
[ALLDATA_SSL.x,ALLDATA_SSL.y]=GD_GenerateData(ALLDATA_SSL.Density,ALLDATA_SSL.Num,ALLDATA_SSL.Dim,[0.5,0.5],0.01);
case 2 % Two Moons with unbalanced classes [0.2,0.8]
ALLDATA_SSL.Density=2;
% generate data
ALLDATA_SSL.Num=500;
[ALLDATA_SSL.x,ALLDATA_SSL.y]=GD_GenerateData(ALLDATA_SSL.Density,ALLDATA_SSL.Num,ALLDATA_SSL.Dim,[0.2,0.8],0.01);
case 3 % Two isotropic Gaussians balanced classes [0.5,0.5]
ALLDATA_SSL.Density=3;
% generate data
ALLDATA_SSL.Num=500;
[ALLDATA_SSL.x,ALLDATA_SSL.y]=GD_GenerateData(ALLDATA_SSL.Density,ALLDATA_SSL.Num,ALLDATA_SSL.Dim,[0.5,0.5,0],0.01);
case 4 % Two isotropic Gaussians unbalanced classes [0.2,0.8]
ALLDATA_SSL.Density=3;
% generate data
ALLDATA_SSL.Num=500;
[ALLDATA_SSL.x,ALLDATA_SSL.y]=GD_GenerateData(ALLDATA_SSL.Density,ALLDATA_SSL.Num,ALLDATA_SSL.Dim,[0.2,0.8,0],0.01);
case 5 % Two isotropic Gaussians with different variance and balanced classes [0.2,0.8]
ALLDATA_SSL.Density=4;
% generate data
ALLDATA_SSL.Num=500;
[ALLDATA_SSL.x,ALLDATA_SSL.y]=GD_GenerateData(ALLDATA_SSL.Density,ALLDATA_SSL.Num,ALLDATA_SSL.Dim,[0.5,0.5,0],0.01);
case 6 % two isotropic Gaussians where the decision boundary goes through the middle of the Gaussians
ALLDATA_SSL.Density=5;
ALLDATA_SSL.Num=500;
[ALLDATA_SSL.x,ALLDATA_SSL.y]=GD_GenerateData(ALLDATA_SSL.Density,ALLDATA_SSL.Num,ALLDATA_SSL.Dim,[0.5,0.5,0],0.01);
case 7 % Three isotropic Gaussians almost balanced [0.3,0.3,0.4]
ALLDATA_SSL.Density=3;
% generate data
ALLDATA_SSL.Num=500;
[ALLDATA_SSL.x,ALLDATA_SSL.y]=GD_GenerateData(ALLDATA_SSL.Density,ALLDATA_SSL.Num,ALLDATA_SSL.Dim,[0.3,0.3,0.4],0.01);
case 8
display('WARNING: Dimension of USPS is fixed !');
end
%UpdateALL(handles);
% --- Executes during object creation, after setting all properties.
function SldDim_CreateFcn(hObject, eventdata, handles)
% hObject handle to SldDim (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
x=0;
% --- Executes on slider movement.
function SldNumLabels_Callback(hObject, eventdata, handles)
% hObject handle to SldNumLabels (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global ALLDATA_SSL;
value = get(hObject,'Value');
ALLDATA_SSL.NumLabels = floor(value*(ALLDATA_SSL.MaxLabels-ALLDATA_SSL.MinLabels) + ALLDATA_SSL.MinLabels);
set(handles.TxtNumLabels,'String',num2str(ALLDATA_SSL.NumLabels));
% initialize labeled data
ALLDATA_SSL.Labeled = randperm(ALLDATA_SSL.Num);
ALLDATA_SSL.Labeled = ALLDATA_SSL.Labeled(1:ALLDATA_SSL.NumLabels);
%UpdateALL(handles);
% --- Executes during object creation, after setting all properties.
function SldNumLabels_CreateFcn(hObject, eventdata, handles)
% hObject handle to SldNumLabels (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
x=0;
% --- Executes on selection change in PopGraphType.
function PopGraphType_Callback(hObject, eventdata, handles)
% hObject handle to PopGraphType (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns PopGraphType contents as cell array
% contents{get(hObject,'Value')} returns selected item from PopGraphType
global ALLDATA_SSL;
value = get(hObject,'Value');
switch value
case 1, ALLDATA_SSL.GraphType = 1; set(handles.TxtNeighborhood,'String','Number of Neighbors');
value = (ALLDATA_SSL.NumKNN - ALLDATA_SSL.MinKNN)/(ALLDATA_SSL.MaxKNN - ALLDATA_SSL.MinKNN);
set(handles.SldNumNeighbors,'Value',value);
set(handles.TxtNumNeighbors,'String',num2str(ALLDATA_SSL.NumKNN,'%d'));
case 2, ALLDATA_SSL.GraphType = 0; set(handles.TxtNeighborhood,'String','Number of Neighbors');
value = (ALLDATA_SSL.NumKNN - ALLDATA_SSL.MinKNN)/(ALLDATA_SSL.MaxKNN - ALLDATA_SSL.MinKNN);
set(handles.SldNumNeighbors,'Value',value);
set(handles.TxtNumNeighbors,'String',num2str(ALLDATA_SSL.NumKNN,'%d'));
case 3, if(ALLDATA_SSL.Density~=6) ALLDATA_SSL.GraphType = 2; set(handles.TxtNeighborhood,'String','Epsilon Parameter');
value = (ALLDATA_SSL.Eps - ALLDATA_SSL.MinEps)/(ALLDATA_SSL.MaxEps - ALLDATA_SSL.MinEps);
set(handles.SldNumNeighbors,'Value',value);
set(handles.TxtNumNeighbors,'String',num2str(ALLDATA_SSL.Eps,'%2.2f'));
else
if(ALLDATA_SSL.GraphType==1)
set(handles.PopGraphType,'Value',1);
end
if(ALLDATA_SSL.GraphType==0)
set(handles.PopGraphType,'Value',2);
end
end
end
%UpdateALL(handles);
% --- Executes during object creation, after setting all properties.
function PopGraphType_CreateFcn(hObject, eventdata, handles)
% hObject handle to PopGraphType (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on slider movement.
function SldRegul_Callback(hObject, eventdata, handles)
% hObject handle to SldRegul (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global SSLDATA;
value = get(hObject,'Value');
value = (log10(SSLDATA.MaxRegul)-log10(SSLDATA.MinRegul))*value + log10(SSLDATA.MinRegul);
SSLDATA.Regul = 10^value;
set(handles.TxtRegul,'String',num2str(SSLDATA.Regul,'%2.2e'));
%UpdateALL(handles);
% --- Executes during object creation, after setting all properties.
function SldRegul_CreateFcn(hObject, eventdata, handles)
% hObject handle to SldRegul (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function SldWeights_Callback(hObject, eventdata, handles)
% hObject handle to SldWeights (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global ALLDATA_SSL;
value = get(hObject,'Value');
ALLDATA_SSL.Gamma = value*(ALLDATA_SSL.MaxGamma-ALLDATA_SSL.MinGamma) + ALLDATA_SSL.MinGamma;
set(handles.TxtWeights,'String',num2str(ALLDATA_SSL.Gamma,'%2.1f'));
%UpdateALL(handles);
% --- Executes during object creation, after setting all properties.
function SldWeights_CreateFcn(hObject, eventdata, handles)
% hObject handle to SldWeights (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -