MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TestComputeUpdatedDual

Function TestComputeUpdatedDual

tensorflow/core/kernels/loss_test.cc:37–50  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

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.
37void 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
52TEST(LogisticLoss, ComputePrimalLoss) {
53 LogisticLossUpdater loss_updater;

Callers 1

TESTFunction · 0.85

Calls 2

ComputeUpdatedDualMethod · 0.45
PrimalLossDerivativeMethod · 0.45

Tested by

no test coverage detected