def test_huber_continuous(self): with self.test_session(): epsilon = tf.constant( 1e-10, dtype=tf.float32) predicted = tf.constant( [1], dtype=tf.float32, name='predicted') gold_standard = tf.constant( [0], dtype=tf.float32, name='gold_standard') huber_loss_inside_delta = huber_loss( predicted + epsilon, gold_standard, delta=1.0) huber_loss_outside_delta = huber_loss( predicted - epsilon, gold_standard, delta=1.0) self.assertAlmostEqual(huber_loss_inside_delta.eval(), huber_loss_outside_delta.eval())
def test_huber_continuous(self): with self.test_session(): epsilon = tf.constant(1e-10, dtype=tf.float32) predicted = tf.constant([1], dtype=tf.float32, name='predicted') gold_standard = tf.constant([0], dtype=tf.float32, name='gold_standard') huber_loss_inside_delta = huber_loss(predicted + epsilon, gold_standard, delta=1.0) huber_loss_outside_delta = huber_loss(predicted - epsilon, gold_standard, delta=1.0) self.assertAlmostEqual(huber_loss_inside_delta.eval(), huber_loss_outside_delta.eval())
def test_huber_loss(self): with self.test_session(): predicted = tf.constant([[0, 10], [10, 0], [10, 0], [10, 0]], dtype=tf.float32, name='predicted') gold_standard = tf.constant([[0, 10], [10, 0], [10, 0], [10, 0]], dtype=tf.float32, name='gold_standard') self.assertEqual(huber_loss(predicted, gold_standard).eval(), 0.0)
def test_huber_loss(self): with self.test_session(): predicted = tf.constant( [[0, 10], [10, 0], [10, 0], [10, 0]], dtype=tf.float32, name='predicted') gold_standard = tf.constant( [[0, 10], [10, 0], [10, 0], [10, 0]], dtype=tf.float32, name='gold_standard') self.assertEqual(huber_loss(predicted, gold_standard).eval(), 0.0)
def test_huber_loss_hand_example(self): with self.test_session(): # loss should be: mean( 0.2 ** 2/ 2 + (2-0.5) ) == 1.52/2 == 0.76 predicted = tf.constant( [1.2, 1], dtype=tf.float32, name='predicted') gold_standard = tf.constant( [1, 3], dtype=tf.float32, name='gold_standard') loss = huber_loss(predicted, gold_standard, delta=1.0) self.assertAlmostEqual(loss.eval(), .76)
def test_huber_loss_hand_example(self): with self.test_session(): # loss should be: mean( 0.2 ** 2/ 2 + (2-0.5) ) == 1.52/2 == 0.76 predicted = tf.constant([1.2, 1], dtype=tf.float32, name='predicted') gold_standard = tf.constant([1, 3], dtype=tf.float32, name='gold_standard') loss = huber_loss(predicted, gold_standard, delta=1.0) self.assertAlmostEqual(loss.eval(), .76)