Page Speed Optimization Libraries  1.9.32.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
decision_tree.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_DECISION_TREE_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_DECISION_TREE_H_
21 
22 #include <cstddef>
23 #include <vector>
24 
25 namespace net_instaweb {
26 
41 class DecisionTree {
42  public:
43  struct Node {
44  int feature_index;
45  double feature_threshold;
46  double confidence;
47  const Node* left;
48  const Node* right;
49  bool IsLeafNode() const { return (left == NULL && right == NULL); }
50  };
51 
54  DecisionTree(const Node* nodes, int num_nodes);
55  ~DecisionTree();
56 
57  int num_features() const { return num_features_; }
58 
65  double Predict(std::vector<double> const& sample) const;
66 
67  private:
68  void SanityCheck() const;
69  void SanityCheckTraversal(const Node* cur, int* num_nodes) const;
70 
71  const Node* Root() const;
72 
73  const Node* nodes_;
74  int num_nodes_;
75  int num_features_;
76 };
77 
78 }
79 
80 #endif
Definition: decision_tree.h:43
double Predict(std::vector< double > const &sample) const
Definition: decision_tree.h:41
DecisionTree(const Node *nodes, int num_nodes)