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

Add game_theory.normal_form_game #220

Merged
merged 6 commits into from
Jan 20, 2016
Merged

Add game_theory.normal_form_game #220

merged 6 commits into from
Jan 20, 2016

Conversation

oyamad
Copy link
Member

@oyamad oyamad commented Jan 13, 2016

This PR adds code on base classes for game theory tools, Player and NormalFormGame (written with help from my previous RA @kusanot): see this notebook for demonstration.

(Applications to learning/evolutionary dynamics models will be submitted with other PRs.)

  • Created a new directory game_theory, and
  • edited docs/qe_apidoc.py accordingly.

@oyamad
Copy link
Member Author

oyamad commented Jan 13, 2016

One issue on importing:
With import quantecon, the submodules markov, random, and util are automatically imported. For example:

>>> import quantecon as qe
>>> qe.random.probvec(2, 3)
array([[ 0.77491011,  0.09414303,  0.13094686],
       [ 0.69912477,  0.09336095,  0.20751428]])

But the newly added game_theory is not imported:

>>> qe.game_theory.NormalFormGame((2, 2))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'quantecon' has no attribute 'game_theory'

If I do import quantecon.game_theory, it works:

>>> import quantecon.game_theory
>>> qe.game_theory.NormalFormGame((2, 2))
2-player NormalFormGame

I wonder there is something wrong with __init__.py or setup.py?

@davidrpugh
Copy link
Contributor

@oyamad

It doesn't look like the module has been included in the __init__.py. I think that adding something like

from . import game_theory

into the quantecon/__init__.py should work.

@oyamad
Copy link
Member Author

oyamad commented Jan 13, 2016

@davidrpugh Thanks, I will try that.

But I wonder why the other submodules such as random are imported without from . import random in quantecon/__init__.py.

@mmcky
Copy link
Contributor

mmcky commented Jan 13, 2016

Hi @oyamad - the main role of the __init__.py file is to control the API and namespace. . So (as @davidrpugh suggests) it would be good to add any objects (that are general enough) from the new module that you would like to be importable from the top level to the __init__.py to allow statements such as:

from quantecon import <object>

But we also need to add it to the packages field in setup.py to distribute the subpackage with the installer.Happy to do this for you and submit a PR if you would like.

I might put some examples together for the new python developers page on this topic.

@oyamad
Copy link
Member Author

oyamad commented Jan 13, 2016

@mmcky 'quantecon.game_theory' is added to packages in setup.py. And from quantecon import game_theory as well as import quantecon.game_theory work.

Please edit this PR for whatever you think needs to be changed.

@mmcky
Copy link
Contributor

mmcky commented Jan 13, 2016

@oyamad Ah right. I see now. Sorry I just noticed I hadn't checked out the branch properly - so my setup.py file wasn't up to date. I will adjust the __init__.py to adjust the behavior as requested above.

@rawls238
Copy link

why not just utilize gambit for this?

@oyamad
Copy link
Member Author

oyamad commented Jan 13, 2016

@mmcky Thanks. Now this works:

>>> import quantecon as qe
>>> qe.game_theory.NormalFormGame((2, 2))
2-player NormalFormGame

But I still don't see why random and others work without from . import random etc.

@oyamad
Copy link
Member Author

oyamad commented Jan 13, 2016

@rawls238 I don't know. Maybe Gambit is too sophisticated for the simple code for learning models (to come out with other PRs).

@davidrpugh
Copy link
Contributor

I was wondering the same...
On 13 Jan 2016 13:52, "Daisuke Oyama" notifications@github.com wrote:

@davidrpugh https://github.com/davidrpugh Thanks, I will try that.

But I wonder why the other submodules such as random are imported without from
. import random in quantecon/init.py
https://github.com/QuantEcon/QuantEcon.py/blob/master/quantecon/__init__.py
.


Reply to this email directly or view it on GitHub
#220 (comment)
.

@mmcky
Copy link
Contributor

mmcky commented Jan 13, 2016

markov and util are imported in the base __init__.py file

from .markov import MarkovChain, random_markov_chain, random_stochastic_matrix, gth_solve, tauchen      #Promote to keep current examples working
from .markov import mc_compute_stationary, mc_sample_path 
from .util import searchsorted, fetch_nb_dependencies

random was however really confusing. I dug into this as I agree it shouldn't be working. It looks like the random module was added to the namespace thanks to the relative import in quantecon/markov/random.py.

from ..random import probvec, sample_without_replacement

If one removes the quantecon.random subpackage then the import of quantecon fails due to this relative import statement. So I will fix this to make the import of the random subpackage explicit. I will make these changes in a separate PR in case this PR has further discussion points.

@mmcky
Copy link
Contributor

mmcky commented Jan 13, 2016

@oyamad Due to the dual edit of __init__.py this branch we will likely result in a merge conflict. I will resolve this if it eventuates.

@oyamad
Copy link
Member Author

oyamad commented Jan 14, 2016

@mmcky Thank you, now I understand it.

@jstac
Copy link
Contributor

jstac commented Jan 14, 2016

I am enthusiastic to have these algorithms and representations included. As usual the code is of the highest quality. The notebook is very helpful to understand the main ideas. Everything I tested runs nicely and seems fast and efficient.

I think it's essential that QuantEcon supports game theory in general and computation of Nash equilibria in particular. Solving for NE ranks alongside dynamic programming as one of the core set of algorithms to implement or support in a general purpose computational econ library.

The only question is what to do about Gambit. I wrote to the lead developer and he showed no enthusiasm for supporting Python 3, making a conda package or cooperating with us on any front.

This makes me think that we should go ahead and accept this PR (plus the corresponding PR for the notebook) and then see how things develop. Does anyone object?

@mmcky
Copy link
Contributor

mmcky commented Jan 20, 2016

Thanks @oyamad. Once I obtain the green light from Travis CI I will merge this PR.

mmcky added a commit that referenced this pull request Jan 20, 2016
Add game_theory.normal_form_game
@mmcky mmcky merged commit e820cfe into master Jan 20, 2016
@mmcky mmcky deleted the game_theory branch January 20, 2016 22:56
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.

5 participants