tfl.lattice_layer.LaplacianRegularizer
Stay organized with collections
Save and categorize content based on your preferences.
Laplacian regularizer for tfl.layers.Lattice
layer.
tfl.lattice_layer.LaplacianRegularizer(
lattice_sizes, l1=0.0, l2=0.0
)
Laplacian regularizer penalizes the difference between adjacent vertices in
multi-cell lattice (see
publication).
Consider a 3 x 2 lattice with weights w
:
w[3]-----w[4]-----w[5]
| | |
| | |
w[0]-----w[1]-----w[2]
where the number at each node represents the weight index.
In this case, the laplacian regularizer is defined as:
l1[0] * (|w[1] - w[0]| + |w[2] - w[1]| +
|w[4] - w[3]| + |w[5] - w[4]|) +
l1[1] * (|w[3] - w[0]| + |w[4] - w[1]| + |w[5] - w[2]|) +
l2[0] * ((w[1] - w[0])^2 + (w[2] - w[1])^2 +
(w[4] - w[3])^2 + (w[5] - w[4])^2) +
l2[1] * ((w[3] - w[0])^2 + (w[4] - w[1])^2 + (w[5] - w[2])^2)
Args |
lattice_sizes
|
Lattice sizes of tfl.layers.Lattice to regularize.
|
l1
|
l1 regularization amount. Either single float or list or tuple of
floats to specify different regularization amount per dimension.
|
l2
|
l2 regularization amount. Either single float or list or tuple of
floats to specify different regularization amount per dimension.
|
Raises |
ValueError
|
If provided input does not correspond to lattice_sizes .
|
Methods
from_config
@classmethod
from_config(
config
)
Creates a regularizer from its config.
This method is the reverse of get_config
,
capable of instantiating the same regularizer from the config
dictionary.
This method is used by TF-Keras model_to_estimator
, saving and
loading models to HDF5 formats, TF-Keras model cloning, some
visualization utilities, and exporting models to and from JSON.
Args |
config
|
A Python dictionary, typically the output of get_config.
|
Returns |
A regularizer instance.
|
get_config
View source
get_config()
Standard Keras config for serialization.
__call__
View source
__call__(
x
)
Returns regularization loss for x
.
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.lattice_layer.LaplacianRegularizer\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/lattice_layer.py#L1001-L1074) |\n\nLaplacian regularizer for [`tfl.layers.Lattice`](../../tfl/layers/Lattice) layer. \n\n tfl.lattice_layer.LaplacianRegularizer(\n lattice_sizes, l1=0.0, l2=0.0\n )\n\nLaplacian regularizer penalizes the difference between adjacent vertices in\nmulti-cell lattice (see\n[publication](http://jmlr.org/papers/v17/15-243.html)).\n\nConsider a 3 x 2 lattice with weights `w`: \n\n w[3]-----w[4]-----w[5]\n | | |\n | | |\n w[0]-----w[1]-----w[2]\n\nwhere the number at each node represents the weight index.\nIn this case, the laplacian regularizer is defined as: \n\n l1[0] * (|w[1] - w[0]| + |w[2] - w[1]| +\n |w[4] - w[3]| + |w[5] - w[4]|) +\n l1[1] * (|w[3] - w[0]| + |w[4] - w[1]| + |w[5] - w[2]|) +\n\n l2[0] * ((w[1] - w[0])^2 + (w[2] - w[1])^2 +\n (w[4] - w[3])^2 + (w[5] - w[4])^2) +\n l2[1] * ((w[3] - w[0])^2 + (w[4] - w[1])^2 + (w[5] - w[2])^2)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------|------------------------------------------------------------------------------------------------------------------------------------|\n| `lattice_sizes` | Lattice sizes of [`tfl.layers.Lattice`](../../tfl/layers/Lattice) to regularize. |\n| `l1` | l1 regularization amount. Either single float or list or tuple of floats to specify different regularization amount per dimension. |\n| `l2` | l2 regularization amount. Either single float or list or tuple of floats to specify different regularization amount per dimension. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-----------------------------------------------------------|\n| `ValueError` | If provided input does not correspond to `lattice_sizes`. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `from_config`\n\n @classmethod\n from_config(\n config\n )\n\nCreates a regularizer from its config.\n\nThis method is the reverse of `get_config`,\ncapable of instantiating the same regularizer from the config\ndictionary.\n\nThis method is used by TF-Keras `model_to_estimator`, saving and\nloading models to HDF5 formats, TF-Keras model cloning, some\nvisualization utilities, and exporting models to and from JSON.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------|----------------------------------------------------------|\n| `config` | A Python dictionary, typically 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 regularizer 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/lattice_layer.py#L1068-L1074) \n\n get_config()\n\nStandard Keras config for serialization.\n\n### `__call__`\n\n[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/lattice_layer.py#L1061-L1066) \n\n __call__(\n x\n )\n\nReturns regularization loss for `x`."]]