From 84e536d3710e2f0563c9945a660dc226625a9090 Mon Sep 17 00:00:00 2001 From: cxx Date: Tue, 7 Nov 2017 13:49:33 +0800 Subject: [PATCH] Fix std calculation using unbiased estimation in sharing stat mode. --- architectures/tensorflow_components/shared_variables.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/architectures/tensorflow_components/shared_variables.py b/architectures/tensorflow_components/shared_variables.py index 8ee623e..2775251 100644 --- a/architectures/tensorflow_components/shared_variables.py +++ b/architectures/tensorflow_components/shared_variables.py @@ -40,8 +40,9 @@ class SharedRunningStats(object): name="count", trainable=False) self._shape = shape - self._mean = tf.to_float(self._sum / self._count) - self._std = tf.sqrt(tf.maximum(tf.to_float(self._sum_squared / self._count) - tf.square(self._mean), 1e-2)) + self._mean = self._sum / self._count + self._std = tf.sqrt(tf.maximum((self._sum_squared - self._count*tf.square(self._mean)) + / tf.maximum(self._count-1, 1), epsilon)) self.new_sum = tf.placeholder(shape=self.shape, dtype=tf.float64, name='sum') self.new_sum_squared = tf.placeholder(shape=self.shape, dtype=tf.float64, name='var')