|View source on GitHub|
Jointly projects into all supported constraints.
tfl.pwl_calibration_lib.project_all_constraints( weights, monotonicity, output_min, output_max, output_min_constraints, output_max_constraints, convexity, lengths, num_projection_iterations=8 )
For all combinations of constraints except the case where bounds constraints are specified without monotonicity constraints we properly project into nearest point with respect to L2 norm. For later case we use a heuristic to map input point into some feasible point with no guarantees on how close this point is to the true projection.
If only bounds or only monotonicity constraints are specified there will be a single step projection. For all other combinations of constraints we use num_projection_iterations iterations of Dykstra's alternating projection algorithm to jointly project onto all the given constraints. Dykstra's algorithm gives us proper projection with respect to L2 norm but approaches it from "wrong" side. That's why in order to ensure that constraints are strictly met we'll do approximate projections in the end which project strictly into feasible space, but it's not an exact projection with respect to the L2 norm. With enough iterations of the Dykstra's algorithm, the impact of such approximate projection should be negligible.
With bound and convexity constraints and no specified monotonicity, this method does not fully satisfy the constrains. Increasing the number of iterations can reduce the constraint violation in such cases.
(num_keypoints, units)-shape tensor which represents weights of PWL calibration layer.
monotonicity: 1 for increasing, -1 for decreasing, 0 for no monotonicity constraints.
output_min: Lower bound constraint of PWL calibration layer.
output_max: Upper bound constraint of PWL calibration layer.
tfl.pwl_calibration_lib.BoundConstraintsTypedescribing the constraints on the layer's minimum value.
tfl.pwl_calibration_lib.BoundConstraintsTypedescribing the constraints on the layer's maximum value.
convexity: 1 for convex, -1 for concave, 0 for no convexity constraints.
lengths: Lengths of pieces of piecewise linear function. Needed only if convexity projection is specified.
num_projection_iterations: Number of iterations of Dykstra's alternating projection algorithm.
Projected weights tensor.