forked from chong-z/tree-ensemble-attack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decision_forest.h
63 lines (41 loc) · 1.66 KB
/
decision_forest.h
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
#pragma once
#include <string>
#include "utility.h"
namespace cz {
class BoundingBox;
class LayeredBoundingBox;
class DecisionTree;
class DecisionForest {
public:
DecisionForest(int num_class, int max_feature_id);
~DecisionForest();
static std::unique_ptr<DecisionForest> CreateFromJson(const std::string& path,
int num_class,
int max_feature_id);
int PredictLabel(const Point& x) const;
int PredictLabelBetween(const Point& x, int class1, int class2) const;
std::unique_ptr<LayeredBoundingBox>
GetLayeredBoundingBox(const Point& x, int class1 = -1, int class2 = -1) const;
BoundingBox GetBoundingBox(const Point& x) const;
const std::vector<std::vector<double>>& FeatureSplits() const;
int HammingDistanceBetween(const Point& p1, const Point& p2, int class1, int class2) const;
std::vector<double> ComputeScores(const Point& x) const;
double ComputeBinaryScoreForTesting(const Point& x) const;
int NumTreesForTesting() const;
private:
friend class NeighborAttack;
friend class DecisionForestTest;
friend class NeighborAttackTest;
void Setup();
void ComputeBoundingBox();
void ComputeFeatureSplits();
void AddDecisionTree(std::unique_ptr<DecisionTree> tree);
bool has_bounding_box_ = false;
std::vector<std::unique_ptr<DecisionTree>> trees_;
// <feature_id, sorted_splits>.
std::unique_ptr<std::vector<std::vector<double>>> feature_splits_;
int num_class_;
int max_feature_id_;
DISALLOW_COPY_AND_ASSIGN(DecisionForest);
};
} // namespace cz