tfl.lattice_lib.finalize_constraints

View source on GitHub

Approximately projects lattice weights to strictly satisfy all constraints.

This projeciton guarantees that constraints are strictly met, but it is not an exact projection w.r.t. the L2 norm. The computationally cost is O((num_monotonic_dims + num_trust_constraints) * num_lattice_weights).

See helper functions _approximately_project_* for details of the individual projection algorithms for each set of constraints. They are designed to be applied sequentially: monotonicity, then edgeworth, trapezoid, and bounds if necessary. This is because the projection algorithms are guaranteed to not violate previous constraints, though they may lead to violations of later constraints.

weights Lattice weights tensor of shape: (prod(lattice_sizes), units).
lattice_sizes List or tuple of integers which represents lattice sizes. which correspond to weights.
monotonicities 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.
edgeworth_trusts None or iterable of three-element tuples. First element is the index of the main (monotonic) feature. Second element is the index of the conditional feature. Third element is the direction of trust set to 1 if higher values of the conditional feature should increase trust in the main feature and -1 otherwise.
trapezoid_trusts None or iterable of three-element tuples. First element is the index of the main (monotonic) feature. Second element is the index of the conditional feature. Third element is the direction of trust set to 1 if higher values of the conditional feature should increase trust in the main feature and -1 otherwise.
output_min None or minimum possible output.
output_max None or maximum possible output.

Projected weights tensor of same shape as weights.