-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewsgroups_fuzzyART.m
More file actions
111 lines (96 loc) · 3.05 KB
/
Newsgroups_fuzzyART.m
File metadata and controls
111 lines (96 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
%% Clean up
clear variables; close all; fclose all; echo off; clc;
%% Add path
addpath('data', 'FastMICE', 'functions', 'classes');
%% Import Data
[labels, data] = Import_NewsgroupsDataset();
%% ISOMAP
D = squareform(pdist(data, 'euclidean'));
opts = struct();
opts.dims = 20:350;
opts.display = 1;
opts.verbose = 0;
[Y, R, E] = IsoMap(D, 'k', 10, opts);
d = length(Y.coords);
embedding = Y.coords{d}';
%% Linear normalization
data = mapminmax(data', 0, 1)';
embedding = mapminmax(embedding', 0, 1)';
%% Fuzzy ART
rho = 0.30:0.05:0.80;
for r = 1:length(rho)
% ART Parameter settings
settings = struct();
settings.rho = rho(r);
settings.alpha = 1e-3;
settings.beta = 1;
settings.display = 1;
nEpochs = 2;
% Train on raw data
FA = FuzzyART(settings);
tic;
FA = FA.train(data, nEpochs);
runtime(1,r) = toc;
fourScoresRaw(r,:) = computeFourClusteringMetrics(FA.labels, labels);
s = silhouette(data, FA.labels);
s_score(1,r) = mean(s);
% Train on ISOMAP data
FA = FuzzyART(settings);
tic;
FA = FA.train(embedding, nEpochs);
runtime(2,r) = toc;
fourScoresISOMAP(r,:) = computeFourClusteringMetrics(FA.labels, labels);
s = silhouette(data, FA.labels);
s_score(2,r) = mean(s);
end
%% Plot performance metrics
figure;
subplot(2,1,1);
plot(rho,fourScoresRaw);
title('Newsgroups Fuzzy ART Performance (Raw)');
xlabel('rho');
legend('NMI', 'ARI', 'ACC', 'PUR', Location='southeast');
subplot(2,1,2);
plot(rho,fourScoresISOMAP);
title('Newsgroups Fuzzy ART Performance (ISOMAP)');
xlabel('rho');
legend('NMI', 'ARI', 'ACC', 'PUR', Location='southeast');
figure;
subplot(2,1,1);
plot(rho, s_score(1,:));
title('Newsgroups Fuzzy ART Silhouette Score (Raw)');
xlabel('rho');
subplot(2,1,2);
plot(rho, s_score(2,:));
title('Newsgroups Fuzzy ART Silhouette Score (ISOMAP)');
xlabel('rho');
figure;
subplot(2,1,1);
plot(rho, runtime(1,:));
title('Newsgroups Fuzzy ART Runtime (Raw)');
xlabel('rho');
ylabel('Time (s)');
subplot(2,1,2);
plot(rho, runtime(2,:));
title('Newsgroups Fuzzy ART Runtime (ISOMAP)');
xlabel('rho');
ylabel('Time (s)');
%% Display best performance metrics
runIdx = find(rho==input('Select best rho value:'));
disp('--------------------------------------------------------------');
disp('Newsgroups Fuzzy ART (Raw)');
disp(['Rho = ', num2str(rho(runIdx))]);
disp(['Runtime = ', num2str(runtime(1,runIdx)), ' (s)']);
disp(['NMI = ',num2str(fourScoresRaw(runIdx,1))]);
disp(['ARI = ',num2str(fourScoresRaw(runIdx,2))]);
disp(['ACC = ',num2str(fourScoresRaw(runIdx,3))]);
disp(['PUR = ',num2str(fourScoresRaw(runIdx,4))]);
disp('--------------------------------------------------------------');
disp('Newsgroups Fuzzy ART (ISOMAP)');
disp(['Rho = ', num2str(rho(runIdx))]);
disp(['Runtime = ', num2str(runtime(2,runIdx)), ' (s)']);
disp(['NMI = ',num2str(fourScoresISOMAP(runIdx,1))]);
disp(['ARI = ',num2str(fourScoresISOMAP(runIdx,2))]);
disp(['ACC = ',num2str(fourScoresISOMAP(runIdx,3))]);
disp(['PUR = ',num2str(fourScoresISOMAP(runIdx,4))]);
disp('--------------------------------------------------------------');