• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 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 TENSORFLOW_CORE_KERNELS_PARAMETERIZED_TRUNCATED_NORMAL_OP_H_
17 #define TENSORFLOW_CORE_KERNELS_PARAMETERIZED_TRUNCATED_NORMAL_OP_H_
18 
19 #include "tensorflow/core/framework/tensor_types.h"
20 #include "tensorflow/core/lib/random/random_distributions.h"
21 
22 namespace tensorflow {
23 
24 class OpKernelContext;
25 
26 namespace functor {
27 
28 // Sample a truncated normal random variable, with mean, stddev, minval, and
29 // maxval parameters for each batch. Uses two rejection sampling algorithms
30 // described in http://rd.springer.com/article/10.1007/BF00143942 and a randn
31 // rejection sampler when most of the normal is inside the bounds.
32 //
33 // Either minval may be -infinity, or maxval may be +infinity. If the interval
34 // (minval, maxval) is empty, the result is NaN.
35 template <typename Device, typename T>
36 struct TruncatedNormalFunctor {
37   void operator()(OpKernelContext* ctx, const Device& d, int64 num_batches,
38                   int64 samples_per_batch, int64 num_elements,
39                   typename TTypes<T>::ConstFlat means,
40                   typename TTypes<T>::ConstFlat stddevs,
41                   typename TTypes<T>::ConstFlat minvals,
42                   typename TTypes<T>::ConstFlat maxvals,
43                   const random::PhiloxRandom& gen,
44                   typename TTypes<T>::Flat output);
45 };
46 
47 }  // namespace functor
48 }  // namespace tensorflow
49 
50 #endif  // TENSORFLOW_CORE_KERNELS_PARAMETERIZED_TRUNCATED_NORMAL_OP_H_
51