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

payoff_function instead of payoff_array? #6

Open
oyamad opened this issue Mar 17, 2016 · 4 comments
Open

payoff_function instead of payoff_array? #6

oyamad opened this issue Mar 17, 2016 · 4 comments
Labels

Comments

@oyamad
Copy link
Member

oyamad commented Mar 17, 2016

As @StefanKarpinski told me:
It may be better to represent a player's payoff function by a function, "payoff_function" or "payoff_func, instead of array payoff_array.

It sounds a great idea to me now.

@sglyon
Copy link
Member

sglyon commented Mar 17, 2016

What would this look like?

This is a terrible implementation and we could certainly do much better, but would this be the type of thing you had in mind:

abstract AbstractPlayer
abstract AbstractNFG

immutable MPPlayer1 <: AbstractPlayer end
immutable MPPlayer2 <: AbstractPlayer end

Base.call(::MPPlayer1, me::Int, them::Int) = me == them ? 1 : -1
Base.call(::MPPlayer2, me::Int, them::Int) = me == them ? -1 : 1

immutable MatchingPennies <: AbstractNFG
    p1:: MPPlayer1
    p2:: MPPlayer2
end

mp1 = MPPlayer1()
mp2 = MPPlayer2()
g = MatchingPennies(mp1, mp2)

mp1(1, 1)  # == 1
mp1(1, 2)  # == -1

mp2(1, 1)  # == -1
mp2(1, 2)  # == 1

@oyamad
Copy link
Member Author

oyamad commented Mar 17, 2016

I am not sure... I was naively thinking about something like:

type Player
    payoff_function::Function
end
u_1(me::Integer, them::Integer) = me == them ? 1 : -1

function u_2(me::Integer, them::Integer)
    payoff_matrix = [-1 1; 1 -1]  # Can be defined by a payoff array
    return payoff_matrix[me, them]
end

p1 = Player(u_1)
p2 = Player(u_2)

@sglyon
Copy link
Member

sglyon commented Mar 17, 2016

@StefanKarpinski what's the latest with having fields of type Function in a type?

I've always avoided it and relied on dispatch, but with new function changes maybe we don't need to do that anymore?

@StefanKarpinski
Copy link

It should be faster now in some cases but not all cases. One thing I believe you can do is make the function a type parameter and then we will get code specialized for specific payoff functions, which could be very fast but may be overkill. Another thing we can do is just put the right type assertions in the places where we call the functions – since we know what these functions should return. In fact, we could have a nominal PayoffFunction type that is callable but has type assertions on the return of its call method(s).

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

No branches or pull requests

3 participants