abc

compression_safeguards.safeguards.abc

Abstract base class for the safeguards.

Classes:

  • Safeguard

    Safeguard abstract base class.

Safeguard

Bases: ABC

flowchart LR compression_safeguards.safeguards.abc.Safeguard[Safeguard] click compression_safeguards.safeguards.abc.Safeguard href "" "compression_safeguards.safeguards.abc.Safeguard"

Safeguard abstract base class.

Methods:

  • check

    Check if the approximation array upholds the property enforced by this

  • get_config

    Returns the configuration of the safeguard.

  • from_config

    Instantiate the safeguard from a configuration dict.

kind class-attribute

kind: str

Safeguard kind.

late_bound abstractmethod property

late_bound: Set[Parameter]

The set of late-bound parameters that this safeguard has.

Late-bound parameters are only bound when checking and applying the safeguard, in contrast to the normal early-bound parameters that are configured during safeguard initialisation.

Late-bound parameters can be used for parameters that depend on the specific data that is to be safeguarded.

check abstractmethod

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.

get_config abstractmethod

get_config() -> dict[str, JSON]

Returns the configuration of the safeguard.

The config must include a 'kind' field with the safeguard kind. All values must be compatible with JSON encoding.

Returns:
  • config( dict[str, JSON] ) –

    Configuration of the safeguard.

from_config classmethod

from_config(config: dict[str, JSON]) -> Self

Instantiate the safeguard from a configuration dict.

Parameters:
  • config (dict[str, JSON]) –

    Configuration of the safeguard.

Returns:
  • safeguard( Self ) –

    Instantiated safeguard.