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

linear combination and convex hull on sspz #2979

Merged
merged 7 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions docs/src/lib/sets/SimpleSparsePolynomialZonotope.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ order(::SimpleSparsePolynomialZonotope)
linear_map(::AbstractMatrix, ::SimpleSparsePolynomialZonotope)
minkowski_sum(::SimpleSparsePolynomialZonotope, ::SimpleSparsePolynomialZonotope)
cartesian_product(::SimpleSparsePolynomialZonotope, ::SimpleSparsePolynomialZonotope)
linear_combination(::SimpleSparsePolynomialZonotope, ::SimpleSparsePolynomialZonotope)
convex_hull(::SimpleSparsePolynomialZonotope, ::SimpleSparsePolynomialZonotope)
convex_hull(::SimpleSparsePolynomialZonotope)
```
35 changes: 35 additions & 0 deletions src/ConcreteOperations/convex_hull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,38 @@ end
convex_hull(X::LazySet, ::EmptySet) = X
convex_hull(::EmptySet, X::LazySet) = X
convex_hull(∅::EmptySet, ::EmptySet) = ∅

"""
convex_hull(P1::SimpleSparsePolynomialZonotope, P2::SimpleSparsePolynomialZonotope)

Computes the convex hull of the simple sparse polynomial zonotopes `P1` and `P2`.

### Input

- `P1` : simple sparse polynomial zonotopes
- `P2` : simple sparse polynomial zonotopes

### Output

Tightest convex simple sparse polynomial zonotope containing `P1` and `P2`.
"""
function convex_hull(P1::SimpleSparsePolynomialZonotope, P2::SimpleSparsePolynomialZonotope)
return linear_combination(linear_combination(P1, P1), linear_combination(P2, P2))
end

"""
convex_hull(P::SimpleSparsePolynomialZonotope)

Computes the convex hull of the simple sparse polynomial zonotope `P`.

### Input

- `P` -- simple sparse polynomial zonotopes

### Output

Tightest convex simple sparse polynomial zonotope containing `P`.
"""
function convex_hull(P::SimpleSparsePolynomialZonotope)
return linear_combination(P, P)
end
37 changes: 37 additions & 0 deletions src/ConcreteOperations/linear_combination.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export linear_combination

"""
linear_combination(P1::SimpleSparsePolynomialZonotope, P2::SimpleSparsePolynomialZonotope)

compute the linear combination of simple sparse polynomial zonotopes `P1` and `P2`.

### Input

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

### Output

linear combination of `P1` and `P2`.

### Notes

The linear combination of two sets ``P₁`` and ``P₂`` is defined as

```math
\\{λp₁ + (1-λ)p₂ | p₁ ∈ P₁, p₂ ∈ P₂, λ ∈ [0, 1]\\}
lucaferranti marked this conversation as resolved.
Show resolved Hide resolved
```
"""
function linear_combination(P1::SimpleSparsePolynomialZonotope, P2::SimpleSparsePolynomialZonotope)
lucaferranti marked this conversation as resolved.
Show resolved Hide resolved
c = 0.5 * (center(P1) + center(P2))
G = 0.5 * hcat(center(P1) - center(P2), genmat(P1), genmat(P1), genmat(P2), -genmat(P2))
E1, E2 = expmat(P1), expmat(P2)
et = promote_type(eltype(E1), eltype(E2))
E = hcat(vcat(zeros(et, nparams(P1) + nparams(P2)), one(et)),
vcat(E1, zeros(et, nparams(P2) + 1, ngens(P1))),
vcat(E2, zeros(et, nparams(P2), ngens(P1)), ones(et, 1, ngens(P1))),
vcat(zeros(et, nparams(P1), ngens(P2)), E2, zeros(et, 1, ngens(P2))),
vcat(zeros(et, nparams(P1), ngens(P2)), E2, ones(et, 1, ngens(P2))))
schillic marked this conversation as resolved.
Show resolved Hide resolved
mforets marked this conversation as resolved.
Show resolved Hide resolved

return SimpleSparsePolynomialZonotope(c, G, E)
end
1 change: 1 addition & 0 deletions src/LazySets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ include("ConcreteOperations/intersection.jl")
include("ConcreteOperations/isdisjoint.jl")
include("ConcreteOperations/issubset.jl")
include("ConcreteOperations/isstrictsubset.jl")
include("ConcreteOperations/linear_combination.jl")
include("ConcreteOperations/minkowski_difference.jl")
include("ConcreteOperations/minkowski_sum.jl")
include("Utils/samples.jl")
Expand Down