Class L1L2

All Implemented Interfaces:
Regularizer
Direct Known Subclasses:
L1, L2

public class L1L2 extends AbstractRegularizer
A regularizer that applies both L1 and L2 regularization penalties.

The L1 regularization penalty is computed as:

loss = l1 * reduceSum(abs(x))

The L2 regularization penalty is computed as

loss = l2 * reduceSum(square(x))
  • Constructor Details

    • L1L2

      public L1L2()
      Creates an L1L2 regularizer with no l1 or l2 penalty with zero penalty
    • L1L2

      public L1L2(float l1, float l2)
      Creates an L1L2 regularizer
      Parameters:
      l1 - L1 regularization factor, if null it is set to 0.
      l2 - L2 regularization factor, if null it is set to 0.
      Throws:
      IllegalArgumentException - if the l1 or l2 regularization factor is Float.isNaN(float) of Float.isInfinite(float)
    • L1L2

      public L1L2(String name, float l1, float l2)
      Creates an L1L2 regularizer
      Parameters:
      name - the name for this regularizer, if null the class name will be used.
      l1 - L1 regularization factor, if null it is set to 0.
      l2 - L2 regularization factor, if null it is set to 0.
      Throws:
      IllegalArgumentException - if the l1 or l2 regularization factor is Float.isNaN(float) of Float.isInfinite(float)
  • Method Details

    • call

      public <R extends TNumber> Operand<R> call(Ops tf, Operand<R> input)
      Computes a regularization penalty from an input.
      Type Parameters:
      R - the data type of the input and result
      Parameters:
      tf - the TensorFlow Ops
      input - the weighted input
      Returns:
      the result of computing the regularization penalty
    • getL1

      public float getL1()
      Gets the L1 regularization factor
      Returns:
      the L1 regularization factor
    • getL2

      public float getL2()
      Gets the L2 regularization factor
      Returns:
      the L2 regularization factor