Skip to content

Commit

Permalink
Merge pull request #1172 from JuliaReach/mforets/1170
Browse files Browse the repository at this point in the history
#1170 - Faster hyperrectangular overapproximation of the linear map of a hyperrectangular set
  • Loading branch information
mforets authored Feb 27, 2019
2 parents de7b2b0 + 42f7f9f commit f565ce7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Approximations/overapproximate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,37 @@ function overapproximate(S::CartesianProductArray{N, <:AbstractHyperrectangle{N}
return convert(Hyperrectangle, S)
end

"""
overapproximate(lm::LinearMap{N, <:AbstractHyperrectangle{N}},
::Type{Hyperrectangle}) where {N}
Return a tight overapproximation of the linear map of a hyperrectangular set
using a hyperrectangle.
### Input
- `S` -- linear map of a hyperrectangular set
- `Hyperrectangle` -- type for dispatch
### Output
A hyperrectangle.
### Algorithm
If `c` and `r` denote the center and vector radius of a hyperrectangle `H`,
a tight hyperrectangular overapproximation of `M * H` is obtained by transforming
`c ↦ M*c` and `r ↦ abs.(M) * c`, where `abs.(⋅)` denotes the element-wise absolute
value operator.
"""
function overapproximate(lm::LinearMap{N, <:AbstractHyperrectangle{N}},
::Type{Hyperrectangle}) where {N<:Real}
M, X = lm.M, lm.X
center_MX = M * center(X)
radius_MX = abs.(M) * radius_hyperrectangle(X)
return Hyperrectangle(center_MX, radius_MX)
end

"""
overapproximate(S::LazySet)::Union{Hyperrectangle, EmptySet}
Expand Down Expand Up @@ -413,3 +444,4 @@ function overapproximate(cap::Intersection{N,
) where {N<:Real}
return overapproximate(swap(cap), dir; kwargs...)
end

6 changes: 6 additions & 0 deletions test/unit_overapproximate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ for N in [Float64, Rational{Int}, Float32]
Zoa = overapproximate(Z, Hyperrectangle) # faster o.a.
Zba = box_approximation(Z) # default o.a. implementation that uses supp function
@test Zoa.center Zba.center && Zoa.radius Zba.radius

# overapproximation of the lazy linear map of a hyperrectangular set
H = Hyperrectangle(N[0, 0], N[1/2, 1])
M = Diagonal(N[2, 2])
OA = overapproximate(M*H, Hyperrectangle)
@test OA isa Hyperrectangle && OA.center == N[0, 0] && OA.radius == N[1, 2]
end

# tests that do not work with Rational{Int}
Expand Down

0 comments on commit f565ce7

Please sign in to comment.