-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathBootstrapGenerator.cpp
More file actions
68 lines (50 loc) · 1.47 KB
/
BootstrapGenerator.cpp
File metadata and controls
68 lines (50 loc) · 1.47 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "BootstrapGenerator.hpp"
BootstrapGenerator::BootstrapGenerator ()
{
// TODO Auto-generated constructor stub
}
BootstrapGenerator::~BootstrapGenerator ()
{
// TODO Auto-generated destructor stub
}
BootstrapReplicate BootstrapGenerator::generate(const PartitionedMSA& parted_msa,
unsigned long random_seed)
{
BootstrapReplicate result;
RandomGenerator gen(random_seed);
for (const auto& pinfo: parted_msa.part_list())
result.site_weights.emplace_back(generate(pinfo.msa(), gen));
return result;
}
FloatWeightVector BootstrapGenerator::generate(const MSA& msa, unsigned long random_seed)
{
RandomGenerator gen(random_seed);
return generate(msa, gen);
}
FloatWeightVector BootstrapGenerator::generate(const MSA& msa, RandomGenerator& gen)
{
unsigned int orig_len = msa.num_sites();
unsigned int comp_len = msa.length();
FloatWeightVector w_buf(orig_len, 0);
std::uniform_int_distribution<unsigned int> distr(0, orig_len-1);
for (unsigned int i = 0; i < orig_len; ++i)
{
auto site = distr(gen);
w_buf[site]++;
}
if (orig_len == comp_len)
return w_buf;
else
{
FloatWeightVector result(comp_len, 0);
auto orig_weights = msa.weights();
assert(!orig_weights.empty());
unsigned int pos = 0;
for (unsigned int i = 0; i < comp_len; ++i)
{
for (unsigned int j = 0; j < orig_weights[i]; ++j)
result[i] += w_buf[pos++];
}
return result;
}
}