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

#1769 - Faster box approximation of VPolytope #2252

Merged
merged 2 commits into from
Oct 27, 2020
Merged

Conversation

schillic
Copy link
Member

Closes #1769.

In 2D this implementation is less efficient for a moderate number of vertices due to the additional conversion from low/high in the Hyperrectangle constructor. I guess in higher dimensions it will be more useful. Should I remove the dispatch for VPolygon or add an invoke of the old method based on the number of vertices?

julia> P1 = VPolytope([[0.0, 0.0], [2.0, 1.0], [1.0, 2.0]]);
julia> P2 = VPolytope([rand(2) for _ in 1:100]);
julia> P3 = VPolytope([rand(2) for _ in 1:1000]);

# this branch

julia> @time box_approximation(P1)
[0.0, 0.0][2.0, 2.0]
  0.000008 seconds (5 allocations: 416 bytes)
Hyperrectangle{Float64,Array{Float64,1},Array{Float64,1}}([1.0, 1.0], [1.0, 1.0])
julia> @time box_approximation(P2)
[0.001830275380493962, 0.005165832293896333][0.9791389830947983, 0.9914106144943142]
    0.000009 seconds (5 allocations: 416 bytes)
Hyperrectangle{Float64,Array{Float64,1},Array{Float64,1}}([0.49048462923764613, 0.4982882233941053], [0.48865435385715217, 0.49312239110020895])
julia> @time box_approximation(P3)
  0.000024 seconds (5 allocations: 416 bytes)
Hyperrectangle{Float64,Array{Float64,1},Array{Float64,1}}([0.4991620587806421, 0.4983966049474178], [0.49909969477169713, 0.4978833437247012])

# master

julia> @time box_approximation(P1)
  0.000004 seconds (3 allocations: 224 bytes)
Hyperrectangle{Float64,Array{Float64,1},Array{Float64,1}}([1.0, 1.0], [1.0, 1.0])
julia> @time box_approximation(P2)
  0.000008 seconds (3 allocations: 224 bytes)
Hyperrectangle{Float64,Array{Float64,1},Array{Float64,1}}([0.49048462923764613, 0.4982882233941053], [0.48865435385715217, 0.49312239110020895])
julia> @time box_approximation(P3)
  0.000049 seconds (3 allocations: 224 bytes)
Hyperrectangle{Float64,Array{Float64,1},Array{Float64,1}}([0.4991620587806421, 0.4983966049474178], [0.49909969477169713, 0.4978833437247012])

@schillic schillic requested a review from mforets July 20, 2020 10:48
@mforets
Copy link
Member

mforets commented Jul 26, 2020

i had a look, see this notebook. in low dims (usually <= 10) static arrays are much faster that regular arrays so it'd be nice that our code supports them. it is not the case with the new method but see the alternative implementation ba2 in that notebook. it is also faster for dim 2 and different number of vertices. for dimension 10, ba1 is faster, though i didn't make exhaustive checks!

@mforets
Copy link
Member

mforets commented Jul 26, 2020

In 2D this implementation is less efficient for a moderate number of vertices

here ba1 is faster than the version in master, while it allocates a bit more. see cells [15] and [9] in the notebook.

applies same comment as in #2241 (comment) for presenting benchmark results

@schillic
Copy link
Member Author

schillic commented Aug 2, 2020

I added the ideas from your implementation with minor modifications.

Side note: I always get one more allocation than in your notebook (but even when I use your exact version, so this is not a problem of my modifications). Maybe you want to double-check...

Copy link
Member

@mforets mforets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 🎉

@schillic schillic merged commit d1c38b4 into master Oct 27, 2020
@schillic schillic deleted the schillic/1769 branch October 27, 2020 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Faster box approximation of VPolytope
2 participants