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

[WIP] Add vertex enumeration. #64

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

shizejin
Copy link
Member

Closes #43

Had a rough try to implement vertex enumeration using Polyhedra.jl.
However, the speed is much slower than support_enumeration, as the implementation is quite inefficient.

julia> using Games

julia> A = [3 3; 2 5; 0 6]
3×2 Array{Int64,2}:
 3  3
 2  5
 0  6

julia> B = [3 2 3; 2 6 1]
2×3 Array{Int64,2}:
 3  2  3
 2  6  1

julia> g = NormalFormGame(Player(A), Player(B))
3×2 NormalFormGame{2,Int64}

julia> @time vertex_enumeration(g)
  0.794228 seconds (54.39 k allocations: 2.807 MiB)
3-element Array{Tuple{Array{Real,1},Array{Real,1}},1}:
 (Real[0.0, 0.333333, 0.666667], Real[0.333333, 0.666667])
 (Real[0.8, 0.2, 0.0], Real[0.666667, 0.333333])          
 (Real[1.0, 0.0, 0.0], Real[1.0, 0.0])              

julia> @time support_enumeration(g)
  0.000373 seconds (331 allocations: 17.609 KiB)
3-element Array{Tuple{Array{Real,1},Array{Real,1}},1}:
 (Real[1.0, 0.0, 0.0], Real[1.0, 0.0])                    
 (Real[0.8, 0.2, 0.0], Real[0.666667, 0.333333])          
 (Real[0.0, 0.333333, 0.666667], Real[0.333333, 0.666667])

The very possible reason is that I am finding the labels of vertices in a very inefficient way (by checking the binded inequalities one by one for each vertex pair). So far I haven't found an efficient way to get labels using Polyhedra.SimpleHRepresentation and Polyhedra.SimpleVRepresentation. Maybe another direction is to use ConvexHull.jl and follow the style of the Python implementation.

It would be great if we can talk about this in the next meeting. @oyamad

@coveralls
Copy link

coveralls commented Dec 11, 2017

Coverage Status

Coverage decreased (-8.9%) to 85.215% when pulling 2f38cc3 on shizejin:vertex_enumeration into 7ffab27 on QuantEcon:master.

@oyamad
Copy link
Member

oyamad commented Dec 12, 2017

  • Is it that Polyhedra.jl doesn't give you a list of indices of binding inequalities?
  • What do you mean by "use ConvexHull.jl"? Can't you use it by passing plib=ConvexHullLib()? (Otherwise, what is the role of the plib option?)

@shizejin
Copy link
Member Author

  • Yes that is what I mean. At least SimpleHRepresentation, SimpleVRepresentation, and SimplePolyhedron do not show the correspondence between vertices in VRepresentation and the binding inequalities in HRepresentation directly (they do not have fields that contain such kind of information). I am still exploring Polyhedra.jl to see if I can extract the correspondence in an efficient way.

  • If we use it by passing plib=ConvexHullLib(), then what we can get is ConvexHullPolyhedron, which does not give simplices. So I was thinking about using it by calling the bottom function of it. However, as I just check, ConvexHull.jl is still using julia v0.5, so maybe it's not a good idea to use it.

@oyamad
Copy link
Member

oyamad commented Dec 12, 2017

Maybe open an issue at Polyhedra.jl for a feature request?

@codecov-io
Copy link

codecov-io commented Dec 14, 2017

Codecov Report

Merging #64 into master will decrease coverage by 10.78%.
The diff coverage is 0%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #64       +/-   ##
===========================================
- Coverage   93.33%   82.55%   -10.79%     
===========================================
  Files           6        6               
  Lines         390      384        -6     
===========================================
- Hits          364      317       -47     
- Misses         26       67       +41
Impacted Files Coverage Δ
src/vertex_enumeration.jl 0% <0%> (ø)
src/normal_form_game.jl 92.24% <0%> (-4.47%) ⬇️
src/support_enumeration.jl 98.66% <0%> (-1.34%) ⬇️
src/pure_nash.jl 100% <0%> (ø) ⬆️
src/generators/bimatrix_generators.jl
src/random.jl 100% <0%> (+8.33%) ⬆️
src/repeated_game.jl 91.22% <0%> (+13.84%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 67268f5...fd1f096. Read the comment docs.

@shizejin
Copy link
Member Author

After discussion in JuliaPolyhedra/Polyhedra.jl#60, I tried to use HRepIterator and hyperplane to find out indices of binding inequalities for each vertex. The speed is improved, but still lower than support_enumeration.

julia> A = [3 3; 2 5; 0 6];

julia> B = [3 2 3; 2 6 1];

julia> g = NormalFormGame(Player(A), Player(B));

julia> @time vertex_enumeration(g)
  0.017728 seconds (52.14 k allocations: 2.496 MiB)
3-element Array{Tuple{Array{Real,1},Array{Real,1}},1}:
 (Real[0.0, 0.333333, 0.666667], Real[0.333333, 0.666667])
 (Real[0.8, 0.2, 0.0], Real[0.666667, 0.333333])          
 (Real[1.0, 0.0, 0.0], Real[1.0, 0.0])      

julia> @time support_enumeration(g);
  0.000196 seconds (331 allocations: 17.609 KiB)
3-element Array{Tuple{Array{Real,1},Array{Real,1}},1}:
 (Real[1.0, 0.0, 0.0], Real[1.0, 0.0])                    
 (Real[0.8, 0.2, 0.0], Real[0.666667, 0.333333])          
 (Real[0.0, 0.333333, 0.666667], Real[0.333333, 0.666667])

Because the method now I am using is still trying to find out labelings after VRepresentation is transformed from HRepresentation, but not to get the information during the transformation, we might be able to improve the efficiency if we find a way to get those information during transformation.

However, what I concerned is that even the "time lower bound" for vertex_enumeration is very high. "time lower bound" refers to the time needed to construct the VRepresentation and HRepresentation using Polyhdra.jl.

I wrote a function construction_BRP to do transforamtion:

julia> using Polyhedra

julia> using LRSLib

julia> @time construction_BRP(g, getlibraryfor(2, Float64));
  0.014271 seconds (43.54 k allocations: 2.088 MiB)

julia> @time construction_BRP(g, LRSLib.LRSLibrary());
  0.003624 seconds (6.42 k allocations: 254.492 KiB)

The needed time for transformation is higher than the total time support_enumeration needs. This means vertext_enumeration can never beat support_enumeration even if we find efficient way to find out labelings (I tried big size game and it is even worse). I wonder why because the Python implementation of @oyamad is much faster.

@coveralls
Copy link

coveralls commented Dec 14, 2017

Coverage Status

Coverage decreased (-11.5%) to 82.552% when pulling 11d7fd1 on shizejin:vertex_enumeration into 7ffab27 on QuantEcon:master.

@oyamad
Copy link
Member

oyamad commented Dec 14, 2017

Did you try QHullLib()? Behind that qhull is working, which is what scipy.spatial.ConvexHull wraps.

And also try @code_warntype and @profile.

@coveralls
Copy link

coveralls commented Dec 14, 2017

Coverage Status

Coverage decreased (-11.5%) to 82.552% when pulling 8ee9e73 on shizejin:vertex_enumeration into 7ffab27 on QuantEcon:master.

@shizejin
Copy link
Member Author

It turns out that QHull.QHullLibrary() is much faster. But to use this library, the polyhedron must contains origin as interior point. Is this the reason that you translate payoff arrays in Python implementation?

@oyamad
Copy link
Member

oyamad commented Dec 14, 2017

That operation, commented in that line, is to guarantee that the BR polytope has a nonempty interior.

Read the docstring of _BestResponsePolytope.

@coveralls
Copy link

Coverage Status

Coverage decreased (-11.5%) to 82.552% when pulling bf2fb7c on shizejin:vertex_enumeration into 7ffab27 on QuantEcon:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-11.5%) to 82.552% when pulling bf2fb7c on shizejin:vertex_enumeration into 7ffab27 on QuantEcon:master.

@oyamad
Copy link
Member

oyamad commented Dec 23, 2017

@shizejin The test is not testing vertex_enumeration.

@shizejin
Copy link
Member Author

@oyamad Sorry for pushing the wrong file. Modified.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.7%) to 94.792% when pulling 1e21d16 on shizejin:vertex_enumeration into 7ffab27 on QuantEcon:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.7%) to 94.792% when pulling 1e21d16 on shizejin:vertex_enumeration into 7ffab27 on QuantEcon:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add vertex enumeration
4 participants