| 22 | namespace tensorforest { |
| 23 | |
| 24 | float ResolveParam(const DepthDependentParam& param, int32 depth) { |
| 25 | float val; |
| 26 | switch (param.ParamType_case()) { |
| 27 | case DepthDependentParam::kConstantValue: |
| 28 | return param.constant_value(); |
| 29 | |
| 30 | case DepthDependentParam::kLinear: |
| 31 | val = depth * param.linear().slope() + param.linear().y_intercept(); |
| 32 | return std::min(std::max(val, param.linear().min_val()), |
| 33 | param.linear().max_val()); |
| 34 | |
| 35 | case DepthDependentParam::kExponential: |
| 36 | return param.exponential().bias() + |
| 37 | param.exponential().multiplier() * |
| 38 | static_cast<float>( |
| 39 | std::pow(param.exponential().base(), |
| 40 | param.exponential().depth_multiplier() * depth)); |
| 41 | |
| 42 | case DepthDependentParam::kThreshold: |
| 43 | if (depth >= param.threshold().threshold()) { |
| 44 | return param.threshold().on_value(); |
| 45 | } else { |
| 46 | return param.threshold().off_value(); |
| 47 | } |
| 48 | |
| 49 | default: |
| 50 | LOG(FATAL) << "unknown parameter type"; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | } // namespace tensorforest |
| 55 | } // namespace tensorflow |