-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsampling.cpp
More file actions
28 lines (25 loc) · 970 Bytes
/
sampling.cpp
File metadata and controls
28 lines (25 loc) · 970 Bytes
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
#include "sampling.h"
std::vector<int> sample_discrete_gaussian_vector(int n, double s) {
osuCrypto::PRNG prng;
prng.SetSeed(osuCrypto::sysRandomSeed());
std::uniform_int_distribution<int> uniform_dist(ceil(-CUTOFF_MODIFIER * s), floor(CUTOFF_MODIFIER * s));
std::bernoulli_distribution bernoulli_dist;
std::vector<int> sampled_vector(n);
int x, p;
for (int i = 0; i < n; i++) {
do {
x = uniform_dist(prng);
bernoulli_dist = std::bernoulli_distribution(exp(-M_PI * pow(x, 2) / pow(s, 2)));
p = bernoulli_dist(prng);
} while (p == 0);
sampled_vector.at(i) = x;
}
return sampled_vector;
}
std::vector<std::vector<int>> sample_discrete_gaussian_vectors(int k, int n, double s) {
std::vector<std::vector<int>> sampled_vectors(k);
for (int i = 0; i < k; i++) {
sampled_vectors.at(i) = sample_discrete_gaussian_vector(n, s);
}
return sampled_vectors;
}