abc

compression_safeguards.safeguards.pointwise.abc

Abstract base class for the pointwise safeguards.

Classes:

PointwiseSafeguard

Bases: Safeguard, ABC

flowchart LR compression_safeguards.safeguards.pointwise.abc.PointwiseSafeguard[PointwiseSafeguard] compression_safeguards.safeguards.abc.Safeguard[Safeguard] compression_safeguards.safeguards.abc.Safeguard --> compression_safeguards.safeguards.pointwise.abc.PointwiseSafeguard click compression_safeguards.safeguards.pointwise.abc.PointwiseSafeguard href "" "compression_safeguards.safeguards.pointwise.abc.PointwiseSafeguard" click compression_safeguards.safeguards.abc.Safeguard href "" "compression_safeguards.safeguards.abc.Safeguard"

Pointwise safeguard abstract base class.

Pointwise safeguards describe properties that are satisfied (or not) per element, i.e. independent of other elements.

Methods:

  • check

    Check if the approximation array upholds the property enforced by this

  • check_pointwise

    Check which elements in the approximation array uphold the property

  • compute_safe_intervals

    Compute the intervals in which the safeguard's guarantees with respect

  • compute_footprint

    Compute the footprint of the foot array, e.g. for expanding data

  • compute_inverse_footprint

    Compute the inverse footprint of the foot array, e.g. for expanding

check

check(
    data: ndarray[S, dtype[T]],
    approximation: ndarray[S, dtype[T]],
    *,
    late_bound: Bindings,
    where: Literal[True] | ndarray[S, dtype[bool]] = True,
) -> bool

Check if the approximation array upholds the property enforced by this safeguard.

Parameters:
  • data (ndarray[S, dtype[T]]) –

    Original data array, relative to which the approximation is checked.

  • approximation (ndarray[S, dtype[T]]) –

    Approximation of the data array.

  • late_bound (Bindings) –

    Bindings for late-bound parameters, including for this safeguard.

  • where (Literal[True] | ndarray[S, dtype[bool]], default: True ) –

    Only check at data points where the condition is True.

Returns:
  • ok( bool ) –

    True if the check succeeded.

check_pointwise abstractmethod

check_pointwise(
    data: ndarray[S, dtype[T]],
    approximation: ndarray[S, dtype[T]],
    *,
    late_bound: Bindings,
    where: Literal[True] | ndarray[S, dtype[bool]] = True,
) -> ndarray[S, dtype[bool]]

Check which elements in the approximation array uphold the property enforced by this safeguard.

Parameters:
  • data (ndarray[S, dtype[T]]) –

    Original data array, relative to which the approximation is checked.

  • approximation (ndarray[S, dtype[T]]) –

    Approximation of the data array.

  • late_bound (Bindings) –

    Bindings for late-bound parameters, including for this safeguard.

  • where (Literal[True] | ndarray[S, dtype[bool]], default: True ) –

    Only check at data points where the condition is True.

Returns:
  • ok( ndarray[S, dtype[bool]] ) –

    Pointwise, True if the check succeeded for this element.

compute_safe_intervals abstractmethod

compute_safe_intervals(
    data: ndarray[S, dtype[T]],
    *,
    late_bound: Bindings,
    where: Literal[True] | ndarray[S, dtype[bool]] = True,
) -> IntervalUnion[T, int, int]

Compute the intervals in which the safeguard's guarantees with respect to the data are upheld.

The returned union of intervals must not have any overlap between the intervals inside the union. The data must be contained in the union.

Parameters:
  • data (ndarray[S, dtype[T]]) –

    Data for which the safe intervals should be computed.

  • late_bound (Bindings) –

    Bindings for late-bound parameters, including for this safeguard.

  • where (Literal[True] | ndarray[S, dtype[bool]], default: True ) –

    Only compute the safe intervals at data points where the condition is True.

Returns:
  • intervals( IntervalUnion[T, int, int] ) –

    Union of intervals in which the safeguard's guarantees are upheld.

compute_footprint abstractmethod

compute_footprint(
    foot: ndarray[S, dtype[bool]],
    *,
    late_bound: Bindings,
    where: Literal[True] | ndarray[S, dtype[bool]] = True,
) -> ndarray[S, dtype[bool]]

Compute the footprint of the foot array, e.g. for expanding data points into the pointwise checks that they contribute to.

For pointwise safeguards, the footprint should be equivalent to foot & where.

Parameters:
  • foot (ndarray[S, dtype[bool]]) –

    Array for which the footprint is computed.

  • late_bound (Bindings) –

    Bindings for late-bound parameters, including for this safeguard.

  • where (Literal[True] | ndarray[S, dtype[bool]], default: True ) –

    Only compute the footprint at pointwise checks where the condition is True.

Returns:

compute_inverse_footprint abstractmethod

compute_inverse_footprint(
    foot: ndarray[S, dtype[bool]],
    *,
    late_bound: Bindings,
    where: Literal[True] | ndarray[S, dtype[bool]] = True,
) -> ndarray[S, dtype[bool]]

Compute the inverse footprint of the foot array, e.g. for expanding pointwise check fails into the points that could have contributed to the failures.

For pointwise safeguards, the inverse footprint should be equivalent to foot & where.

Parameters:
  • foot (ndarray[S, dtype[bool]]) –

    Array for which the inverse footprint is computed.

  • late_bound (Bindings) –

    Bindings for late-bound parameters, including for this safeguard.

  • where (Literal[True] | ndarray[S, dtype[bool]], default: True ) –

    Only compute the inverse footprint at pointwise checks where the condition is True.

Returns: