-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariate.cpp
More file actions
47 lines (43 loc) · 1.77 KB
/
Copy pathvariate.cpp
File metadata and controls
47 lines (43 loc) · 1.77 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
#include "variate.h"
#include "colormod.h"
std::vector<Profile> Variate::gaussian(Profile profile,
const std::function<double(unsigned int)> stddevOnIndex,
unsigned int times) {
clock_t start = clock();
std::vector<Profile> res(times);
std::random_device rd{};
std::mt19937 gen{rd()};
int j = 0;
for (unsigned int i = 0; i < profile.size(); i++) {
std::normal_distribution<double> d(profile[i], stddevOnIndex(i));
for (unsigned int k = 0; k < times; k++) {
double val = d(gen);
if (val > 0) res[k].push_back(val);
else {
res[k].push_back(profile[i]);
j++;
}
}
}
clock_t end = clock();
double seconds = double(end - start) / CLOCKS_PER_SEC;
Color::Modifier green(Color::FG_GREEN);
Color::Modifier red(Color::FG_RED);
Color::Modifier def(Color::FG_DEFAULT);
std::cout << green << "Variate::gaussian\t-\t" << seconds << " sec." << def << std::endl;
if (j)
std::cout << red << j/double(times) << "*" << times
<< " values less than zero (replaced with values of the original profile)." << def << std::endl;
return res;
}
Profile Variate::gaussian(Profile profile, const std::function<double(unsigned int)> stddevOnIndex) {
return Variate::gaussian(profile, stddevOnIndex, 1)[0];
}
std::vector<Profile> Variate::gaussian(Profile profile, double stddev, unsigned int times) {
return Variate::gaussian(profile,
[&stddev](unsigned int i){ return i*0.+stddev; },
times);
}
Profile Variate::gaussian(Profile profile, double stddev) {
return Variate::gaussian(profile, stddev, 1)[0];
}