Skip to content

Add game_theory/normal_form_game.jl#95

Closed
oyamad wants to merge 3 commits intomasterfrom
game_theory
Closed

Add game_theory/normal_form_game.jl#95
oyamad wants to merge 3 commits intomasterfrom
game_theory

Conversation

@oyamad
Copy link
Copy Markdown
Member

@oyamad oyamad commented Jan 24, 2016

This is a Julia version of normal_form_game.py (QuantEcon/QuantEcon.py#220).
See this notebook for demonstration.

TODO:

  • Docstring
  • Add payoff_profile_array method
  • Decide on what to display by show(io::IO, player::Player) and show(io::IO, g::NormalFormGame)

Issues:

  • I don't think I really understand Julia's type system. I tried to make the constructors/methods type-stable using @code_warntype, but I am not 100% sure.
  • Methods are defined for NTuple as an action profile: a tuple of integers (pure actions), a tuple of vectors of reals (mixed actions; vectors may be different in length), or a tuple of integers and vectors. Is it better to implement these methods also for Arrays?

Some features:

  • To constitute a NormalFormGame, Player instances must be homogeneous in their eltype of payoff_array.

    type Player{N,T<:Real}
        payoff_array::Array{T,N}
        num_actions::Int
        num_opponents::Int
        tol::Float64
    end
    type NormalFormGame{N,T<:Real}
        players::NTuple{N,Player{N,T}}
        N::Int
        nums_actions::NTuple{N,Int}
    end

    (The current Python version allows heterogeneous dtypes, but I think I am going to change it.)
    (EDIT: To be changed by Changes in normal_form_game QuantEcon.py#226.)

@sglyon
Copy link
Copy Markdown
Member

sglyon commented Jan 25, 2016

Thank you for adding this!

I'll try to find time to review very soon.

As always, I appreciate the effort you take into including tests with your pull requests.

@sglyon
Copy link
Copy Markdown
Member

sglyon commented Jan 25, 2016

@oyamad can you elaborate on parts of the type system you are concerned about? Are there specific methods or functions that gave or are giving you a hard time?

@oyamad
Copy link
Copy Markdown
Member Author

oyamad commented Jan 26, 2016

Sorry I was not clear. I did many trials and errors and finally succeeded in getting rid of (almost) all warnings in @code_warntype (except for ANYs in anonymous functions and NormalFormGame{T<:Real}(data::Matrix{T}) where the return type is different depending on the input). I don't think I really understand what my code is doing in terms of typing. In particular:

  • I do not know when I should provide type parameters and when I do not need to or should not.
  • I used @generated for NormalFormGame{T<:Real}(data::Array{T}) to construct NTuple{N,Player{N,T}} for the value N determined by ndims(data) - 1, but I am not sure whether this is the best strategy.

Referred to base/show.jl
@oyamad
Copy link
Copy Markdown
Member Author

oyamad commented Feb 2, 2016

I modified show(io::IO, player::Player) and show(io::IO, g::NormalFormGame), mimicking that for Array.

They look like:

julia> player1 = Player([3 1; 0 2])
2x2 Player{2,Int64}:
 3  1
 0  2

julia> player2 = Player([2 0; 1 3])
2x2 Player{2,Int64}:
 2  0
 1  3

julia> g = NormalFormGame((player1, player2))
2x2 NormalFormGame{2,Int64}

julia> NormalFormGame((2, 2, 2))
2x2x2 NormalFormGame{3,Float64}

Let me leave payoff_profile_array unimplemented for this PR.

(Tests fail for nightly with UndefVarError: qnwlege not defined.)

@oyamad oyamad changed the title [WIP] Add game_theory/normal_form_game.jl Add game_theory/normal_form_game.jl Feb 2, 2016
@sglyon
Copy link
Copy Markdown
Member

sglyon commented Feb 16, 2016

Hi @oyamad I'm sorry I haven't been super proactive in reviewing and merging this. The delay is caused partly because I have been busy and partly because I have been waiting to get the work over at https://github.com/QuantEcon/Games.jl to get off the ground.

I think the plan going forward will be to have the game theory work start and progress over at that repository. Down the road we will consider merging that code into QuantEcon.jl, but we'll have to see how far things go and if it makes sense to keep Games.jl as a standalone package before making that decision.

With that in mind, are you ok if we move this PR over to that repo and use it as a starting point for the work that will happen over there?

@oyamad
Copy link
Copy Markdown
Member Author

oyamad commented Feb 16, 2016

@spencerlyon2 No problem at all. Sure, please move this PR to Games.jl. Thanks!

@sglyon
Copy link
Copy Markdown
Member

sglyon commented Feb 17, 2016

Closing in favor of QuantEcon/GameTheory.jl#1

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.

2 participants