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

#912 - Quadratic map of a zonotope #2218

Merged
merged 15 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from 9 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
1 change: 1 addition & 0 deletions docs/src/lib/sets/Zonotope.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ split(::AbstractZonotope, ::Int)
split(::AbstractZonotope, ::AbstractVector{Int}, ::AbstractVector{Int})
remove_zero_generators(::Zonotope)
linear_map!(::Zonotope, ::AbstractMatrix, ::Zonotope)
quadratic_map(Q::Vector{MT}, Z::Zonotope{N}) where {N, MT<:AbstractMatrix{N}}
```

Inherited from [`LazySet`](@ref):
Expand Down
62 changes: 62 additions & 0 deletions src/Sets/Zonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,65 @@ function linear_map!(Zout::Zonotope, M::AbstractMatrix, Z::Zonotope)
mul!(Zout.generators, M, Z.generators)
return Zout
end

"""
quadratic_map(Q::Vector{MT}, Z::Zonotope{N}) where {N, MT<:AbstractMatrix{N}}

Return the overapproximation of the quadratic map of the given zonotope.
mforets marked this conversation as resolved.
Show resolved Hide resolved
SebastianGuadalupe marked this conversation as resolved.
Show resolved Hide resolved

### Input

- `Z` -- zonotope
- `Q` -- array of square matrices

### Output

The overapproximation of the quadratic map of the given zonotope.
SebastianGuadalupe marked this conversation as resolved.
Show resolved Hide resolved

### Notes

Mathematically, a quadratic map of a zonotope is defined as:

```math
Z_Q = \\right\\{ \\lambda | \\lambda_i = x^T Q\\^{(i)} x, x \\in Z \\left\\}
SebastianGuadalupe marked this conversation as resolved.
Show resolved Hide resolved
```
such that each coordinate ``i`` of the resulting zonotope is influenzed by ``Q\\^{(i)}``
SebastianGuadalupe marked this conversation as resolved.
Show resolved Hide resolved

### Algorithm

This function implements [Lemma 1, 1].

[1] *Matthias Althoff and Bruce H. Krogh. 2012. Avoiding geometric intersection
operations in reachability analysis of hybrid systems. In Proceedings of the
15th ACM international conference on Hybrid Systems: Computation and Control
(HSCC ’12). Association for Computing Machinery, New York, NY, USA, 45–54.*
"""
function quadratic_map(Q::Vector{MT}, Z::Zonotope{N}) where {N, MT<:AbstractMatrix{N}}
@assert length(Q) == dim(Z) "the number of matrices needs to match the dimension of the zonotope"
G = genmat(Z)
c = center(Z)
n, p = size(G)
h = Matrix{N}(undef, n, binomial(p+2, 2)-1)
d = Vector{N}(undef, n)
g(x) = view(G, :, x)
cᵀ = c'
for (i, Qᵢ) in enumerate(Q)
cᵀQᵢ = cᵀ * Qᵢ
Qᵢc = Qᵢ * c
aux = zero(N)
for j=1:p
aux += g(j)' * Qᵢ * g(j)
h[i, j] = cᵀQᵢ * g(j) + g(j)' * Qᵢc
h[i, p+j] = 0.5 * g(j)' * Qᵢ * g(j)
end
d[i] = cᵀQᵢ * c + 0.5 * aux
l = 0
for j=1:p-1
for k=j+1:p
l += 1
h[i, 2p+l] = g(j)' * Qᵢ * g(k) + g(k)' * Qᵢ * g(j)
end
end
schillic marked this conversation as resolved.
Show resolved Hide resolved
end
return Zonotope(d, h)
end