From 8955782ea3660f2beba060b3cf9a912103842ba7 Mon Sep 17 00:00:00 2001 From: schillic Date: Sun, 16 Jun 2024 22:54:30 +0200 Subject: [PATCH] fix overapproximate of SSPZ with Zonotope and dom --- src/Approximations/overapproximate_zonotope.jl | 7 ++++--- test/Sets/SimpleSparsePolynomialZonotope.jl | 4 +++- test/Sets/SparsePolynomialZonotope.jl | 7 +++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Approximations/overapproximate_zonotope.jl b/src/Approximations/overapproximate_zonotope.jl index cce2d66c86..ee2486e39d 100644 --- a/src/Approximations/overapproximate_zonotope.jl +++ b/src/Approximations/overapproximate_zonotope.jl @@ -213,8 +213,9 @@ function _overapproximate_union_zonotope_GGP09(X::LazySet{N}) where {N} end # Given center, (dependent) generator matrix and exponent matrix of a (simple) -# sparse polynomial zonotope, compute thew new center and generator matrix of -# its zonotope overapproximation. +# sparse polynomial zonotope, compute the new center and generator matrix of +# its zonotope overapproximation. This method assumes that the parameter domain +# is [-1, 1]ᵖ. function _zonotope_overapprox!(c, G, E) @inbounds for (j, g) in enumerate(eachcol(G)) if all(iseven, E[:, j]) @@ -284,7 +285,7 @@ function overapproximate(P::SimpleSparsePolynomialZonotope, ::Type{<:Zonotope}, end m, r = IA.midpoint_radius(α) cnew .+= m * g - Gnew[:, j] .= abs.(g) * r + Gnew[:, j] .= r * g end return Zonotope(cnew, Gnew) end diff --git a/test/Sets/SimpleSparsePolynomialZonotope.jl b/test/Sets/SimpleSparsePolynomialZonotope.jl index 500db110f6..a31ee85622 100644 --- a/test/Sets/SimpleSparsePolynomialZonotope.jl +++ b/test/Sets/SimpleSparsePolynomialZonotope.jl @@ -15,7 +15,9 @@ for N in [Float64, Float32, Rational{Int}] @test nparams(S) == 2 @test order(S) == 1 // 1 - @test overapproximate(S, Zonotope) == Zonotope(N[3.0, 1], N[1 1; 2 1.0]) + Z = Zonotope(N[3.0, 1], N[1 1; 2 1.0]) + @test overapproximate(S, Zonotope) == Z + @test overapproximate(S, UnionSetArray{Zonotope}; nsdiv=1) == UnionSetArray([Z]) @test length(overapproximate(S, UnionSetArray{Zonotope}; nsdiv=3)) == 9 if vIA >= v"0.19.0" # `mince` with non-uniform partition was introduced in IA v0.19.0 @test length(overapproximate(S, UnionSetArray{Zonotope}; partition=(2, 3))) == 6 diff --git a/test/Sets/SparsePolynomialZonotope.jl b/test/Sets/SparsePolynomialZonotope.jl index 1fd5034838..a897740cf2 100644 --- a/test/Sets/SparsePolynomialZonotope.jl +++ b/test/Sets/SparsePolynomialZonotope.jl @@ -62,6 +62,9 @@ for N in [Float64, Float32, Rational{Int}] 0 0 0 1 0 1; 0 0 0 0 1 3] Z = overapproximate(PZ2, Zonotope) + SSPZ2 = convert(SimpleSparsePolynomialZonotope, PZ2) + Z2 = overapproximate(SSPZ2, Zonotope, IntervalBox(-1 .. 1, -1 .. 1)) + @test isequivalent(Z, Z2) CPPZ = cartesian_product(PZ, Z) @test center(CPPZ) == N[4, 4, 0, 0] @test genmat_dep(CPPZ) == N[2 1 2; @@ -130,6 +133,10 @@ for N in [Float64, Float32, Rational{Int}] l2, u2 = extrema(PZ; algorithm="lowhigh") H2 = Hyperrectangle(; low=l2, high=u2) @test H2 ⊆ H1 == Hyperrectangle(N[0, 0], N[7 // 2, 5 // 2]) + Z = Zonotope(N[0, 0], N[3//2 1 1; 3//2 0 -1]) + @test isequivalent(overapproximate(PZ, Zonotope), Z) + SSPZ2 = convert(SimpleSparsePolynomialZonotope, PZ) + @test isequivalent(overapproximate(SSPZ2, Zonotope, IntervalBox(-1 .. 1, -1 .. 1)), Z) end for N in [Float64]