This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathtypes.h
66 lines (53 loc) · 2.03 KB
/
types.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
64
65
66
/*
Copyright 2015 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef TYPES_H_
#define TYPES_H_
#include <map>
#include <vector>
using std::map;
using std::pair;
using std::vector;
// Used in many places as the minimum possible difference between two distinct
// numbers. Helps make code stable, tests predictable, etc.
static const float kTolerance = 1e-7;
typedef int Feature;
typedef int Label;
typedef int NodeId;
typedef float Value;
typedef float Weight;
// An example consists of a vector of feature values, a label and a weight.
// Note that this is a dense feature representation; the value of every
// feature is contained in the vector, listed in a canonical order.
typedef struct Example {
vector<Value> values;
Label label;
Weight weight;
} Example;
// A tree node.
typedef struct Node {
vector<Example> examples; // Examples at this node.
Feature split_feature; // Split feature.
Value split_value; // Split value.
NodeId left_child_id; // Pointer to left child, if any.
NodeId right_child_id; // Pointer to right child, if any.
Weight positive_weight; // Total weight of positive examples at this node.
Weight negative_weight; // Total weight of negative examples at this node.
bool leaf; // Is this node is a leaf?
int depth; // Depth of the node in the tree. Root node has depth 0.
} Node;
// A tree is a vector of nodes.
typedef vector<Node> Tree;
// A model is a vector of (weight, tree) pairs, i.e., a weighted combination of
// trees.
typedef vector<pair<Weight, Tree>> Model;
#endif // TYPES_H_