Пример #1
0
 def custom_hinge(_, y_pred):
     loss = 0.5 * tf.reduce_sum(w**2) + 0.5 * tf.reduce_sum(
         V**2) + quantile_loss(self.r, y_pred, nu)
     self.r = tf.contrib.distributions.percentile(tf.reduce_max(y_pred,
                                                                axis=1),
                                                  q=100 * nu)
     return loss
def test_loss_function():
    # Test case described in the paper
    # GIVEN we have this data (integers from 1-9) and nu = 1/3 (0.33)
    data = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    nu = 0.33
    y = tf.convert_to_tensor([data], dtype=tf.float32)
    # WHEN we execute the quantile loss function on each value in the data
    results = {r: quantile_loss(r, y, nu) - r for r in data}
    # THEN the argument which gives us the minimum value should be 3
    assert next(k for k, v in results.items() if v == min(results.values())) == 3
Пример #3
0
 def quantile_loss_metric(*args):
     return quantile_loss(self.r, args[1], nu)