# tfl.configs.AggregateFunctionConfig

<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/configs.py#L586-L687) |

Config for aggregate function learning model.

    tfl.configs.AggregateFunctionConfig(
        feature_configs,
        regularizer_configs=None,
        middle_dimension=1,
        middle_lattice_size=2,
        middle_calibration=False,
        middle_calibration_num_keypoints=10,
        middle_calibration_input_keypoints_type='fixed',
        middle_monotonicity=None,
        middle_lattice_interpolation='hypercube',
        aggregation_lattice_interpolation='hypercube',
        output_min=None,
        output_max=None,
        output_calibration=False,
        output_calibration_num_keypoints=10,
        output_initialization='uniform',
        output_calibration_input_keypoints_type='fixed'
    )

### Used in the notebooks

| Used in the tutorials |
|---|
| - [TF Lattice Aggregate Function Models](https://www.tensorflow.org/lattice/tutorials/aggregate_function_models) |

An aggregate function learning model applies piecewise-linear and categorical
calibration on the ragged input features, followed by an aggregation layer
that aggregates the calibrated inputs. Lastly a lattice model and an optional
output piecewise-linear calibration are applied.

#### Example:

    model_config = tfl.configs.AggregateFunctionConfig(
        feature_configs=[...],
    )
    model = tfl.premade.AggregateFunction(model_config)
    model.compile(...)
    model.fit(...)
    model.evaluate(...)

<br />

<br />

<br />

| ## Args ||
|---|---|
| `feature_configs` | A list of [`tfl.configs.FeatureConfig`](https://www.tensorflow.org/lattice/api_docs/python/tfl/configs/FeatureConfig) instances that specify configurations for each feature. |
| `regularizer_configs` | A list of [`tfl.configs.RegularizerConfig`](https://www.tensorflow.org/lattice/api_docs/python/tfl/configs/RegularizerConfig) instances that apply global regularization. |
| `middle_dimension` | The number of calibrated lattices that are applied to each block. The outputs of these lattices are then averaged over the blocks, and the middle_dimension resulting numbers are then passed into the "middle" calibrated lattice. This middle lattice therefore has input dimension equal to middle_dimension. |
| `middle_lattice_size` | Size of each of the middle_lattice dimensions. |
| `middle_calibration` | If a piecewise-linear calibration should be used on the inputs to the middle lattice. |
| `middle_calibration_num_keypoints` | Number of keypoints to use for the middle piecewise-linear calibration. |
| `middle_calibration_input_keypoints_type` | One of "fixed" or "learned_interior". If "learned_interior", keypoints are initialized to the values in `pwl_calibration_input_keypoints` but then allowed to vary during training, with the exception of the first and last keypoint location which are fixed. |
| `middle_monotonicity` | Specifies if the middle calibrators should be monotonic, using 'increasing' or 1 to indicate increasing monotonicity, 'decreasing' or -1 to indicate decreasing monotonicity, and 'none' or 0 to indicate no monotonicity constraints. |
| `middle_lattice_interpolation` | One of 'hypercube' or 'simplex'. For a d-dimensional lattice, 'hypercube' interpolates 2\^d parameters, whereas 'simplex' uses d+1 parameters and thus scales better. For details see [`tfl.lattice_lib.evaluate_with_simplex_interpolation`](https://www.tensorflow.org/lattice/api_docs/python/tfl/lattice_lib/evaluate_with_simplex_interpolation) and [`tfl.lattice_lib.evaluate_with_hypercube_interpolation`](https://www.tensorflow.org/lattice/api_docs/python/tfl/lattice_lib/evaluate_with_hypercube_interpolation). |
| `aggregation_lattice_interpolation` | One of 'hypercube' or 'simplex'. For a d-dimensional lattice, 'hypercube' interpolates 2\^d parameters, whereas 'simplex' uses d+1 parameters and thus scales better. For details see [`tfl.lattice_lib.evaluate_with_simplex_interpolation`](https://www.tensorflow.org/lattice/api_docs/python/tfl/lattice_lib/evaluate_with_simplex_interpolation) and [`tfl.lattice_lib.evaluate_with_hypercube_interpolation`](https://www.tensorflow.org/lattice/api_docs/python/tfl/lattice_lib/evaluate_with_hypercube_interpolation). |
| `output_min` | Lower bound constraint on the output of the model. |
| `output_max` | Upper bound constraint on the output of the model. |
| `output_calibration` | If a piecewise-linear calibration should be used on the output of the lattice. |
| `output_calibration_num_keypoints` | Number of keypoints to use for the output piecewise-linear calibration. |
| `output_initialization` | The initial values to setup for the output of the model. When using output calibration, these values are used to initialize the output keypoints of the output piecewise-linear calibration. Otherwise the lattice parameters will be setup to form a linear function in the range of output_initialization. It can be one of: <br /> - String `'uniform'`: Output is initliazed uniformly in label range. - A list of numbers: To be used for initialization of the output lattice or output calibrator. |
| `output_calibration_input_keypoints_type` | One of "fixed" or "learned_interior". If "learned_interior", keypoints are initialized to the values in `pwl_calibration_input_keypoints` but then allowed to vary during training, with the exception of the first and last keypoint location which are fixed. |

## Methods

### `deserialize_nested_configs`

[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/configs.py#L124-L158)

    @classmethod
    deserialize_nested_configs(
        config, custom_objects=None
    )

Returns a deserialized configuration dictionary.

### `feature_config_by_name`

[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/configs.py#L164-L173)

    feature_config_by_name(
        feature_name
    )

Returns existing or default FeatureConfig with the given name.

### `from_config`

[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/configs.py#L684-L687)

    @classmethod
    from_config(
        config, custom_objects=None
    )

### `get_config`

[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/configs.py#L93-L122)

    get_config()

Returns a configuration dictionary.

### `regularizer_config_by_name`

[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/configs.py#L179-L188)

    regularizer_config_by_name(
        regularizer_name
    )

Returns existing or default RegularizerConfig with the given name.