-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrepeatkmeans_sps.m
43 lines (23 loc) · 1.08 KB
/
repeatkmeans_sps.m
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
%% this data goes into elbow_sps.m and is used to choose k
clear all; close all;clc
basedir = '/Users/sps253/Documents/energy_landscape'; %%<- your dir here!
cd(basedir);
%% load data
split = 'main' %%<- options: main, gsr, sch, music, psilo
load(fullfile(['data/',split,'.mat']))
savedir = fullfile(basedir,'repkmeans');
mkdir(savedir); cd(savedir);
%% set inputs
nreps = 50; % how many times to repeat clustering. will choose lowest error solution
distanceMethod = 'correlation';
maxI = 1000; % how many times you allow kmeans to try to converge
maxk = round(sqrt(TR)) -1; %k^2 must be less than TR to capture all transitions
for numClusters = 2:maxk %because we have 220 frames, k^2 must be less than 220 to capture all transitions
disp(['K = ',num2str(numClusters)]);
disp('start k-means');
[partition,~,sumd] = kmeans(concTS,numClusters,'Distance',distanceMethod,'Replicates',nreps,'MaxIter',maxI);
save(fullfile(savedir,['kmeans',split,'k_',num2str(numClusters),'.mat']),'partition','sumd')
clear partition
clear sumd
end
disp('complete');