-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathNode.cpp
More file actions
74 lines (65 loc) · 1.89 KB
/
Copy pathNode.cpp
File metadata and controls
74 lines (65 loc) · 1.89 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
68
69
70
71
72
73
74
/**
* This file is part of ltp-text-detector.
* Copyright (C) 2013 Michael Opitz
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <detector/Node.h>
#include <iostream>
#include <fstream>
#include <limits>
#include <float.h>
#include <Eigen/Core>
#include <Eigen/Dense>
#include <detector/config.h>
using std::vector;
namespace Detector {
Node::Node(
int id,
const Matrix& labels,
const std::vector<double> &weights,
const vector<int> &samples,
int label,
bool recompute_impurity)
: id_(id),
n_samples_(samples.size()),
samples_(samples),
split_bias_(-1),
fraction_pos_(label)
{
init_node(labels, weights, recompute_impurity);
}
Node::Node()
: id_(0),
n_samples_(0),
split_bias_(-1),
fraction_pos_(-1.0),
is_leaf_(0) {}
void Node::init_node(const Matrix& labels, const std::vector<double> &weights, bool recompute_fraction_pos)
{
if (recompute_fraction_pos) {
double sum = 0.0;
double norm = 0.0;
for (size_t i = 0; i < samples_.size(); ++i) {
double val = labels(samples_[i],0);
double w = weights[samples_[i]];
sum += (val * w);
norm += w;
}
assert (norm > 0);
fraction_pos_ = sum / norm; /// (norm <= 0.0f ? 1e-5 : norm);
}
is_leaf_ = false;
}
}