# tfl.lattice_layer.LinearInitializer

<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_layer.py#L653-L737) |

Initializes a [`tfl.layers.Lattice`](https://www.tensorflow.org/lattice/api_docs/python/tfl/layers/Lattice) as linear function.

    tfl.lattice_layer.LinearInitializer(
        lattice_sizes, monotonicities, output_min, output_max, unimodalities=None
    )

- The linear function will have positive coefficients for monotonic dimensions and 0 otherwise. If all dimensions are unconstrained, all coefficients will be positive.
- Linear coefficients are set such that the minimum/maximum output of the lattice matches the given output_min/output_max.
- Each monotonic dimension contributes with same weight regardless of number of vertices per dimension.
- No dimension can be both monotonic and unimodal.
- Unimodal dimensions contribute with same weight as monotonic dimensions.
- Unimodal dimensions linearly decrease for first `(dim_size + 1) // 2` vertices and then linearly increase for following vertices.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `lattice_sizes` | Lattice sizes of [`tfl.layers.Lattice`](https://www.tensorflow.org/lattice/api_docs/python/tfl/layers/Lattice) to initialize. |
| `monotonicities` | Monotonic dimensions for initialization. Does not need to match `monotonicities` of [`tfl.layers.Lattice`](https://www.tensorflow.org/lattice/api_docs/python/tfl/layers/Lattice). |
| `output_min` | Minimum layer output after initialization. |
| `output_max` | Maximum layer output after initialization. |
| `unimodalities` | None or unimodal dimensions after initialization. Does not need to match `unimodalities` of [`tfl.layers.Lattice`](https://www.tensorflow.org/lattice/api_docs/python/tfl/layers/Lattice). |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If there is a mismatch between `monotonicities` and `lattice_sizes`. |

<br />

## Methods

### `from_config`

    @classmethod
    from_config(
        config
    )

Instantiates an initializer from a configuration dictionary.

#### Example:

    initializer = RandomUniform(-1, 1)
    config = initializer.get_config()
    initializer = RandomUniform.from_config(config)

<br />

<br />

<br />

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

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| An `Initializer` instance. ||

<br />

### `get_config`

[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/lattice_layer.py#L728-L737)

    get_config()

Standard Keras config for serialization.

### `__call__`

[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/lattice_layer.py#L708-L726)

    __call__(
        shape, dtype=None, partition_info=None
    )

Returns weights of [`tfl.layers.Lattice`](https://www.tensorflow.org/lattice/api_docs/python/tfl/layers/Lattice) layer.

<br />

<br />

<br />

| Args ||
|---|---|
| `shape` | Must be: `(prod(lattice_sizes), units)`. |
| `dtype` | Standard Keras initializer param. |
| `partition_info` | Standard Keras initializer param. Not used. |

<br />