-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathROG.m
More file actions
36 lines (27 loc) · 1.04 KB
/
ROG.m
File metadata and controls
36 lines (27 loc) · 1.04 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
function groups = ROG(totalDims, groupSize)
% RANDOMGROUPING 将维度随机分成固定大小的组,最后一组包含剩余维度
% groups = RandomGrouping(totalDims, groupSize) 将总维度totalDims随机分组
% 每组大小为groupSize,最后一组包含剩余维度
% 生成所有维度的索引
allDims = 1:totalDims;
% 随机打乱维度顺序
shuffledDims = allDims(randperm(totalDims));
% 计算组数
numFullGroups = floor(totalDims / groupSize);
hasRemainder = mod(totalDims, groupSize) ~= 0;
numGroups = numFullGroups + hasRemainder;
% 初始化输出组
groups = cell(1, numGroups);
% 分配维度到各组
for i = 1:numFullGroups
startIdx = (i-1) * groupSize + 1;
endIdx = i * groupSize;
random_indices = randperm(totalDims, randperm(groupSize,1));
groups{i} = unique([shuffledDims(startIdx:endIdx),random_indices]);
end
% 处理剩余维度(如果有)
if hasRemainder
startIdx = numFullGroups * groupSize + 1;
groups{numGroups} = shuffledDims(startIdx:totalDims);
end
end