-
Notifications
You must be signed in to change notification settings - Fork 0
/
findSubclusters_forHDCCE.m
179 lines (140 loc) · 5.97 KB
/
findSubclusters_forHDCCE.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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
% ========================================================================
% Subcluster Function gpu
% ========================================================================
function Indices = findSubclusters_forHDCCE(Clusters,clusterSize,iCluster,reference_clusterSize)
% Indices = Indices{subCluster_size} = SubclusterIndices_clusterSize
% SubclusterIndices_clusterSize(jCluster,subCluster_size, iCluster) =
% the jth cluster of size subCluster_size that is a subcluster of
% the ith cluster of size clusterSize.
% In a valid cluster, all indices must be natural numbers.
% Initialize Indices assuming that all n choose k subsets are subclusters.
Indices = zeros(NchooseK(reference_clusterSize, ceil(reference_clusterSize/2)),reference_clusterSize);
% Each cluster is a subset of itself.
Indices(1,clusterSize)=iCluster;
% Vector of number of subsets for each subset size.
numberSubClusters = NchooseK(clusterSize,1:clusterSize);
% Check all non-empty subsets have been found.
if clusterSize == 1
return;
end
% Initialize lists of all possible subclusters.
if clusterSize > 2
possibleSubClusters_2 = zeros(numberSubClusters(2),clusterSize);
if clusterSize > 3
possibleSubClusters_3 = zeros(numberSubClusters(3),clusterSize);
if clusterSize > 4
possibleSubClusters_4 = zeros(numberSubClusters(4),clusterSize);
if clusterSize > 5
possibleSubClusters_5 = zeros(numberSubClusters(5),clusterSize);
if clusterSize > 6
possibleSubClusters_6 = zeros(numberSubClusters(5),clusterSize);
if clusterSize > 7
possibleSubClusters_7 = zeros(numberSubClusters(5),clusterSize);
if clusterSize > 8
possibleSubClusters_8 = zeros(numberSubClusters(5),clusterSize);
if clusterSize > 9
possibleSubClusters_9 = zeros(numberSubClusters(5),clusterSize);
if clusterSize > 10
possibleSubClusters_10 = zeros(numberSubClusters(5),clusterSize);
if clusterSize > 11
possibleSubClusters_11 = zeros(numberSubClusters(5),clusterSize);
if clusterSize > 12
error('Cluster size not supported.');
end; end; end; end; end; end; end; end; end; end; end
% Initialize subcluster counters.
subcluster_count = zeros(1,clusterSize);
% Loop over all proper subsets.
for isc = 1:2^(clusterSize)-1
% Get the binary representation of the subset.
subcluster_str = dec2bin(isc);
% Determine the number of filler zeros required.
nZeros = clusterSize - length(subcluster_str);
% Generate str representing the subcluster.
subcluster_str = [repmat('0',1,nZeros) subcluster_str];
% Determine the size of the subcluster.
sc_size = sum(subcluster_str=='1');
% Increment subcluster counter.
subcluster_count(sc_size) = subcluster_count(sc_size) + 1;
% Convert subcluster_str to logical array.
switch sc_size
case 2
possibleSubClusters_2(subcluster_count(sc_size),1:clusterSize) = subcluster_str=='1';
case 3
possibleSubClusters_3(subcluster_count(sc_size),1:clusterSize) = subcluster_str=='1';
case 4
possibleSubClusters_4(subcluster_count(sc_size),1:clusterSize) = subcluster_str=='1';
case 5
possibleSubClusters_5(subcluster_count(sc_size),1:clusterSize) = subcluster_str=='1';
case 6
possibleSubClusters_6(subcluster_count(sc_size),1:clusterSize) = subcluster_str=='1';
case 7
possibleSubClusters_7(subcluster_count(sc_size),1:clusterSize) = subcluster_str=='1';
case 8
possibleSubClusters_8(subcluster_count(sc_size),1:clusterSize) = subcluster_str=='1';
case 9
possibleSubClusters_9(subcluster_count(sc_size),1:clusterSize) = subcluster_str=='1';
case 10
possibleSubClusters_10(subcluster_count(sc_size),1:clusterSize) = subcluster_str=='1';
case 11
possibleSubClusters_11(subcluster_count(sc_size),1:clusterSize) = subcluster_str=='1';
end
end
% Get the ith cluster of size clusterSize from the list of clusters.
Cluster = Clusters(iCluster, 1:clusterSize ,clusterSize);
% Loop through the elements of the cluster.
for ii =1:length(Cluster)
% Get spin ii.
inucleus = Cluster(ii);
% Find the index in Clusters that cooresponds to inucleus
% and store it in Indices.
foundIndices = find(Clusters(:,1,1)'==inucleus);
if ~isempty(foundIndices)
Indices(ii,1) = foundIndices;
end
end
% Check if all subcluster sizes were accounted for.
if clusterSize == 2
return;
end
%--------------------------------------------------------------------------
for isize = 2:clusterSize-1
% Get list of possible subclusters.
switch isize
case 2
possibleSubClusters_ = possibleSubClusters_2;
case 3
possibleSubClusters_ = possibleSubClusters_3;
case 4
possibleSubClusters_ = possibleSubClusters_4;
case 5
possibleSubClusters_ = possibleSubClusters_5;
case 6
possibleSubClusters_ = possibleSubClusters_6;
case 7
possibleSubClusters_ = possibleSubClusters_7;
case 8
possibleSubClusters_ = possibleSubClusters_8;
case 9
possibleSubClusters_ = possibleSubClusters_9;
case 10
possibleSubClusters_ = possibleSubClusters_10;
case 11
possibleSubClusters_ = possibleSubClusters_11;
end
% Loop through all subclusters.
for jCluster = 1:numberSubClusters(isize)
% Get the jth subcluster.
SubCluster = Cluster(possibleSubClusters_(jCluster,:)==1);
% Search for a valid cluster that equals the subcluster.
Search = Clusters(:, 1:isize, isize)==SubCluster;
% Locate where the subcluster is.
subclusterIndex = find( all(Search,2));
% Set invalid subcluster indices to zero.
if isempty(subclusterIndex)
subclusterIndex = 0;
end
% Record the subcluster's index.
Indices(jCluster,isize) = subclusterIndex;
end
end
end