Skip to content

Commit

Permalink
Merge pull request #3446 from JuliaReach/schillic/prune
Browse files Browse the repository at this point in the history
Remove redundant generators in zonotope overapproximations
  • Loading branch information
schillic committed Mar 18, 2024
2 parents 130e744 + 460a141 commit 79981c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
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

0 comments on commit 79981c4

Please sign in to comment.