def test_create_ndcg_lambda_weight(self): sorted_labels = [[2.0, 1.0]] lambda_weight = ranking_losses.create_ndcg_lambda_weight() max_dcg = 3.0 / math.log(2.) + 1.0 / math.log(3.) with self.cached_session(): self.assertAllClose( lambda_weight.pair_weights(sorted_labels).eval(), [[[0., 2. * (1. / math.log(2.) - 1. / math.log(3.)) / max_dcg], [2. * (1. / math.log(2.) - 1. / math.log(3.)) / max_dcg, 0.]]])
def test_create_ndcg_lambda_weight(self): with tf.Graph().as_default(): labels = [[2.0, 1.0]] ranks = [[1, 2]] lambda_weight = ranking_losses.create_ndcg_lambda_weight() scale = 2. max_dcg = 3.0 / math.log(2.) + 1.0 / math.log(3.) with self.cached_session(): self.assertAllClose( lambda_weight.pair_weights(labels, ranks).eval() / scale, [[[0., 2. * (1. / math.log(2.) - 1. / math.log(3.)) / max_dcg], [2. * (1. / math.log(2.) - 1. / math.log(3.)) / max_dcg, 0.]]])