This repository has been archived on 2021-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
NC/mp4/Project_4_Maggioni_Claudio/src/laplacianRcond.m

45 lines
1.3 KiB
Mathematica
Raw Normal View History

2020-11-17 13:12:36 +00:00
clear variables;
close all;
warning OFF;
addpath ../datasets
addpath ../datasets/Meshes
[Pts_spirals,Pts_clusterin,Pts_corn,Pts_halfk,Pts_fullmoon,Pts_out] = getPoints();
close all;
TITLES = ["Two Spirals", "Cluster in cluster", "Corners", "Half crescent", "Full crescent", "Outlier"];
RUNS = {Pts_spirals, Pts_clusterin, Pts_corn, Pts_halfk, Pts_fullmoon, Pts_out};
KS = {2, 2, 4, 2, 2, 4};
B = zeros(100, 6);
for j = 20:70
for i = 1:6
p = (j - 20) / 10;
% Specify the number of clusters
Pts = RUNS{i};
K = KS{i};
n = size(Pts, 1);
% Create Gaussian similarity function
[S] = similarityfunc(Pts(:,1:2), 10^p * log(n));
% Find the minimal spanning tree of the full graph. Use the information
% to determine a valid value for epsilon
H = minSpanTree(S);
epsilon = max(H(H > 0), [], 'all');
% Create the epsilon similarity graph
[G] = epsilonSimGraph(epsilon,Pts);
% Create the adjacency matrix for the epsilon case
W = S .* G;
% Create the Laplacian matrix and implement spectral clustering
[L,Diag] = CreateLapl(W);
B(j, i) = rcond(L);
fprintf("%s - %g: %g\n", TITLES(i), 10^p, B(j,i));
end
end