Code Monkey home page Code Monkey logo

nashpy's Introduction

Nash: a python library for the computation of equilibria of 2 player strategic games.

This is a library with simple dependencies (it only requires numpy) so that it is pip installable: if you want to do sophisticated equilibria computation YOU SHOULD use gambit.

This is a linear algebraic implementation of support enumeration using numpy.

This algorithm has also been implemented in Sagemath.

Installation

The easiest way to install is from pypi:

$ pip install nashpy  # This doesn't work yet  #TODO Speak to James

Usage

You can create a zero sum game by passing a single 2 dimensional array/list:

>>> import nash
>>> A = [[1, -1], [-1, 1]]
>>> matching_pennies = nash.Game(A)
>>> matching_pennies.zero_sum
True

To compute the equilibria you can iterate over Game.equilibria() which is a generator:

>>> for eq in matching_pennies.equilibria():
...     print(eq)
(array([ 0.5,  0.5]), array([ 0.5,  0.5]))

You can also create bi matrix games by passing two 2 dimensional arrays/lists:

>>> A = [[1, 2], [3, 0]]
>>> B = [[0, 2], [3, 1]]
>>> battle_of_the_sexes = nash.Game(A, B)
>>> battle_of_the_sexes.zero_sum
False
>>> for eq in battle_of_the_sexes.equilibria():
...     print(eq)
(array([ 1.,  0.]), array([ 0.,  1.]))
(array([ 0.,  1.]), array([ 1.,  0.]))
(array([ 0.5,  0.5]), array([ 0.5,  0.5]))

Development

To run the full test suite:

$ python setup.py test

All contributions are welcome, although this is meant to be a simple library, for more detailed game theoretic contribution please see gambit.

nashpy's People

Contributors

drvinceknight avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.