Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cartesian_product for SparsePolynomialZonotope #3438

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/src/lib/concrete_binary_operations/cartesian_product.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ CurrentModule = LazySets
cartesian_product(::VPolytope, ::VPolytope)
cartesian_product(::LazySet, ::LazySet)
cartesian_product(::SimpleSparsePolynomialZonotope, ::SimpleSparsePolynomialZonotope)
cartesian_product(::SparsePolynomialZonotope, ::SparsePolynomialZonotope)
cartesian_product(::SparsePolynomialZonotope, ::AbstractZonotope)
```
69 changes: 69 additions & 0 deletions src/ConcreteOperations/cartesian_product.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ Compute the Cartesian product of two simple sparse polynomial zonotopes.
### Output

The Cartesian product of `P1` and `P2`.

### Algorithm

This method implements Proposition 3.1.22 in [1].

[1] Kochdumper, Niklas. *Extensions of polynomial zonotopes and their application
to verification of cyber-physical systems.* PhD diss., Technische Universität
München, 2022.
"""
function cartesian_product(P1::SimpleSparsePolynomialZonotope,
P2::SimpleSparsePolynomialZonotope)
Expand All @@ -224,3 +232,64 @@ function cartesian_product(P1::SimpleSparsePolynomialZonotope,
E = cat(expmat(P1), expmat(P2); dims=(1, 2))
return SimpleSparsePolynomialZonotope(c, G, E)
end

"""
cartesian_product(P1::SparsePolynomialZonotope, P2::SparsePolynomialZonotope)

Compute the Cartesian product of two sparse polynomial zonotopes.

### Input

- `P1` -- sparse polynomial zonotope
- `P2` -- sparse polynomial zonotope

### Output

The Cartesian product of `P1` and `P2`.

### Algorithm

This method implements Proposition 3.1.22 in [1].

[1] Kochdumper, Niklas. *Extensions of polynomial zonotopes and their application
to verification of cyber-physical systems.* PhD diss., Technische Universität
München, 2022.
"""
function cartesian_product(P1::SparsePolynomialZonotope, P2::SparsePolynomialZonotope)
c = vcat(center(P1), center(P2))
G = cat(genmat_dep(P1), genmat_dep(P2); dims=(1, 2))
GI = cat(genmat_indep(P1), genmat_indep(P2); dims=(1, 2))
E = cat(expmat(P1), expmat(P2); dims=(1, 2))
return SparsePolynomialZonotope(c, G, GI, E)
end

"""
cartesian_product(SPZ::SparsePolynomialZonotope, Z::AbstractZonotope)

Compute the Cartesian product of a sparse polynomial zonotope and a zonotopic set.

### Input

- `SPZ` -- sparse polynomial zonotope
- `Z` -- zonotopic set

### Output

The Cartesian product of `SPZ` and `Z`.

### Algorithm

This method implements Proposition 3.1.22 in [1].

[1] Kochdumper, Niklas. *Extensions of polynomial zonotopes and their application
to verification of cyber-physical systems.* PhD diss., Technische Universität
München, 2022.
"""
@commutative function cartesian_product(SPZ::SparsePolynomialZonotope, Z::AbstractZonotope)
c = vcat(center(SPZ), center(Z))
G1 = genmat_dep(SPZ)
G = vcat(G1, zeros(eltype(G1), size(G1)))
GI = cat(genmat_indep(SPZ), genmat(Z); dims=(1, 2))
E = expmat(SPZ)
return SparsePolynomialZonotope(c, G, GI, E)
end
15 changes: 12 additions & 3 deletions src/ConcreteOperations/exact_sum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@ Compute the exact sum of sparse polyomial zonotopes ``P₁`` and ``P₂``.
### Output

A `SparsePolynomialZonotope` representing the exact sum ``P₁ ⊞ P₂``.

### Algorithm

This method implements Proposition 3.1.20 in [1].

[1] Kochdumper, Niklas. *Extensions of polynomial zonotopes and their application
to verification of cyber-physical systems.* PhD diss., Technische Universität
München, 2022.
"""
function exact_sum(P1::SparsePolynomialZonotope, P2::SparsePolynomialZonotope)
indexvector(P1) == indexvector(P2) || throw(ArgumentError("the exact sum " *
"is currently only implemented for sparse polynomial zonotopes with " *
"the same index vector"))
if indexvector(P1) != indexvector(P2)
throw(ArgumentError("the exact sum is currently only implemented for " *
"sparse polynomial zonotopes with the same index vector"))
end

c = center(P1) + center(P2)
G = hcat(genmat_dep(P1), genmat_dep(P2))
Expand Down
25 changes: 25 additions & 0 deletions test/Sets/SparsePolynomialZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@ for N in [Float64, Float32, Rational{Int}]
@test genmat_indep(TPZ) == genmat_indep(TPZ)
@test expmat(TPZ) == expmat(TPZ)

CPPZ = cartesian_product(PZ, PZ2)
@test center(CPPZ) == N[4, 4, 0, 0]
@test genmat_dep(CPPZ) == N[2 1 2 0 0 0;
0 2 2 0 0 0;
0 0 0 2 0 1;
0 0 0 1 2 1]
@test genmat_indep(CPPZ) == hcat(N[1, 0, 0, 0])
@test expmat(CPPZ) == [1 0 3 0 0 0;
0 1 1 0 0 0;
0 0 0 1 0 1;
0 0 0 0 1 3]
Z = overapproximate(PZ2, Zonotope)
CPPZ = cartesian_product(PZ, Z)
@test center(CPPZ) == N[4, 4, 0, 0]
@test genmat_dep(CPPZ) == N[2 1 2;
0 2 2;
0 0 0;
0 0 0]
@test genmat_indep(CPPZ) == N[1 0 0 0;
0 0 0 0;
0 2 0 1;
0 1 2 1]
@test expmat(CPPZ) == [1 0 3;
0 1 1]

MSPZ = minkowski_sum(PZ, PZ2)
@test center(MSPZ) == [4, 4]
@test genmat_dep(MSPZ) == [2 1 2 2 0 1; 0 2 2 1 2 1]
Expand Down
Loading