# tfl.lattice_lib.finalize_constraints

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/lattice_lib.py#L1039-L1104) |

Approximately projects lattice weights to strictly satisfy all constraints.

    tfl.lattice_lib.finalize_constraints(
        weights,
        lattice_sizes,
        monotonicities,
        edgeworth_trusts=None,
        trapezoid_trusts=None,
        output_min=None,
        output_max=None
    )

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.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `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. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| Projected weights tensor of same shape as `weights`. ||

<br />