def testFtrlWithL1_L2_L2Shrinkage(self):
    'Test the new FTRL op with support for l2 shrinkage.\n\n    The addition of this parameter which places a constant pressure on weights\n    towards the origin causes the gradient descent trajectory to differ. The\n    weights will tend to have smaller magnitudes with this parameter set.\n    '
    for dtype in self.float_types:
        with self.test_session(), self.test_scope():
            var0 = resource_variable_ops.ResourceVariable([1.0, 2.0], dtype=dtype)
            var1 = resource_variable_ops.ResourceVariable([4.0, 3.0], dtype=dtype)
            grads0 = constant_op.constant([0.1, 0.2], dtype=dtype)
            grads1 = constant_op.constant([0.01, 0.02], dtype=dtype)
            opt = ftrl.FtrlOptimizer(3.0, initial_accumulator_value=0.1, l1_regularization_strength=0.001, l2_regularization_strength=2.0, l2_shrinkage_regularization_strength=0.1)
            ftrl_update = opt.apply_gradients(zip([grads0, grads1], [var0, var1]))
            variables.global_variables_initializer().run()
            self.assertAllClose([1.0, 2.0], var0.eval())
            self.assertAllClose([4.0, 3.0], var1.eval())
            for _ in range(10):
                ftrl_update.run()
            self.assertAllClose(np.array([(- 0.21931979), (- 0.40642974)]), var0.eval())
            self.assertAllClose(np.array([(- 0.0282721), (- 0.07188385)]), var1.eval())
Test the new FTRL op with support for l2 shrinkage.

The addition of this parameter which places a constant pressure on weights
towards the origin causes the gradient descent trajectory to differ. The
weights will tend to have smaller magnitudes with this parameter set.
def testFtrlWithL1_L2_L2Shrinkage(self):
    'Test the new FTRL op with support for l2 shrinkage.\n\n    The addition of this parameter which places a constant pressure on weights\n    towards the origin causes the gradient descent trajectory to differ. The\n    weights will tend to have smaller magnitudes with this parameter set.\n    '
    for dtype in self.float_types:
        with self.test_session(), self.test_scope():
            var0 = resource_variable_ops.ResourceVariable([1.0, 2.0], dtype=dtype)
            var1 = resource_variable_ops.ResourceVariable([4.0, 3.0], dtype=dtype)
            grads0 = constant_op.constant([0.1, 0.2], dtype=dtype)
            grads1 = constant_op.constant([0.01, 0.02], dtype=dtype)
            opt = ftrl.FtrlOptimizer(3.0, initial_accumulator_value=0.1, l1_regularization_strength=0.001, l2_regularization_strength=2.0, l2_shrinkage_regularization_strength=0.1)
            ftrl_update = opt.apply_gradients(zip([grads0, grads1], [var0, var1]))
            variables.global_variables_initializer().run()
            self.assertAllClose([1.0, 2.0], var0.eval())
            self.assertAllClose([4.0, 3.0], var1.eval())
            for _ in range(10):
                ftrl_update.run()
            self.assertAllClose(np.array([(- 0.21931979), (- 0.40642974)]), var0.eval())
            self.assertAllClose(np.array([(- 0.0282721), (- 0.07188385)]), var1.eval())