def __init__(self, encoder, predictor, name='AverageKL', prefix='Metrics', dtype=tf.float32, batch_size=1, buffer_size=1000): super(AverageKLMetric, self).__init__(name=name, prefix=prefix, metric_names=('KL', 'MSE')) self._kl_buffer = tf_metrics.TFDeque(buffer_size, dtype) self._mse_buffer = tf_metrics.TFDeque(buffer_size, dtype) self._dtype = dtype self._encoder = encoder self._predictor = predictor
def test_mean_not_full(self): d = tf_metrics.TFDeque(3, tf.int32) self.evaluate(tf.compat.v1.global_variables_initializer()) self.evaluate(d.add(2)) self.evaluate(d.add(4)) self.assertEqual(3.0, self.evaluate(d.mean()))
def test_extend(self): d = tf_metrics.TFDeque(3, tf.int32, shape=(2,)) self.evaluate(tf.compat.v1.global_variables_initializer()) self.evaluate(d.extend([[1, 1], [2, 2], [3, 3], [4, 4]])) self.assertAllEqual([[4, 4], [2, 2], [3, 3]], self.evaluate(d.data)) self.assertAllEqual([3, 3], self.evaluate(d.mean()))
def test_extend(self): d = tf_metrics.TFDeque(3, tf.float32) self.evaluate(tf.compat.v1.global_variables_initializer()) self.evaluate(d.extend([1, 2, 3, 4])) self.assertEqual(3.0, self.evaluate(d.mean())) self.assertEqual(tf.float32, d.mean().dtype)
def test_mean_not_full(self): d = tf_metrics.TFDeque(3, tf.int32, shape=(2,)) self.evaluate(tf.compat.v1.global_variables_initializer()) self.evaluate(d.add([1, 1])) self.evaluate(d.add([3, 3])) self.assertAllEqual([2, 2], self.evaluate(d.mean())) self.assertEqual(tf.int32, d.mean().dtype)
def __init__(self, prefix='Metrics', dtype=tf.float32, batch_size=1, buffer_size=10, obs_dim=None, start_index=0, end_index=None, name=None): assert obs_dim is not None self._start_index = start_index self._end_index = end_index self._obs_dim = obs_dim name = self.NAME if name is None else name super(BaseDistanceMetric, self).__init__(name=name, prefix=prefix) self._buffer = tf_metrics.TFDeque(buffer_size, dtype) self._dist_buffer = tf_metrics.TFDeque( 1000, dtype) # Episodes should have length less than 1k self.dtype = dtype
def test_queue_empty(self): d = tf_metrics.TFDeque(3, tf.int32) self.evaluate(tf.compat.v1.global_variables_initializer()) self.assertEqual(0, self.evaluate(d.mean())) self.assertEqual(tf.int32.min, self.evaluate(d.max())) self.assertEqual(tf.int32.max, self.evaluate(d.min())) self.assertEqual(tf.int32, d.mean().dtype) self.assertEqual(tf.int32, d.min().dtype) self.assertEqual(tf.int32, d.max().dtype)
def test_mean_roll_over(self): d = tf_metrics.TFDeque(3, tf.float32) self.evaluate(tf.compat.v1.global_variables_initializer()) self.evaluate(d.add(1)) self.evaluate(d.add(2)) self.evaluate(d.add(3)) self.evaluate(d.add(4)) self.assertEqual(3.0, self.evaluate(d.mean())) self.assertEqual(tf.float32, d.mean().dtype)
def test_mean_roll_over(self): d = tf_metrics.TFDeque(3, tf.float32, shape=(2,)) self.evaluate(tf.compat.v1.global_variables_initializer()) self.evaluate(d.add([1, 1])) self.evaluate(d.add([2, 2])) self.evaluate(d.add([3, 3])) self.evaluate(d.add([4, 4])) self.assertAllEqual([3.0, 3.0], self.evaluate(d.mean())) self.assertEqual(tf.float32, d.mean().dtype)
def test_rolls_over(self): d = tf_metrics.TFDeque(3, tf.int32) self.evaluate(tf.compat.v1.global_variables_initializer()) self.evaluate(d.add(1)) self.evaluate(d.add(2)) self.evaluate(d.add(3)) self.assertAllEqual([1, 2, 3], self.evaluate(d.data)) self.evaluate(d.add(4)) self.assertAllEqual([4, 2, 3], self.evaluate(d.data))
def test_rolls_over(self): d = tf_metrics.TFDeque(3, tf.int32, shape=(2,)) self.evaluate(tf.compat.v1.global_variables_initializer()) self.evaluate(d.add([1, 1])) self.evaluate(d.add([2, 2])) self.evaluate(d.add([3, 3])) self.assertAllEqual([[1, 1], [2, 2], [3, 3]], self.evaluate(d.data)) self.evaluate(d.add([4, 4])) self.assertAllEqual([[4, 4], [2, 2], [3, 3]], self.evaluate(d.data))
def test_clear(self): d = tf_metrics.TFDeque(3, tf.int32, shape=(2,)) self.evaluate(tf.compat.v1.global_variables_initializer()) self.evaluate(d.add([1, 1])) self.evaluate(d.clear()) self.assertAllEqual((0, 2), self.evaluate(d.data).shape) self.evaluate(d.add([2, 2])) self.evaluate(d.add([3, 3])) self.assertAllEqual([[2, 2], [3, 3]], self.evaluate(d.data))
def test_data_is_zero(self): d = tf_metrics.TFDeque(3, tf.int32) self.evaluate(tf.compat.v1.global_variables_initializer()) self.assertAllEqual([], self.evaluate(d.data))
def test_mean_empty(self): d = tf_metrics.TFDeque(3, tf.int32) self.evaluate(tf.compat.v1.global_variables_initializer()) self.assertEqual(0, self.evaluate(d.mean()))
def test_mean_empty(self): d = tf_metrics.TFDeque(3, tf.int32, shape=(2,)) self.evaluate(tf.compat.v1.global_variables_initializer()) self.assertAllEqual([0, 0], self.evaluate(d.mean())) self.assertEqual(tf.int32, d.mean().dtype)
def test_max(self): d = tf_metrics.TFDeque(4, tf.float32) self.evaluate(tf.compat.v1.global_variables_initializer()) self.evaluate(d.extend([1, 2, 3, 4])) self.assertEqual(4.0, self.evaluate(d.max()))
def test_data_is_zero(self): d = tf_metrics.TFDeque(3, tf.int32, shape=(2,)) self.evaluate(tf.compat.v1.global_variables_initializer()) values = self.evaluate(d.data) self.assertAllEqual((0, 2), values.shape)