API Reference

Zonotope Class

class zonotope.zonotope.Zonotope(center, infinity_terms=None, special_terms=None, special_norm=2, clone=True)[source]

Bases: object

Implementation of the multi-norm Zonotope base object with N variables.

The special norm is p, its dual counterpart is q. The number of special error terms is Es, and the number of infinity terms is Ei.

Weights are stored in three matrices: - W_C: center (bias), shape: (N) - W_Ei: infinity terms, shape: (N Ei) - W_Es: special terms, shape: (N Es)

Parameters:
  • center (Float[Tensor, '...'])

  • infinity_terms (Float[Tensor, '... Ei'] | None)

  • special_terms (Float[Tensor, '... Es'] | None)

  • special_norm (int)

  • clone (bool)

__init__(center, infinity_terms=None, special_terms=None, special_norm=2, clone=True)[source]

Initialize a zonotope.

Parameters:
  • center (Float[Tensor, '...']) – Center point of the zonotope (bias)

  • infinity_terms (Float[Tensor, '... Ei'] | None) – Coefficient matrix for infinity-norm error terms

  • special_terms (Float[Tensor, '... Es'] | None) – Coefficient matrix for special (p-norm) error terms

  • special_norm (int) – The p value for the special error terms (default: 2)

  • clone (bool) – Whether to clone the input tensors (default: True)

Return type:

None

property E: int

Total number of error terms (special + infinity).

property Es: int

Number of special (p-norm) error terms.

property Ei: int

Number of infinity-norm error terms.

property N: int

Total number of variables in the zonotope.

property shape: Size

Shape of the center tensor.

property device: device

Device of the tensors.

property dtype: dtype

Data type of the tensors.

classmethod from_values(center, infinity_terms=None, special_terms=None, special_norm=2)[source]

Create a zonotope from various input types, converting to tensors as needed.

Parameters:
  • center (Any) – Center point values (will be converted to tensor)

  • infinity_terms (Any) – Values for infinity-norm error terms

  • special_terms (Any) – Values for special p-norm error terms

  • special_norm (int) – The p value for special error terms

Returns:

A new Zonotope instance

Return type:

Zonotope

classmethod from_bounds(lower, upper, special_norm=2)[source]

Create a zonotope from lower and upper bounds.

Parameters:
  • lower (Any) – Lower bounds

  • upper (Any) – Upper bounds

  • special_norm (int) – The p value for special error terms

Returns:

A new Zonotope instance

Return type:

Zonotope

concretize()[source]

Computer lower and upper bounds of the zonotope (Section 4.1)

Return type:

Tuple[Float[Tensor, ‘…’], Float[Tensor, ‘…’]]

expand_infinity_error_terms(n_infinity_terms)[source]

Expand the number of infinity error terms to the specified value.

! Will be updated with a better strategy soon

Parameters:

n_infinity_terms (int)

Return type:

None

clone(center=None, infinity_terms=None, special_terms=None, special_norm=None)[source]
Parameters:
  • center (Float[Tensor, '...'] | None)

  • infinity_terms (Float[Tensor, '... Ei'] | None)

  • special_terms (Float[Tensor, '... Es'] | None)

  • special_norm (int | None)

Return type:

Zonotope

add(other)[source]
Parameters:

other (Zonotope | float | int | Tensor)

Return type:

Zonotope

mul(other)[source]

Multiply this zonotope by a scalar in-place

Parameters:

other (float | int | Tensor)

Return type:

Zonotope

div(other)[source]
Parameters:

other (float | int | Tensor)

Return type:

Zonotope

sub(other)[source]
Parameters:

other (Zonotope | float | int | Tensor)

Return type:

Zonotope

rsub(other)[source]
Parameters:

other (Zonotope | float | int | Tensor)

Return type:

Zonotope

sample_point(n_samples=1, use_binary_weights=False, include_special_terms=True, include_infinity_terms=True)[source]

Sample points from within the zonotope.

Parameters:
  • n_samples (int) – Number of points to sample

  • use_binary_weights (bool) – Whether to use binary weights (corners of the zonotope)

  • include_special_terms (bool) – Whether to include special error terms

  • include_infinity_terms (bool) – Whether to include infinity error terms

Returns:

Tensor of sampled points with shape (n_samples, *self.shape)

Return type:

Float[Tensor, ‘S …’]

rearrange(pattern, **kwargs)[source]

Einops rearrange

Parameters:

pattern (str)

Return type:

Zonotope

repeat(pattern, **kwargs)[source]

Einops repeat

Parameters:

pattern (str)

Return type:

Zonotope

einsum(other, pattern, **kwargs)[source]

Einops einsum

Parameters:
Return type:

Zonotope

sum(dim, **kwargs)[source]

Torch sum

Parameters:

dim (int)

Return type:

Zonotope

to(device=None, dtype=None)[source]

Torch to

Parameters:
Return type:

Zonotope

contiguous()[source]

Torch contiguous

Return type:

None

__getitem__(key)[source]
__repr__()[source]

Return repr(self).

Return type:

str

__len__()[source]
Return type:

int

__add__(other)
Parameters:

other (Zonotope | float | int | Tensor)

Return type:

Zonotope

__radd__(other)
Parameters:

other (Zonotope | float | int | Tensor)

Return type:

Zonotope

__mul__(other)

Multiply this zonotope by a scalar in-place

Parameters:

other (float | int | Tensor)

Return type:

Zonotope

__rmul__(other)

Multiply this zonotope by a scalar in-place

Parameters:

other (float | int | Tensor)

Return type:

Zonotope