tfl.linear_layer.LinearConstraints
Stay organized with collections
Save and categorize content based on your preferences.
Applies monotonicity constraints and normalization to TFL Linear layer.
tfl.linear_layer.LinearConstraints(
monotonicities,
monotonic_dominances=None,
range_dominances=None,
input_min=None,
input_max=None,
normalization_order=None
)
Monotonicity is specified per input dimension in which case learned weight for
those dimensions is guaranteed to be either non negative for increasing or non
positive for decreasing monotonicity.
Monotonic dominance can be specified for any pair of dimensions referred to as
dominant and weak dimensions such that the effect (slope) in the direction
of the dominant dimension to be greater than that of the weak dimension
for any point. Both dominant and weak dimensions must be increasing.
Range dominance can be specified for any pair of dominant and weak
dimensions such that the range of possible outputs to be greater if one varies
the dominant dimension than if one varies the weak dimension for any
point. We require the slope of the dominant dimension scaled by its input
range to be greater than the slope of the weak dimension similarly scaled by
its input range. Both dimensions must have the same direction of monotonicity
and their input min and max must be provided.
Weights can be constrained to have norm 1.
Args |
monotonicities
|
Same meaning as corresponding parameter of Linear .
|
monotonic_dominances
|
Same meaning as corresponding parameter of Linear .
|
range_dominances
|
Same meaning as corresponding parameter of Linear .
|
input_min
|
Same meaning as corresponding parameter of Linear .
|
input_max
|
Same meaning as corresponding parameter of Linear .
|
normalization_order
|
Same meaning as corresponding parameter of Linear .
|
Methods
from_config
@classmethod
from_config(
config
)
Instantiates a weight constraint from a configuration dictionary.
Example:
constraint = UnitNorm()
config = constraint.get_config()
constraint = UnitNorm.from_config(config)
Args |
config
|
A Python dictionary, the output of get_config .
|
get_config
View source
get_config()
Standard Keras get_config() method.
__call__
View source
__call__(
w
)
Applies constraints to w.
Args |
w
|
Tensor which represents weights of TFL linear layer. Must have shape:
(len(self.monotonicities), 1) .
|
Raises |
ValueError
|
if shape of w is not (len(self.monotonicities), 1) .
|
Returns |
Tensor w with monotonicity constraints and normalization applied to it.
|
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-08-02 UTC."],[],[],null,["# tfl.linear_layer.LinearConstraints\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/linear_layer.py#L350-L434) |\n\nApplies monotonicity constraints and normalization to TFL Linear layer. \n\n tfl.linear_layer.LinearConstraints(\n monotonicities,\n monotonic_dominances=None,\n range_dominances=None,\n input_min=None,\n input_max=None,\n normalization_order=None\n )\n\nMonotonicity is specified per input dimension in which case learned weight for\nthose dimensions is guaranteed to be either non negative for increasing or non\npositive for decreasing monotonicity.\n\nMonotonic dominance can be specified for any pair of dimensions referred to as\n*dominant* and *weak* dimensions such that the effect (slope) in the direction\nof the *dominant* dimension to be greater than that of the *weak* dimension\nfor any point. Both dominant and weak dimensions must be increasing.\n\nRange dominance can be specified for any pair of *dominant* and *weak*\ndimensions such that the range of possible outputs to be greater if one varies\nthe *dominant* dimension than if one varies the *weak* dimension for any\npoint. We require the slope of the *dominant* dimension scaled by its input\nrange to be greater than the slope of the *weak* dimension similarly scaled by\nits input range. Both dimensions must have the same direction of monotonicity\nand their input min and max must be provided.\n\nWeights can be constrained to have norm 1.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------------|------------------------------------------------------|\n| `monotonicities` | Same meaning as corresponding parameter of `Linear`. |\n| `monotonic_dominances` | Same meaning as corresponding parameter of `Linear`. |\n| `range_dominances` | Same meaning as corresponding parameter of `Linear`. |\n| `input_min` | Same meaning as corresponding parameter of `Linear`. |\n| `input_max` | Same meaning as corresponding parameter of `Linear`. |\n| `normalization_order` | Same meaning as corresponding parameter of `Linear`. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `from_config`\n\n @classmethod\n from_config(\n config\n )\n\nInstantiates a weight constraint from a configuration dictionary.\n\n#### Example:\n\n constraint = UnitNorm()\n config = constraint.get_config()\n constraint = UnitNorm.from_config(config)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------|--------------------------------------------------|\n| `config` | A Python dictionary, the output of `get_config`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A [`tf.keras.constraints.Constraint`](https://www.tensorflow.org/api_docs/python/tf/keras/constraints/Constraint) instance. ||\n\n\u003cbr /\u003e\n\n### `get_config`\n\n[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/linear_layer.py#L425-L434) \n\n get_config()\n\nStandard Keras get_config() method.\n\n### `__call__`\n\n[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/linear_layer.py#L403-L423) \n\n __call__(\n w\n )\n\nApplies constraints to w.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-----|--------------------------------------------------------------------------------------------------------|\n| `w` | Tensor which represents weights of TFL linear layer. Must have shape: `(len(self.monotonicities), 1)`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|--------------|---------------------------------------------------------|\n| `ValueError` | if shape of `w` is not `(len(self.monotonicities), 1)`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| Tensor `w` with monotonicity constraints and normalization applied to it. ||\n\n\u003cbr /\u003e"]]