Skip to content

Commit

Permalink
support function for Ballp
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Apr 7, 2023
1 parent 20f887c commit 1a64678
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
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
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 1a64678

Please sign in to comment.