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

Remove redundant generators in zonotope overapproximations #3446

Merged
merged 4 commits into from
Mar 18, 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
36 changes: 19 additions & 17 deletions src/Approximations/overapproximate_zonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ A zonotope.
"""
function overapproximate(P::SparsePolynomialZonotope, ::Type{<:Zonotope})
cnew, Gnew = _zonotope_overapprox(center(P), genmat_dep(P), expmat(P))
return Zonotope(cnew, hcat(Gnew, genmat_indep(P)))
Z = Zonotope(cnew, hcat(Gnew, genmat_indep(P)))
Zred = remove_redundant_generators(Z)
return Zred
end

"""
Expand Down Expand Up @@ -380,7 +382,7 @@ function load_taylormodels_overapproximation()

"""
overapproximate(vTM::Vector{TaylorModel1{T, S}}, ::Type{<:Zonotope};
[remove_zero_generators]::Bool=true
[remove_redundant_generators]::Bool=true
[normalize]::Bool=true) where {T, S}

Overapproximate a Taylor model in one variable with a zonotope.
Expand All @@ -389,8 +391,8 @@ function load_taylormodels_overapproximation()

- `vTM` -- vector of `TaylorModel1`
- `Zonotope` -- target set type
- `remove_zero_generators` -- (optional; default: `true`) flag to remove zero
generators of the resulting zonotope
- `remove_redundant_generators` -- (optional; default: `true`) flag to remove
redundant generators of the resulting zonotope
- `normalize` -- (optional; default: `true`) flag to skip the normalization of
the Taylor models

Expand Down Expand Up @@ -527,16 +529,16 @@ function load_taylormodels_overapproximation()
normalization onto the symmetric intervals ``[-1, 1]``.
"""
function overapproximate(vTM::Vector{TaylorModel1{T,S}}, ::Type{<:Zonotope};
remove_zero_generators::Bool=true,
remove_redundant_generators::Bool=true,
normalize::Bool=true) where {T,S}
return _overapproximate_vTM_zonotope(vTM, 1, T;
remove_zero_generators=remove_zero_generators,
remove_redundant_generators=remove_redundant_generators,
normalize=normalize)
end

"""
overapproximate(vTM::Vector{TaylorModelN{N, T, S}}, ::Type{<:Zonotope};
[remove_zero_generators]::Bool=true
[remove_redundant_generators]::Bool=true
[normalize]::Bool=true) where {N, T, S}


Expand All @@ -546,8 +548,8 @@ function load_taylormodels_overapproximation()

- `vTM` -- vector of `TaylorModelN`
- `Zonotope` -- target set type
- `remove_zero_generators` -- (optional; default: `true`) flag to remove zero
generators of the resulting zonotope
- `remove_redundant_generators` -- (optional; default: `true`) flag to remove
redundant generators of the resulting zonotope
- `normalize` -- (optional; default: `true`) flag to skip the normalization of
the Taylor models

Expand Down Expand Up @@ -604,26 +606,26 @@ function load_taylormodels_overapproximation()
124.0

julia> Matrix(genmat(Z))
4 Matrix{Float64}:
0.0 -1.0 5.0 0.0
1.5 0.0 0.0 123.0
2 Matrix{Float64}:
0.0 -6.0
124.5 0.0
```

### Algorithm

We refer to the algorithm description for the univariate case.
"""
function overapproximate(vTM::Vector{TaylorModelN{N,T,S}}, ::Type{<:Zonotope};
remove_zero_generators::Bool=true,
remove_redundant_generators::Bool=true,
normalize::Bool=true) where {N,T,S}
n = N # number of variables is get_numvars() in TaylorSeries
return _overapproximate_vTM_zonotope(vTM, n, T;
remove_zero_generators=remove_zero_generators,
remove_redundant_generators=remove_redundant_generators,
normalize=normalize)
end

function _overapproximate_vTM_zonotope(vTM, n, N;
remove_zero_generators::Bool=true,
remove_redundant_generators::Bool=true,
normalize::Bool=true)
m = length(vTM)

Expand Down Expand Up @@ -656,8 +658,8 @@ function load_taylormodels_overapproximation()
end

Z = Zonotope(c, G)
if remove_zero_generators
Z = LazySets.remove_zero_generators(Z)
if remove_redundant_generators
Z = LazySets.remove_redundant_generators(Z)
end
return Z
end
Expand Down
4 changes: 1 addition & 3 deletions test/Sets/SparsePolynomialZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ for N in [Float64, Float32, Rational{Int}]
S = SparsePolynomialZonotope(N[-0.5, -0.5], N[1.0 1 1 1; 1 0 -1 1], zeros(N, 2, 0),
[1 0 1 2; 0 1 1 0])
Z = overapproximate(S, Zonotope)

@test center(Z) == N[0, 0]
@test genmat(Z) == N[1 1 1 0.5; 1 0 -1 0.5]
@test isequivalent(Z, Zonotope(N[0, 0], N[1.5 1 1; 1.5 0 -1]))

PZ = SparsePolynomialZonotope(N[-1, 2], N[1 2 0 2; 0 1 2 -1], N[1 0; 2 0], [1 0 1 2; 0 0 0 1])
PZreduced = remove_redundant_generators(PZ)
Expand Down
Loading