-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsamples.cpp
More file actions
53 lines (48 loc) · 1.23 KB
/
Copy pathsamples.cpp
File metadata and controls
53 lines (48 loc) · 1.23 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
//
// Created by Victor on 5/21/20.
//
#include "samples.h"
#include <vector>
#include <random>
#include <algorithm>
using namespace std;
// shuffled sequence containing integers 0, 1, ..., n-1 each l times
vector<int> gen_seq(int &l, int &n) {
vector<int> seq = vector<int>(l * n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < l; ++j) {
seq.at(i * l + j) = i;
}
}
random_device rd;
mt19937 g(rd());
shuffle(seq.begin(), seq.end(), g);
return seq;
}
// N = 30 random samples | C = choose 6 | n = 13 elements
vector<vector<int> > gen_samples(int N, int C, int n) {
int l = 1 + (int) (N * C) / n;
vector<int> seq = gen_seq(l, n);
vector<int> heads(n, 0);
vector<int> size(n, 0);
int filled = 0;
vector<vector<int> > samps(N + 1, vector<int>());
int c = 0;
for (int x : seq) {
c++;
if (heads[x] < filled) {
heads[x] = filled;
}
// cout << to_string(c) + ' ' + to_string(heads[x]) << endl;
samps[heads[x]].push_back(x);
if (samps[heads[x]].size() == C) {
filled++;
}
if (filled == N) {
break;
}
heads[x]++;
}
samps.pop_back();
return samps;
}