⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demosimilaritygraphs.m

📁 一个Matlab写的关于图理论以及其在机器学习中应用的教学用GUI软件
💻 M
📖 第 1 页 / 共 3 页
字号:
drawnow%disp('start DrawData 1')% draw data set and plot it: switch GD_Global.CurrentDataSet;   case 1 % Two Moons with balanced classes [0.5,0.5]  density = 2;  [pointstrans,labelstrans] =GD_GenerateData(density,...                                                   GD_Global.CurrentNumPoints,...                                                   GD_Global.CurrentDataDim , ...                                                   [0.5,0.5],...                                                   GD_Global.CurrentVarNoise);   case 2 % Two Moons with unbalanced classes [0.2,0.8]  density=2;    [pointstrans,labelstrans] =GD_GenerateData(density,...                                                   GD_Global.CurrentNumPoints,...                                                   GD_Global.CurrentDataDim , ...                                                   [0.2,0.8],...                                                   GD_Global.CurrentVarNoise);       case 3 % Two isotropic Gaussians balanced classes [0.5,0.5]  density=3;  [pointstrans,labelstrans] =GD_GenerateData(density,...                                                   GD_Global.CurrentNumPoints,...                                                   GD_Global.CurrentDataDim , ...                                                   [0.5,0.5,0],...                                                   GD_Global.CurrentVarNoise);   case 4 % Two isotropic Gaussians unbalanced classe [0.2,0.8]  density=3;  [pointstrans,labelstrans] =GD_GenerateData(density,...                                                   GD_Global.CurrentNumPoints,...                                                   GD_Global.CurrentDataDim , ...                                                   [0.2,0.8,0],...                                                   GD_Global.CurrentVarNoise); case 5 % Two isotropic Gaussians with different variance and balanced classes [0.2,0.8]  density=4;    [pointstrans,labelstrans] =GD_GenerateData(density,...                                                   GD_Global.CurrentNumPoints,...                                                   GD_Global.CurrentDataDim , ...                                                   [0.2,0.8,0],...                                                   GD_Global.CurrentVarNoise);   case 6 % Three isotropic Gaussians almost balanced [0.3,0.3,0.4]  density=3;      [pointstrans,labelstrans] =GD_GenerateData(density,...                                                   GD_Global.CurrentNumPoints,...                                                   GD_Global.CurrentDataDim , ...                                                   [0.3,0.3,0.4],...                                                   GD_Global.CurrentVarNoise);  endGD_Global.points = pointstrans';% set current axis to plot in: set(gcf, 'CurrentAxes',handles.axes_data_left); % now plot it: GD_PlotLabels(GD_Global.points(:,1:2), ones(size(GD_Global.points(:,1))), 'Data set (relvant dimensions)');axis equal% ------------------------------------------------------------function ComputeSimilarityAndPlot(handles)% ------------------------------------------------------------global GD_Global; %disp('start compute sim')% compute similarity matrix: GD_Global.D = DistEuclideanPiotrDollar( GD_Global.points, GD_Global.points ); % GD_ComputeDistanceMatrix(GD_Global.points,2);GD_Global.S = exp(- GD_Global.D / (2 * GD_Global.CurrentSigma^2)); %compute_gaussian_kernel_matrix(GD_Global.points,GD_Global.points,GD_Global.CurrentSigma);% plot similarity heat map: set(gcf, 'CurrentAxes',handles.axes_data_middle); claimagesc(GD_Global.S)title('Heat map of similarity values')colorbar('Xtick',[1,60], 'XtickLabels',[0,1], 'FontSize', 10)% plot similarity histogramset(gcf, 'CurrentAxes',handles.axes_data_right); clahist(GD_Global.S(:))title('Histogram of the similarity values')% set max epsilon to max distance: GD_Global.MaxEps = max(max(GD_Global.D)); % if one of the current graphs is an eps graph, assign good para to it: if (GD_Global.CurrentGraph1 == 1 || GD_Global.CurrentGraph1 == 4)  GD_Global.CurrentGraphPara1 = SelectGoodEps(handles);endif (GD_Global.CurrentGraph2 == 1 || GD_Global.CurrentGraph2 == 4)    GD_Global.CurrentGraphPara2 = SelectGoodEps(handles);end% need to initialize sliders again afterwards: InitializeSliders(handles);% ------------------------------------------------------------function ComputeGraphAndPlot(handles, whichone)% ------------------------------------------------------------global GD_Global; %disp('start comptue graph')if (whichone==1)  type = GD_Global.CurrentGraph1;  currentPara = GD_Global.CurrentGraphPara1;  cla(handles.axes_graph1_left)  cla(handles.axes_graph1_middle)  cla(handles.axes_graph1_right)  cla(handles.axes_graph1_rr)  drawnow  else  type = GD_Global.CurrentGraph2;  currentPara = GD_Global.CurrentGraphPara2;  cla(handles.axes_graph2_left)  cla(handles.axes_graph2_middle)  cla(handles.axes_graph2_right)  cla(handles.axes_graph2_rr)  drawnowend% compute adjacency matrix of graph: switch type;  case 1 %weighted eps graph%  W = build_epsilon_graph(GD_Global.S, currentPara,'sim');  Wunweighted = GD_BuildEpsilonGraph(GD_Global.D, currentPara, 'dist');   W = Wunweighted .* GD_Global.S;  case 2 %symm knn   W = GD_BuildSymmetricKnnGraph(GD_Global.S, ceil(currentPara),'sim'); case 3 % mut knn  W = GD_BuildMutualKnnGraph(GD_Global.S, ceil(currentPara),'sim'); case 4 % unweithed eps graph  W = GD_BuildEpsilonGraph(GD_Global.D, currentPara, 'dist'); endif (whichone ==1 )  GD_Global.W1 = W;  else  GD_Global.W2 = W;end% plot it graph itself: if (whichone==1)  set(gcf, 'CurrentAxes',handles.axes_graph1_left); cla else  set(gcf, 'CurrentAxes',handles.axes_graph2_left); cla endclaGD_PlotGraph(GD_Global.points(:,1:2), W, 'Connectivity')axis equal% plot the degrees of the graph nodes: if (whichone==1)  set(gcf, 'CurrentAxes',handles.axes_graph1_middle); cla else  set(gcf, 'CurrentAxes',handles.axes_graph2_middle); cla endclad = sum(W,2); GD_PlotFunction(gca, GD_Global.points(:,1:2),d,'Degrees of the vertices')%colorbar('Location','EastOutside')axis equal% % plot the degrees statitics: % if (whichone==1)%   set(gcf, 'CurrentAxes',handles.axes_graph1_right); cla % else%   set(gcf, 'CurrentAxes',handles.axes_graph2_right); cla % end% cla% hist(d); % title('Histogram of degrees')% plot the adjacency heat map: if (whichone==1)  set(gcf, 'CurrentAxes',handles.axes_graph1_right); claimagesc(GD_Global.W1); else  set(gcf, 'CurrentAxes',handles.axes_graph2_right); cla   imagesc(GD_Global.W2); endtitle('Adjacency matrix')% plot statistics on connected components: %[num_components, index_components] = connected_components_ule(W); index_components = GD_GetComps(W); num_components = max(index_components);size_components = zeros(max([num_components,5]),1);for it=1:num_components  size_components(it) = length(find(index_components==it));endsize_components = sort(size_components,'descend');if (whichone==1)  set(gcf, 'CurrentAxes',handles.axes_graph1_rr); cla else  set(gcf, 'CurrentAxes',handles.axes_graph2_rr); cla endclabar(size_components)title('Points per conn. comp.')%ylabel('Points per component')%xlabel('Index of the component')% ------------------------------------------------------------function goodeps = SelectGoodEps(handles)% ------------------------------------------------------------% set current value of current eps to something useful in the beginning:global GD_Global; if (isempty(GD_Global.S))  goodeps = GD_Global.DefaultEps; else     % try to select reasonable eps according to bold rule of thumb  % mean of distance of k-th nearest neighbor:     k = 7;   Ssorted = sort(GD_Global.S,2,'descend');  Sk = Ssorted(:,k+1); %attention, start to count at second col, first is always 1  epsilon = mean(Sk);   Dsorted = sort(GD_Global.D,2,'ascend');  Dk = Dsorted(:,k+1); %attention, start to count at second col, first is always 1  epsilon = mean(Dk);   % but need to make sure it is ine the correct range:   if (GD_Global.MinEps <= epsilon && GD_Global.MaxEps >= epsilon)    goodeps = epsilon;   else    disp(sprintf('goodeps would be %f, which is not in the range',epsilon))  goodeps = GD_Global.DefaultEps;   endend% ------------------------------------------------------------function goodeps = SelectGoodSigma(handles)% ------------------------------------------------------------% set current value of current eps to something useful in the beginning:global GD_Global; if (isempty(GD_Global.D))  goodsigma = GD_Global.DefaultSigma; else     % try to select reasonable eps according to bold rule of thumb  % mean of similarity of k-th nearest neighbor:     k = 7;   Dsorted = sort(GD_Global.D,2,'ascend');  Dk = Dsorted(:,k+1); %attention, start to count at second col, first is always 1  sigma = mean(Dk);   % but need to make sure it is ine the correct range:   if (GD_Global.MinSigma <= sigma && GD_Global.MaxSigma >= sigma)    goodsigma = sigma;   else    disp(sprintf('goodsigma would be %f, which is not in the range',sigma))    goodsigma = GD_Global.DefaultSigma;   endend  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -