utils.h revision bc0a56da15eed8738e8a53e2dd340030332df28a
1// Copyright 2016 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 16#ifndef LEARNING_LIB_TENSOR_FOREST_HYBRID_CORE_OPS_UTILS_H_ 17#define LEARNING_LIB_TENSOR_FOREST_HYBRID_CORE_OPS_UTILS_H_ 18#include <vector> 19 20#include "tensorflow/core/framework/tensor.h" 21#include "tensorflow/core/platform/types.h" 22 23namespace tensorflow { 24namespace tensorforest { 25 26// Returns the probability that the point falls to the left. 27float LeftProbability(const Tensor& point, 28 const Tensor& weight, 29 float bias, 30 int num_features); 31 32float LeftProbabilityK(const Tensor& point, 33 std::vector<int32> feature_set, 34 const Tensor& weight, 35 float bias, 36 int num_features, 37 int k); 38 39// Returns a random set of num_features_to_pick features in the 40// range [0, num_features). Must return the same set of 41// features for subsequent calls with the same tree_num, node_num, and 42// random_seed. This allows us to calculate feature sets between calls to ops 43// without having to store their values. 44void GetFeatureSet(int32 tree_num, int32 node_num, int32 random_seed, 45 int32 num_features, int32 num_features_to_pick, 46 std::vector<int32>* features); 47 48} // namespace tensorforest 49} // namespace tensorflow 50 51#endif // LEARNING_LIB_TENSOR_FOREST_HYBRID_CORE_OPS_UTILS_H_ 52 53 54