-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector_entry.cpp
56 lines (48 loc) · 1.31 KB
/
vector_entry.cpp
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
#include <math.h>
#include <random>
#include "vector_entry.h"
VectorEntry::VectorEntry() :
vec(),
is_true()
{
}
VectorEntry::VectorEntry(boost::numeric::ublas::vector<double> vector_, bool is_true_) :
vec(vector_),
is_true(is_true_)
{
}
VectorEntry::VectorEntry(const boost::numeric::ublas::vector<double>& min,
const boost::numeric::ublas::vector<double>& max,
Shape shape, bool is_true_) :
vec(min.size()),
is_true(is_true_)
{
using namespace boost::numeric::ublas;
switch (shape) {
default:
case SHAPE_CUBE: {
for (int i = vec.size()-1; i >= 0; --i) {
vec[i] = (double)rand() / RAND_MAX * (max[i] - min[i]) + min[i];
}
} break;
case SHAPE_ORTHOPLEX: {
double sum = 1;
for (int i = vec.size()-1; i >= 0; --i) {
vec[i] = (1 - pow((double)rand() / RAND_MAX, 1/(i+1)))*sum;
sum -= vec[i];
if (rand() % 2) {
vec[i] = -vec[i];
}
vec[i] = ((max[i] - min[i])*vec[i] + (max[i] + min[i]))/2;
}
} break;
case SHAPE_SIMPLEX: {
double sum = 1;
for (int i = vec.size()-1; i >= 0; --i) {
vec[i] = (1 - pow((double)rand() / RAND_MAX, 1/(i+1)))*sum;
sum -= vec[i];
vec[i] = (max[i] - min[i])*vec[i]/2;
}
} break;
}
}