-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcombiner.cpp
More file actions
50 lines (40 loc) · 1.4 KB
/
Copy pathcombiner.cpp
File metadata and controls
50 lines (40 loc) · 1.4 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
#include <algorithm>
#include "combiner.h"
namespace NGCForest {
// TCombiner
void TCombiner::Combine(const std::vector<const TFeatures*> &source, TFeatures &result) {
result.resize(source.front()->size());
DoCombine(source, result);
}
// TMajorityVoteCombiner
namespace {
size_t ArgMax(const TFeatures &values) {
size_t res = 0;
for (size_t i = 1; i < values.size(); ++i) {
if (values[i] > values[res])
res = i;
}
return res;
}
}
void TMajorityVoteCombiner::DoCombine(const std::vector<const TFeatures*> &source, TFeatures &result) {
std::fill(result.begin(), result.end(), 0.0);
for (size_t i = 0; i < source.size(); ++i) {
size_t indexOfMax = ArgMax(*source[i]);
result[indexOfMax] += 1.0;
}
for (double &val : result)
val /= source.size();
}
// TAverageCombiner
void TAverageCombiner::DoCombine(const std::vector<const TFeatures*> &source, TFeatures &result) {
std::fill(result.begin(), result.end(), 0.0);
for (size_t i = 0; i < source.size(); ++i) {
for (size_t j = 0; j < result.size(); ++j) {
result[j] += (*(source[i]))[j];
}
}
for (double &val : result)
val /= source.size();
}
} // namespace NGCForest