Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise support function for (un)bounded sets #1115

Closed
schillic opened this issue Feb 12, 2019 · 5 comments · Fixed by #1797
Closed

Revise support function for (un)bounded sets #1115

schillic opened this issue Feb 12, 2019 · 5 comments · Fixed by #1797
Assignees
Labels
bug 🐛 Something isn't working performance 🐎 More efficient code refactoring 🔧 Internal code changes, typically no impact on API

Comments

@schillic
Copy link
Member

schillic commented Feb 12, 2019

There is a problem with the support function for unbounded sets. If an entry of the direction is zero, and the corresponding entry of the support vector is ±Inf, then the result is NaN.

julia> dot([1., 0.], [Inf, -Inf])
NaN

The reason for this is:

julia> Inf * 0.
NaN

In #1114 we defined (but reverted again) a new dot product and replaced the definition of ρ. However, this makes the computation less efficient. For sets that are known to be bounded, this modification is not needed.
So we should actually define the old version as a more efficient alternative, and call it from (statically) bounded set types.

@schillic schillic added bug 🐛 Something isn't working performance 🐎 More efficient code refactoring 🔧 Internal code changes, typically no impact on API labels Feb 12, 2019
@schillic schillic changed the title Rework support function for (un)bounded sets Revise support function for (un)bounded sets Feb 12, 2019
@mforets
Copy link
Member

mforets commented Feb 12, 2019

With the half-space, i think that the actual behavior is fine:

julia> h = HalfSpace([1.0, -1.0], 0.0);

julia> σ([1.0, -1.0], h)
2-element Array{Float64,1}:
 0.0
 0.0

julia> σ([-1.0, 1.0], h)
ERROR: the support vector for the halfspace with normal direction [1.0, -1.0] is not defined along a direction [-1.0, 1.0]
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] #σ_helper#65 at /Users/forets/.julia/dev/LazySets/src/Hyperplane.jl:351 [inlined]
 [3] (::getfield(LazySets, Symbol("#kw##σ_helper")))(::NamedTuple{(:error_unbounded, :halfspace),Tuple{Bool,Bool}}, ::typeof(LazySets.σ_helper), ::Array{Float64,1}, ::Hyperplane{Float64}) at ./none:0
 [4] σ(::Array{Float64,1}, ::HalfSpace{Float64}) at /Users/forets/.julia/dev/LazySets/src/HalfSpace.jl:112
 [5] top-level scope at none:0

julia> ρ([1.0, -1.0], h)
0.0

julia> ρ([-1.0, 1.0], h)
Inf

@mforets
Copy link
Member

mforets commented Feb 12, 2019

I know that this result is inconsistent with the HPolyhedron, since it does not error over an unbounded direction:

julia> p = HPolyhedron([h])
HPolyhedron{Float64}(HalfSpace{Float64}[HalfSpace{Float64}([1.0, -1.0], 0.0)])

julia> σ([1.0, -1.0], p)
2-element Array{Float64,1}:
 0.0
 0.0

julia> σ([-1.0, 1.0], p)
2-element Array{Float64,1}:
 -Inf  
    0.0

julia> ρ([1.0, -1.0], p)
0.0

julia> ρ([-1.0, 1.0], p)
Inf

I doubt that there is "practical" interest in returning σ([-1.0, 1.0], p), to be used in further calculations -- instead, why don't we send an error, as with the half-space.

@schillic
Copy link
Member Author

schillic commented Feb 13, 2019

With the half-space, i think that the actual behavior is fine

Yes, because we explicitly define the behavior in those cases. But I did not say anything about the HalfSpace, so why is that relevant here?

I know that this result is inconsistent with the HPolyhedron, since it does not error over an unbounded direction

That we want to resolve in #750. Again, the reason why the problem does not occur here is that we explicitly handle this case.

why don't we send an error, as with the half-space.

Please not, we spent efforts to support it after we discussed that we want this.

I doubt that there is "practical" interest in returning σ([-1.0, 1.0], p), to be used in further calculations

The main application where the result of σ is reused is in the default implementation of ρ. Hence we have to define ρ for every lazy set type. The implementations would all look identical, so we can write a new helper function for those cases. This is what I proposed above.

@schillic
Copy link
Member Author

I found out that we already define the support function for all possibly unbounded set types (except for SymmetricIntervalHull, but that type does not make sense for unbounded sets (see #1116)). So the solution in my use case is to define the support function there as well.
We should keep that in mind for future set types. I propose that we add a note in the documentation of LazySet.

@schillic
Copy link
Member Author

SymmetricIntervalHull now inherits the definition from AbstractHyperrectangle, so there is nothing left to do apart from the note in the documentation.

schillic added a commit that referenced this issue Nov 27, 2019
#1115 - Add better documentation for ρ to LazySet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working performance 🐎 More efficient code refactoring 🔧 Internal code changes, typically no impact on API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants