# tfl.linear_layer.LinearConstraints

<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/linear_layer.py#L350-L434) |

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.

<br />

<br />

<br />

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

<br />

## 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)

<br />

<br />

<br />

| Args ||
|---|---|
| `config` | A Python dictionary, the output of `get_config`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A [`tf.keras.constraints.Constraint`](https://www.tensorflow.org/api_docs/python/tf/keras/constraints/Constraint) instance. ||

<br />

### `get_config`

[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/linear_layer.py#L425-L434)

    get_config()

Standard Keras get_config() method.

### `__call__`

[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/linear_layer.py#L403-L423)

    __call__(
        w
    )

Applies constraints to w.

<br />

<br />

<br />

| Args ||
|---|---|
| `w` | Tensor which represents weights of TFL linear layer. Must have shape: `(len(self.monotonicities), 1)`. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ValueError` | if shape of `w` is not `(len(self.monotonicities), 1)`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| Tensor `w` with monotonicity constraints and normalization applied to it. ||

<br />