tfl.lattice_lib.finalize_constraints
Stay organized with collections
Save and categorize content based on your preferences.
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.
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.
|
Returns |
Projected weights tensor of same shape as weights .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-08-02 UTC.
[null,null,["Last updated 2024-08-02 UTC."],[],[],null,["# tfl.lattice_lib.finalize_constraints\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/lattice_lib.py#L1039-L1104) |\n\nApproximately projects lattice weights to strictly satisfy all constraints. \n\n tfl.lattice_lib.finalize_constraints(\n weights,\n lattice_sizes,\n monotonicities,\n edgeworth_trusts=None,\n trapezoid_trusts=None,\n output_min=None,\n output_max=None\n )\n\nThis projeciton guarantees that constraints are strictly met, but it is not\nan exact projection w.r.t. the L2 norm. The computationally cost is\n`O((num_monotonic_dims + num_trust_constraints) * num_lattice_weights)`.\n\nSee helper functions `_approximately_project_*` for details of the individual\nprojection algorithms for each set of constraints. They are designed to be\napplied sequentially: monotonicity, then edgeworth, trapezoid, and bounds if\nnecessary. This is because the projection algorithms are guaranteed to not\nviolate *previous* constraints, though they may lead to violations of *later*\nconstraints.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `weights` | Lattice weights tensor of shape: `(prod(lattice_sizes), units)`. |\n| `lattice_sizes` | List or tuple of integers which represents lattice sizes. which correspond to weights. |\n| `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. |\n| `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. |\n| `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. |\n| `output_min` | None or minimum possible output. |\n| `output_max` | None or maximum possible output. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| Projected weights tensor of same shape as `weights`. ||\n\n\u003cbr /\u003e"]]