tensorflow_lattice/python/pwl_calibration_layer.py [693:757]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  def __init__(
      self,
      monotonicity="none",
      convexity="none",
      lengths=None,
      output_min=None,
      output_max=None,
      output_min_constraints=pwl_calibration_lib.BoundConstraintsType.NONE,
      output_max_constraints=pwl_calibration_lib.BoundConstraintsType.NONE,
      num_projection_iterations=8):
    """Initializes an instance of `PWLCalibration`.

    Args:
      monotonicity: Same meaning as corresponding parameter of `PWLCalibration`.
      convexity: Same meaning as corresponding parameter of `PWLCalibration`.
      lengths: Lengths of pieces of piecewise linear function. Needed only if
        convexity is specified.
      output_min: Minimum possible output of pwl function.
      output_max: Maximum possible output of pwl function.
      output_min_constraints: A `tfl.pwl_calibration_lib.BoundConstraintsType`
        describing the constraints on the layer's minimum value.
      output_max_constraints: A `tfl.pwl_calibration_lib.BoundConstraintsType`
        describing the constraints on the layer's maximum value.
      num_projection_iterations: Same meaning as corresponding parameter of
        `PWLCalibration`.
    """
    pwl_calibration_lib.verify_hyperparameters(
        output_min=output_min,
        output_max=output_max,
        monotonicity=monotonicity,
        convexity=convexity,
        lengths=lengths)
    self.monotonicity = monotonicity
    self.convexity = convexity
    self.lengths = lengths
    self.output_min = output_min
    self.output_max = output_max
    self.output_min_constraints = output_min_constraints
    self.output_max_constraints = output_max_constraints
    self.num_projection_iterations = num_projection_iterations

    canonical_convexity = utils.canonicalize_convexity(self.convexity)
    canonical_monotonicity = utils.canonicalize_monotonicity(self.monotonicity)
    if (canonical_convexity != 0 and canonical_monotonicity == 0 and
        (output_min_constraints != pwl_calibration_lib.BoundConstraintsType.NONE
         or output_max_constraints !=
         pwl_calibration_lib.BoundConstraintsType.NONE)):
      logging.warning("Convexity constraints are specified with bounds "
                      "constraints, but without monotonicity. Such combination "
                      "might lead to convexity being slightly violated. "
                      "Consider increasing num_projection_iterations to "
                      "reduce violation.")

  def __call__(self, w):
    """Applies constraints to w."""
    return pwl_calibration_lib.project_all_constraints(
        weights=w,
        monotonicity=utils.canonicalize_monotonicity(self.monotonicity),
        output_min=self.output_min,
        output_max=self.output_max,
        output_min_constraints=self.output_min_constraints,
        output_max_constraints=self.output_max_constraints,
        convexity=utils.canonicalize_convexity(self.convexity),
        lengths=self.lengths,
        num_projection_iterations=self.num_projection_iterations)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



tensorflow_lattice/python/pwl_calibration_sonnet_module.py [444:508]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  def __init__(
      self,
      monotonicity="none",
      convexity="none",
      lengths=None,
      output_min=None,
      output_max=None,
      output_min_constraints=pwl_calibration_lib.BoundConstraintsType.NONE,
      output_max_constraints=pwl_calibration_lib.BoundConstraintsType.NONE,
      num_projection_iterations=8):
    """Initializes an instance of `PWLCalibration`.

    Args:
      monotonicity: Same meaning as corresponding parameter of `PWLCalibration`.
      convexity: Same meaning as corresponding parameter of `PWLCalibration`.
      lengths: Lengths of pieces of piecewise linear function. Needed only if
        convexity is specified.
      output_min: Minimum possible output of pwl function.
      output_max: Maximum possible output of pwl function.
      output_min_constraints: A `tfl.pwl_calibration_lib.BoundConstraintsType`
        describing the constraints on the layer's minimum value.
      output_max_constraints: A `tfl.pwl_calibration_lib.BoundConstraintsType`
        describing the constraints on the layer's maximum value.
      num_projection_iterations: Same meaning as corresponding parameter of
        `PWLCalibration`.
    """
    pwl_calibration_lib.verify_hyperparameters(
        output_min=output_min,
        output_max=output_max,
        monotonicity=monotonicity,
        convexity=convexity,
        lengths=lengths)
    self.monotonicity = monotonicity
    self.convexity = convexity
    self.lengths = lengths
    self.output_min = output_min
    self.output_max = output_max
    self.output_min_constraints = output_min_constraints
    self.output_max_constraints = output_max_constraints
    self.num_projection_iterations = num_projection_iterations

    canonical_convexity = utils.canonicalize_convexity(self.convexity)
    canonical_monotonicity = utils.canonicalize_monotonicity(self.monotonicity)
    if (canonical_convexity != 0 and canonical_monotonicity == 0 and
        (output_min_constraints != pwl_calibration_lib.BoundConstraintsType.NONE
         or output_max_constraints !=
         pwl_calibration_lib.BoundConstraintsType.NONE)):
      logging.warning("Convexity constraints are specified with bounds "
                      "constraints, but without monotonicity. Such combination "
                      "might lead to convexity being slightly violated. "
                      "Consider increasing num_projection_iterations to "
                      "reduce violation.")

  def __call__(self, w):
    """Applies constraints to w."""
    return pwl_calibration_lib.project_all_constraints(
        weights=w,
        monotonicity=utils.canonicalize_monotonicity(self.monotonicity),
        output_min=self.output_min,
        output_max=self.output_max,
        output_min_constraints=self.output_min_constraints,
        output_max_constraints=self.output_max_constraints,
        convexity=utils.canonicalize_convexity(self.convexity),
        lengths=self.lengths,
        num_projection_iterations=self.num_projection_iterations)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



