Skip to content

Commit

Permalink
Merge pull request #3274 from JuliaReach/schillic/600
Browse files Browse the repository at this point in the history
#600 - Specialized support function for Ball1 and Ballp
  • Loading branch information
schillic authored May 5, 2023
2 parents e008b52 + 7d88a1c commit 61a8696
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/src/lib/sets/Ball1.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CurrentModule = LazySets
```@docs
Ball1
σ(::AbstractVector, ::Ball1)
ρ(::AbstractVector, ::Ball1)
∈(::AbstractVector, ::Ball1, ::Bool=false)
vertices_list(::Ball1)
center(::Ball1)
Expand All @@ -18,7 +19,6 @@ reflect(::Ball1)
```

Inherited from [`LazySet`](@ref):
* [`ρ`](@ref ρ(::AbstractVector, ::LazySet))
* [`norm`](@ref norm(::LazySet, ::Real))
* [`radius`](@ref radius(::LazySet, ::Real))
* [`diameter`](@ref diameter(::LazySet, ::Real))
Expand Down
1 change: 1 addition & 0 deletions docs/src/lib/sets/Ballp.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CurrentModule = LazySets
```@docs
Ballp
σ(::AbstractVector, ::Ballp)
ρ(::AbstractVector, ::Ballp)
∈(::AbstractVector, ::Ballp)
center(::Ballp)
rand(::Type{Ballp})
Expand Down
27 changes: 27 additions & 0 deletions src/Sets/Ball1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,33 @@ function σ(d::AbstractVector, B::Ball1)
return res
end

"""
ρ(d::AbstractVector, B::Ball1)
Evaluate the support function of a ball in the 1-norm in the given direction.
### Input
- `d` -- direction
- `B` -- ball in the 1-norm
### Output
Evaluation of the support function in the given direction.
### Algorithm
Let ``c`` and ``r`` be the center and radius of the ball ``B`` in the 1-norm,
respectively. Then:
```math
ρ(d, B) = ⟨d, c⟩ + r ‖d‖_∞.
```
"""
function ρ(d::AbstractVector, B::Ball1)
return dot(d, B.center) + B.radius * maximum(abs, d)
end

"""
∈(x::AbstractVector, B::Ball1, [failfast]::Bool=false)
Expand Down
7 changes: 2 additions & 5 deletions src/Sets/Ball2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Return the support function of a 2-norm ball in the given direction.
The support function in the given direction.
### Notes
### Algorithm
Let ``c`` and ``r`` be the center and radius of the ball ``B`` in the 2-norm,
respectively. Then:
Expand All @@ -106,10 +106,7 @@ respectively. Then:
```
"""
function ρ(d::AbstractVector, B::Ball2)
c = B.center
r = B.radius
dnorm = norm(d, 2)
return dot(d, c) + dnorm * r
return dot(d, B.center) + B.radius * norm(d, 2)
end

"""
Expand Down
34 changes: 31 additions & 3 deletions src/Sets/Ballp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,49 @@ otherwise, for all ``i = 1, …, n``.
"""
function σ(d::AbstractVector, B::Ballp)
p = B.p
q = p/(p-1)
q = p / ( p - 1)
v = similar(d)
N = promote_type(eltype(d), eltype(B))
@inbounds for (i, di) in enumerate(d)
v[i] = di == zero(N) ? di : abs.(di).^q / di
end
vnorm = norm(v, p)
if iszero(vnorm)
if isapproxzero(vnorm)
svec = B.center
else
svec = @.(B.center + B.radius * (v/vnorm))
svec = @.(B.center + B.radius * (v / vnorm))
end
return svec
end

"""
ρ(d::AbstractVector, B::Ballp)
Evaluate the support function of a ball in the p-norm in the given direction.
### Input
- `d` -- direction
- `B` -- ball in the p-norm
### Output
Evaluation of the support function in the given direction.
### Algorithm
Let ``c`` and ``r`` be the center and radius of the ball ``B`` in the p-norm,
respectively, and let ``q = \\frac{p}{p-1}``. Then:
```math
ρ(d, B) = ⟨d, c⟩ + r ‖d‖_q.
```
"""
function ρ(d::AbstractVector, B::Ballp)
q = B.p / (B.p - 1)
return dot(d, B.center) + B.radius * norm(d, q)
end

"""
∈(x::AbstractVector, B::Ballp)
Expand Down

0 comments on commit 61a8696

Please sign in to comment.