View source on GitHub |
Implements PWLCalibration with derived parameters (kernels).
pwl_calibration_fn
is similar to tfl.layers.PWLCalibration
with the key
difference that the keypoints are decided by the given parameters instead
of learnable weights belonging to a layer. These parameters can be one of:
- constants,
- trainable variables,
- outputs from other TF modules.
For inputs of shape (batch_size, units)
, two sets of parameters are required
to configure the piece-wise linear calibrator in terms of its x and y values:
keypoint_input_parameters
for configuring the x values,keypoint_output_parameters
for configuring the y values.
This function is a general form of conditional calibration, that one input variable is calibrated based on free form parameters coming from other variables and their transformations.
Shapes:
The last dimension sizes of keypoint_input_parameters
(input_param_size) and
keypoint_output_parameters
(output_param_size) depend on the number of
keypoints used by the calibrator. We follow the relationships that
- input_param_size = # keypoints - 2, as the leftmost and rightmost keypoints are given.
output_param_size = # keypoints initially, and we then modify it by
- if cyclic calibrator: output_param_size -= 1,
- if clamp_min: output_param_size -= 1,
- if clamp_max: output_param_size -= 1,
- if need to learn how to impute missing: output_param_size += 1.
The final shapes need to be broadcast friendly with (batch_size, units, 1)
:
keypoint_input_parameters
:(1 or batch_size, 1 or units, input_param_size)
.keypoint_output_parameters
:(1 or batch_size, 1 or units, output_param_size)
.
Functions
default_keypoint_input_parameters(...)
: Helper creating default keypoint_input_parameters
.
default_keypoint_output_parameters(...)
: Helper creating default keypoint_output_parameters
.
pwl_calibration_fn(...)
: Calibrates inputs
using derived parameters (kernels).