aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/tensor_forest/kernels/v4/params_test.cc
blob: 4010a71006d58df0bec6d3686a9c47433b46fdd4 (plain)
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
67
68
69
70
71
72
73
// Copyright 2017 The TensorFlow Authors. 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.
// =============================================================================
#include "tensorflow/contrib/tensor_forest/kernels/v4/params.h"
#include "tensorflow/contrib/tensor_forest/proto/tensor_forest_params.pb.h"
#include "tensorflow/core/platform/test.h"

namespace {

using tensorflow::tensorforest::DepthDependentParam;
using tensorflow::tensorforest::ResolveParam;

TEST(ParamsTest, TestConstant) {
  DepthDependentParam param;
  param.set_constant_value(10.0);

  ASSERT_EQ(ResolveParam(param, 0), 10.0);
  ASSERT_EQ(ResolveParam(param, 100), 10.0);
}

TEST(ParamsTest, TestLinear) {
  DepthDependentParam param;
  auto* linear = param.mutable_linear();
  linear->set_y_intercept(100.0);
  linear->set_slope(-10.0);
  linear->set_min_val(23.0);
  linear->set_max_val(90.0);

  ASSERT_EQ(ResolveParam(param, 0), 90);
  ASSERT_EQ(ResolveParam(param, 1), 90);
  ASSERT_EQ(ResolveParam(param, 2), 80);

  ASSERT_EQ(ResolveParam(param, 30), 23);
}

TEST(ParamsTest, TestExponential) {
  DepthDependentParam param;
  auto* expo = param.mutable_exponential();
  expo->set_bias(100.0);
  expo->set_base(10.0);
  expo->set_multiplier(-1.0);
  expo->set_depth_multiplier(1.0);

  ASSERT_EQ(ResolveParam(param, 0), 99);
  ASSERT_EQ(ResolveParam(param, 1), 90);
  ASSERT_EQ(ResolveParam(param, 2), 0);
}

TEST(ParamsTest, TestThreshold) {
  DepthDependentParam param;
  auto* threshold = param.mutable_threshold();
  threshold->set_on_value(100.0);
  threshold->set_off_value(10.0);
  threshold->set_threshold(5.0);

  ASSERT_EQ(ResolveParam(param, 0), 10);
  ASSERT_EQ(ResolveParam(param, 4), 10);
  ASSERT_EQ(ResolveParam(param, 5), 100);
  ASSERT_EQ(ResolveParam(param, 6), 100);
}

}  // namespace