Skip to content

Commit

Permalink
Merge pull request #3118 from JuliaReach/schillic/box_approximation
Browse files Browse the repository at this point in the history
Revise box-/ballinf-approximation and sih code
  • Loading branch information
schillic authored Oct 10, 2022
2 parents 91fdb61 + c16f9ac commit d104aaa
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 181 deletions.
3 changes: 1 addition & 2 deletions docs/src/lib/approximations.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ approximate
## Box Approximations

```@docs
ballinf_approximation
box_approximation
interval_hull
symmetric_interval_hull
box_approximation_symmetric
box_approximation_helper
ballinf_approximation
```

## Iterative refinement
Expand Down
28 changes: 7 additions & 21 deletions src/Approximations/ballinf_approximation.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# ===========================================================
# Concrete overapproximation with a ball in the infinity norm
# ===========================================================

"""
ballinf_approximation(S::ConvexSet)
ballinf_approximation(S::LazySet)
Overapproximate a set by a tight ball in the infinity norm.
Expand All @@ -17,36 +13,26 @@ A tight ball in the infinity norm.
### Algorithm
The center and radius of the box are obtained by evaluating the support function
of the given set along the canonical directions.
The center and radius of the ball are obtained by averaging the low and high
coordinates of `S` computed with the `extrema` function.
"""
function ballinf_approximation(S::ConvexSet{N}) where {N}
function ballinf_approximation(S::LazySet{N}) where {N}
n = dim(S)
c = Vector{N}(undef, n)
r = zero(N)
d = zeros(N, n)

@inbounds for i in 1:n
d[i] = one(N)
htop = ρ(d, S)
d[i] = -one(N)
hbottom = -ρ(d, S)
d[i] = zero(N)
c[i] = (htop + hbottom) / 2
rcur = (htop - hbottom) / 2
lo, hi = extrema(S, i)
rcur = (hi - lo) / 2
if (rcur > r)
r = rcur
elseif !_geq(rcur, zero(N))
# contradicting bounds => set is empty
return EmptySet{N}(dim(S))
end
c[i] = (hi + lo) / 2
end
return BallInf(c, r)
end

# ===============
# Specializations
# ===============

# empty set specialization
ballinf_approximation(∅::EmptySet) =
Loading

0 comments on commit d104aaa

Please sign in to comment.