zonopy.zonotope#
- class zonopy.zonotope(Z, dtype=None, device=None)[source]#
Bases:
object
1D Zonotope class
A Zonotope is a set of the form
where is the center and are the generators, each of which is a vector in the same space as .
This class defines a basic zonotope and its operations. is a tensor of shape where is the number of generators and is the dimension of the zonotope. The first row of is the center and the rest are the generators, such that . is a matrix of shape .
- __init__(Z, dtype=None, device=None)[source]#
Initialize a zonotope
- Parameters:
Z (torch.Tensor) – center vector and generator matrix
dtype (torch.dtype, optional) – data type of . If
None
, the data type is inferred. Defaults toNone
.device (str, optional) – device of . If
None
, the device is inferred. Defaults toNone
.
- Raises:
AssertionError – If the dimension of 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, ...])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', ...
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
The center of a zonotope return <torch.Tensor> , shape [nx]
The device of a zonotope properties return 'cpu', 'cuda:0', or ...
The dimension of a zonotope return <int>, nx
The data type of a zonotope properties return torch.float or torch.double
Generators of a zonotope return <torch.Tensor> , shape [N, nx]
The number of generators of a zonotope return <int>, N
The shape of vector elements (ex.
- property center#
The center of a zonotope return <torch.Tensor> , shape [nx]
- 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
- 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
- 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>
- 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>