This test checks that the dual value after update is optimal. At the optimum the dual value should be the opposite of the primal gradient. This does not hold at a point where the primal is not differentiable.
| 35 | // At the optimum the dual value should be the opposite of the primal gradient. |
| 36 | // This does not hold at a point where the primal is not differentiable. |
| 37 | void TestComputeUpdatedDual(const DualLossUpdater &loss_updater, |
| 38 | const int num_loss_partitions, const double label, |
| 39 | const double example_weight, |
| 40 | const double current_dual, const double wx, |
| 41 | const double weighted_example_norm) { |
| 42 | double new_dual = loss_updater.ComputeUpdatedDual( |
| 43 | num_loss_partitions, label, example_weight, current_dual, wx, |
| 44 | weighted_example_norm); |
| 45 | // The primal gradient needs to be computed after the weight update. |
| 46 | double new_wx = wx + (new_dual - current_dual) * num_loss_partitions * |
| 47 | weighted_example_norm * example_weight; |
| 48 | EXPECT_NEAR(new_dual, -loss_updater.PrimalLossDerivative(new_wx, label, 1.0), |
| 49 | 1e-5); |
| 50 | } |
| 51 | |
| 52 | TEST(LogisticLoss, ComputePrimalLoss) { |
| 53 | LogisticLossUpdater loss_updater; |
no test coverage detected