Fix a bug in tf.metrics.mean_tensor for case that the weights are very small.
authorA. Unique TensorFlower <gardener@tensorflow.org>
Wed, 21 Feb 2018 20:42:51 +0000 (12:42 -0800)
committerTensorFlower Gardener <gardener@tensorflow.org>
Wed, 21 Feb 2018 20:51:15 +0000 (12:51 -0800)
commit2a104e284c455615ba68c714e60a69f458be56ba
treea3536c2f74c6df62032bbd3b2ef6d562cb9fb71a
parente3b0a4291984f1af0cb8bf512542dffaca2d6cb5
Fix a bug in tf.metrics.mean_tensor for case that the weights are very small.

We have renamed metrics_test.MeanTensorTest.testWeighted1d as metrics_test.MeanTensorTest.testBinaryWeighted1d, since the weights on the instances are zeros and ones.

We have added a new metrics_test.MeanTensorTest.testWeighted1d that has small weights. It was failing for the previous implementation, but passes now.

Now the code for mean_tensor() and mean() now use the same _safe_div method. Previously, mean_tensor() used a different means to ensure that we don't divide by zero. This set the denominator to max(1., sum(weights)), which was inaccurate when sum(weights) is non-zero, but less than one.

PiperOrigin-RevId: 186503714
tensorflow/python/kernel_tests/metrics_test.py
tensorflow/python/ops/metrics_impl.py