zonopy.zonotope#

class zonopy.zonotope(Z, dtype=None, device=None)[source]#

Bases: object

1D Zonotope class

A Zonotope is a set of the form

Z:={c+i=1Naigi  |  ai[1,1]}\mathcal{Z} := \left\{c + \sum_{i=1}^{N} a_i g_i \; \middle\vert \; a_i \in [-1,1]\right\}

where cc is the center and gig_i are the generators, each of which is a vector in the same space as cc.

This class defines a basic zonotope and its operations. Z\mathbf{Z} is a tensor of shape (N+1)×d(N+1) \times d where NN is the number of generators and dd is the dimension of the zonotope. The first row of ZZ is the center and the rest are the generators, such that Z=[c,G]T\mathbf{Z} = [c,G]^T. G=[g1,g2,,gN]G = [g_1, g_2, \ldots, g_N] is a matrix of shape N×dN \times d.

__init__(Z, dtype=None, device=None)[source]#

Initialize a zonotope

Parameters:
  • Z (torch.Tensor) – center vector and generator matrix Z=[c,G]T\mathbf{Z} = [c,G]^T

  • dtype (torch.dtype, optional) – data type of Z\mathbf{Z}. If None, the data type is inferred. Defaults to None.

  • device (str, optional) – device of Z\mathbf{Z}. If None, the device is inferred. Defaults to None.

Raises:

AssertionError – If the dimension of Z\mathbf{Z} is not 2

Methods

__init__(Z[, dtype, device])

Initialize a zonotope

cpu()

Change the device of a zonotope to CPU

deleteZerosGenerators([eps])

Delete zero vector generators return <zonotope>

plot(ax[, facecolor, edgecolor, linewidth, dim])

plot 2 dimensional projection of a zonotope self: <zonotope> ax: <Axes> axes oject of a figure to plot facecolor: <string> color of face edgecolor: <string> color of edges

polygon()

Vertice representation as a polygon from a 2-dimensional zonotope

polygon_patch([alpha, facecolor, edgecolor, ...])

polyhedron()

Vertice representation as a polygon from a 3-dimensional zonotope

polyhedron_patch([alpha, facecolor, ...])

polytope([combs])

Half-plane representation of zonotope return, A: <torch.tensor>, shape [,nx] b: <torch.tensor>, shape []

project([dim])

The projection of a zonotope onto the specified dimensions self: <zonotope> dim: <int> or <list> or <torch.Tensor> dimensions for prjection

reduce(order[, option])

slice(slice_dim, slice_pt)

slice zonotope on specified point in a certain dimension self: <zonotope> slice_dim: <torch.Tensor> or <list> or <int> , shape [] slice_pt: <torch.Tensor> or <list> or <float> or <int> , shape [] return <zonotope>

to([dtype, device])

Change the device and data type of a zonotope dtype: torch.float or torch.double device: 'cpu', 'gpu', 'cuda:0', ...

to_interval()

Convert zonotope to interval return <interval>

to_polyZonotope([dim, id])

Convert zonotope to polynomial zonotope self: <zonotope> dim: <int>, dimension to take as sliceable return <polyZonotope>

Attributes

center

The center of a zonotope return <torch.Tensor> , shape [nx]

device

The device of a zonotope properties return 'cpu', 'cuda:0', or ...

dimension

The dimension of a zonotope return <int>, nx

dtype

The data type of a zonotope properties return torch.float or torch.double

generators

Generators of a zonotope return <torch.Tensor> , shape [N, nx]

n_generators

The number of generators of a zonotope return <int>, N

shape

The shape of vector elements (ex.

property center#

The center of a zonotope return <torch.Tensor> , shape [nx]

cpu()[source]#

Change the device of a zonotope to CPU

deleteZerosGenerators(eps=0)[source]#

Delete zero vector generators return <zonotope>

property device#

The device of a zonotope properties return ‘cpu’, ‘cuda:0’, or …

property dimension#

The dimension of a zonotope return <int>, nx

property dtype#

The data type of a zonotope properties return torch.float or torch.double

property generators#

Generators of a zonotope return <torch.Tensor> , shape [N, nx]

property n_generators#

The number of generators of a zonotope return <int>, N

plot(ax, facecolor='none', edgecolor='green', linewidth=0.2, dim=[0, 1])[source]#

plot 2 dimensional projection of a zonotope self: <zonotope> ax: <Axes> axes oject of a figure to plot facecolor: <string> color of face edgecolor: <string> color of edges

ex. import matplotlib.pyplot as plt fig = plt.figure() ax = fig.gca() zono.plot(ax) plt.show()

polygon()[source]#

Vertice representation as a polygon from a 2-dimensional zonotope

return <torch.Tensor>, <torch.float> or <torch.double> , shape [P,2], where P is the number of vertices

polygon_patch(alpha=0.5, facecolor='none', edgecolor='green', linewidth=0.2, dim=[0, 1])[source]#
polyhedron()[source]#

Vertice representation as a polygon from a 3-dimensional zonotope

return <torch.Tensor>, <torch.float> or <torch.double> , shape [P,3], where P is the number of vertices

polyhedron_patch(alpha=0.5, facecolor='none', edgecolor='green', linewidth=0.2)[source]#
polytope(combs=None)[source]#

Half-plane representation of zonotope return, A: <torch.tensor>, shape [,nx] b: <torch.tensor>, shape []

A point, x (torch.Tensor, shape (nx,)), is at outside of a zonotope <-> max(A@x-b)>=0 (you might wanna use 1e-6 as a threshold instead for numerical stability)

A point, x, is inside of a zonotope <-> max(A@x-b)<0

project(dim=[0, 1])[source]#

The projection of a zonotope onto the specified dimensions self: <zonotope> dim: <int> or <list> or <torch.Tensor> dimensions for prjection

return <zonotope>

reduce(order, option='girard')[source]#
property shape#

The shape of vector elements (ex. center) of a zonotope return <tuple>, (nx,)

slice(slice_dim, slice_pt)[source]#

slice zonotope on specified point in a certain dimension self: <zonotope> slice_dim: <torch.Tensor> or <list> or <int> , shape [] slice_pt: <torch.Tensor> or <list> or <float> or <int> , shape [] return <zonotope>

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

Change the device and data type of a zonotope dtype: torch.float or torch.double device: ‘cpu’, ‘gpu’, ‘cuda:0’, …

to_interval()[source]#

Convert zonotope to interval return <interval>

to_polyZonotope(dim=None, id=None)[source]#

Convert zonotope to polynomial zonotope self: <zonotope> dim: <int>, dimension to take as sliceable return <polyZonotope>