1// Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// =============================================================================
15#ifndef TENSORFLOW_CONTRIB_BOOSTED_TREES_LIB_TREES_DECISION_TREE_H_
16#define TENSORFLOW_CONTRIB_BOOSTED_TREES_LIB_TREES_DECISION_TREE_H_
17
18#include "tensorflow/contrib/boosted_trees/lib/utils/example.h"
19#include "tensorflow/contrib/boosted_trees/proto/tree_config.pb.h"  // NOLINT
20
21namespace tensorflow {
22namespace boosted_trees {
23namespace trees {
24
25// Decision tree class to encapsulate tree traversal and mutation logic.
26// This class does not hold state and is thread safe.
27class DecisionTree {
28 public:
29  // Traverse given an instance, a sub-root and its set of features
30  // and return the leaf index or -1 if the tree is empty or
31  // the sub-root is invalid.
32  static int Traverse(const DecisionTreeConfig& config, int32 sub_root_id,
33                      const utils::Example& example);
34
35  // Links the specified children to the parent, the children must
36  // already be added to the decision tree config so this method
37  // just ensures nodes are re-linked.
38  static void LinkChildren(const std::vector<int32>& children,
39                           TreeNode* parent_node);
40
41  // Retrieves node children indices if any.
42  static std::vector<int32> GetChildren(const TreeNode& node);
43};
44
45}  // namespace trees
46}  // namespace boosted_trees
47}  // namespace tensorflow
48
49#endif  // TENSORFLOW_CONTRIB_BOOSTED_TREES_LIB_TREES_DECISION_TREE_H_
50