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

Function FtrlCompute

tensorflow/core/kernels/training_ops.cc:441–464  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

439
440template <typename T>
441inline T FtrlCompute(const T& accum, const T& linear, const T& lr, const T& l1,
442 const T& l2, const T& lr_power,
443 const bool multiply_linear_by_lr) {
444 T quadratic;
445 if (multiply_linear_by_lr) {
446 if (lr_power == static_cast<T>(-0.5)) {
447 quadratic = Eigen::numext::sqrt(accum) + static_cast<T>(2) * l2 * lr;
448 } else {
449 quadratic =
450 Eigen::numext::pow(accum, -lr_power) + static_cast<T>(2) * l2 * lr;
451 }
452 auto l1_reg_adjust = std::max(std::min(linear, l1 * lr), -l1 * lr);
453 return (l1_reg_adjust - linear) / quadratic;
454 } else {
455 if (lr_power == static_cast<T>(-0.5)) {
456 quadratic = Eigen::numext::sqrt(accum) / lr + static_cast<T>(2) * l2;
457 } else {
458 quadratic =
459 Eigen::numext::pow(accum, -lr_power) / lr + static_cast<T>(2) * l2;
460 }
461 auto l1_reg_adjust = std::max(std::min(linear, l1), -l1);
462 return (l1_reg_adjust - linear) / quadratic;
463 }
464}
465
466} // namespace
467

Callers 1

operator()Method · 0.85

Calls 4

sqrtClass · 0.70
powClass · 0.70
maxFunction · 0.50
minFunction · 0.50

Tested by

no test coverage detected