tfl.lattice_lib.linear_initializer

View source on GitHub

Returns a lattice layer weight tensor that represents a linear function.

tfl.lattice_lib.linear_initializer(
    lattice_sizes,
    output_min,
    output_max,
    monotonicities=None,
    unimodalities=None,
    units=1,
    dtype=tf.float32
)
  • The linear function will have positive coefficients for monotonic dimensions and 0 otherwise. If all dimensions are unconstrained, all coefficients will be positive.
  • Linear coefficients are set such that the minimum/maximum output of the lattice matches the given output_min/output_max.
  • Each monotonic dimension contributes with same weight regardless of number of vertices per dimension.
  • No dimension can be both monotonic and unimodal.
  • Unimodal dimensions contribute with same weight as monotonic dimensions.
  • Unimodal dimensions linearly decrease for first (dim_size + 1) // 2 vertices and then linearly increase for following vertices.

Args:

  • lattice_sizes: List or tuple of integers which represents lattice sizes.
  • output_min: Minimum output of lattice layer after initialization.
  • output_max: Maximum output of lattice layer after initialization.
  • monotonicities: None or list or tuple of same length as lattice_sizes of {0, 1} which represents monotonicity constraints per dimension. 1 stands for increasing (non-decreasing in fact), 0 for no monotonicity constraints.
  • unimodalities: None or list or tuple of same length as lattice_sizes of {0, 1} which represents unimodality constraints per dimension. 1 stands for unimodal dimension, 0 for no unimodality constraints.
  • units: Output dimension of the layer. Each of units lattices will be initialized identically.
  • dtype: dtype.

Returns:

Lattice weights tensor of shape: (prod(lattice_sizes), units).