def testNearestNeighbors(self): x = tf.constant([[0, 0.9, 0], [0.8, 0., 0.]], dtype=tf.float32) x = tf.reshape(x, [1, 1, 2, 3]) means = tf.constant( [[1, 0, 0], [0, 1, 0], [0, 0, 1], [9, 9, 9]], dtype=tf.float32) means = tf.stack([means, means], axis=0) x_means_hot, _ = discretization.nearest_neighbor( x, means, block_v_size=4) x_means_hot_test = np.array([[0, 1, 0, 0], [1, 0, 0, 0]]) x_means_hot_test = np.expand_dims(x_means_hot_test, axis=0) x_means_hot_eval = self.evaluate(x_means_hot) self.assertEqual(np.shape(x_means_hot_eval), (1, 2, 4)) self.assertTrue(np.all(x_means_hot_eval == x_means_hot_test))
def testNearestNeighbors(self): x = tf.constant([[0, 0.9, 0], [0.8, 0., 0.]], dtype=tf.float32) x = tf.reshape(x, [1, 1, 2, 3]) means = tf.constant( [[1, 0, 0], [0, 1, 0], [0, 0, 1], [9, 9, 9]], dtype=tf.float32) means = tf.stack([means, means], axis=0) x_means_hot, _ = discretization.nearest_neighbor( x, means, block_v_size=4) x_means_hot_test = np.array([[0, 1, 0, 0], [1, 0, 0, 0]]) x_means_hot_test = np.expand_dims(x_means_hot_test, axis=0) x_means_hot_eval = self.evaluate(x_means_hot) self.assertEqual(np.shape(x_means_hot_eval), (1, 2, 4)) self.assertTrue(np.all(x_means_hot_eval == x_means_hot_test))
def testNearestNeighbors(self): x = tf.constant([[0, 0.9, 0], [0.8, 0., 0.]], dtype=tf.float32) x = tf.expand_dims(x, axis=0) means = tf.constant([[1, 0, 0], [0, 1, 0], [0, 0, 1], [9, 9, 9]], dtype=tf.float32) means = tf.stack([means, means], axis=0) x_means_hot = discretization.nearest_neighbor(x, means, block_v_size=4) x_means_hot_test = np.array([[0, 1, 0, 0], [1, 0, 0, 0]]) x_means_hot_test = np.expand_dims(x_means_hot_test, axis=0) with self.test_session() as sess: tf.global_variables_initializer().run() x_means_hot_eval = sess.run(x_means_hot) self.assertEqual(np.shape(x_means_hot_eval), (1, 2, 4)) self.assertTrue(np.all(x_means_hot_eval == x_means_hot_test))
def testNearestNeighbors(self): x = tf.constant([[0, 0.9, 0], [0.8, 0., 0.]], dtype=tf.float32) x = tf.expand_dims(x, axis=0) means = tf.constant( [[1, 0, 0], [0, 1, 0], [0, 0, 1], [9, 9, 9]], dtype=tf.float32) means = tf.stack([means, means], axis=0) x_means_hot = discretization.nearest_neighbor(x, means, block_v_size=4) x_means_hot_test = np.array([[0, 1, 0, 0], [1, 0, 0, 0]]) x_means_hot_test = np.expand_dims(x_means_hot_test, axis=0) with self.test_session() as sess: tf.global_variables_initializer().run() x_means_hot_eval = sess.run(x_means_hot) self.assertEqual(np.shape(x_means_hot_eval), (1, 2, 4)) self.assertTrue(np.all(x_means_hot_eval == x_means_hot_test))