utils
pytorch_lattice.utils.data
Utility functions and classes for handling data.
Dataset
Bases: Dataset
A class for loading a dataset for a calibrated model.
Source code in pytorch_lattice/utils/data.py
__init__(X, y, features)
Initializes an instance of Dataset
.
Source code in pytorch_lattice/utils/data.py
prepare_features(X, features)
Maps categorical features to their integer indices in place.
Source code in pytorch_lattice/utils/data.py
pytorch_lattice.utils.models
Utility functions for use in model classes.
calibrate_and_stack(x, calibrators)
Helper function to run calibrators along columns of given data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
The input tensor of feature values of shape |
required |
calibrators |
ModuleDict
|
A dictionary of calibrator functions. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
A torch.Tensor resulting from applying the calibrators and stacking the results. |
Source code in pytorch_lattice/utils/models.py
initialize_feature_calibrators(features, output_min=None, output_max=None)
Helper function to initialize calibrators for calibrated model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features |
list[Union[NumericalFeature, CategoricalFeature]]
|
A list of numerical and/or categorical feature configs. |
required |
output_min |
Optional[float]
|
The minimum output value for the model. If |
None
|
output_max |
Union[Optional[float], list[Optional[float]]]
|
A list of maximum output value for each feature of the model. If
|
None
|
Returns:
Type | Description |
---|---|
ModuleDict
|
A |
Raises:
Type | Description |
---|---|
ValueError
|
If any feature configs are not |
Source code in pytorch_lattice/utils/models.py
initialize_monotonicities(features)
Helper function to initialize monotonicities for calibrated model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features |
list[Union[NumericalFeature, CategoricalFeature]]
|
A list of numerical and/or categorical feature configs. |
required |
Returns:
Type | Description |
---|---|
list[Optional[Monotonicity]]
|
A list of |
list[Optional[Monotonicity]]
|
each feature has a monotonicity or not. |
Source code in pytorch_lattice/utils/models.py
initialize_output_calibrator(monotonic, output_calibration_num_keypoints, output_min=None, output_max=None)
Helper function to initialize output calibrator for calibrated model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
monotonic |
bool
|
Whether output calibrator should have monotonicity constraint. |
required |
output_calibration_num_keypoints |
Optional[int]
|
The number of keypoints in output
calibrator. If |
required |
output_min |
Optional[float]
|
The minimum output value for the model. If |
None
|
output_max |
Optional[float]
|
The maximum output value for the model. If |
None
|
Returns:
Type | Description |
---|---|
Optional[NumericalCalibrator]
|
A |
Raises:
Type | Description |
---|---|
ValueError
|
If any feature configs are not |