All Projects → daffidwilde → matching

daffidwilde / matching

Licence: MIT license
A package for solving matching games.

Programming Languages

python
139335 projects - #7 most used programming language
TeX
3793 projects

Projects that are alternatives of or similar to matching

Computational-Economics
Algorithmic game theory, recursive macroeconomics, machine learning for econometrics
Stars: ✭ 35 (-63.92%)
Mutual labels:  game-theory
Deep-Learning-Mahjong---
Reinforcement learning (RL) implementation of imperfect information game Mahjong using markov decision processes to predict future game states
Stars: ✭ 45 (-53.61%)
Mutual labels:  game-theory
algorithms
The All ▲lgorithms documentation website.
Stars: ✭ 114 (+17.53%)
Mutual labels:  game-theory
gt
Source files for my course on Game Theory.
Stars: ✭ 28 (-71.13%)
Mutual labels:  game-theory
gamegym
A game theory framework with examples and algorithms
Stars: ✭ 49 (-49.48%)
Mutual labels:  game-theory
shallow-blue
UCI Chess engine written in C++11
Stars: ✭ 55 (-43.3%)
Mutual labels:  game-theory
mxfactorial
a payment application intended for deployment by the united states treasury
Stars: ✭ 36 (-62.89%)
Mutual labels:  game-theory
prometheus-spec
Censorship-resistant trustless protocols for smart contract, generic & high-load computing & machine learning on top of Bitcoin
Stars: ✭ 24 (-75.26%)
Mutual labels:  game-theory
axle
Axle Domain Specific Language for Scientific Cloud Computing and Visualization
Stars: ✭ 65 (-32.99%)
Mutual labels:  game-theory
datafsm
Machine Learning Finite State Machine Models from Data with Genetic Algorithms
Stars: ✭ 14 (-85.57%)
Mutual labels:  game-theory
Neural-Fictitous-Self-Play
Scalable Implementation of Neural Fictitous Self-Play
Stars: ✭ 52 (-46.39%)
Mutual labels:  game-theory
CovGT-3DRegistration-matlab
A 3D Scene Registration Method via Covariance Descriptors and an Evolutionary Stable Strategy Game Theory Solver
Stars: ✭ 20 (-79.38%)
Mutual labels:  game-theory
Java-Questions-and-Solutions
This repository aims to solve and create new problems from different spheres of coding. A path to help students to get access to solutions and discuss their doubts.
Stars: ✭ 34 (-64.95%)
Mutual labels:  game-theory
gtsa
Game Tree Search Algorithms - C++ library for AI bot programming
Stars: ✭ 68 (-29.9%)
Mutual labels:  game-theory
ilqgames
Iterative Linear-Quadratic Games!
Stars: ✭ 54 (-44.33%)
Mutual labels:  game-theory
egtplot
egtplot: A python package for 3-Strategy Evolutionary Games
Stars: ✭ 33 (-65.98%)
Mutual labels:  game-theory

Matching

A package for solving matching games.

Matching games allow for the allocation of resources and partnerships in a fair way. Typically, a matching game is defined by two sets of players that each have preferences over at least some of the elements of the other set. The objective of the game is then to find a mapping between the sets of players in which everyone is happy enough with their match.

In Matching, we deal with four types of matching game:

  • the stable marriage problem (SM);
  • the hospital-resident assignment problem (HR);
  • the student-allocation problem (SA);
  • the stable roommates problem (SR).

Installation

Matching requires Python 3.5 or above, and relies only on NumPy for general use.

The library is most easily installed using pip:

$ python -m pip install matching

However, if you would like to install it from source then go ahead and clone the GitHub repo:

$ git clone https://github.com/daffidwilde/matching.git
$ cd matching
$ python setup.py install

Documentation

Full documentation (including tutorials and discussion material) is available here: https://matching.readthedocs.io

An academic paper on this library has been included in the Journal of Open Source Software (JOSS) and is available here: https://joss.theoj.org/papers/10.21105/joss.02169

Playing a simple game

With all games, Matching uses a Player class to represent the members of the "applying" party, i.e. residents and students. For HR and SA, there are specific classes to represent the roles of Hospital, Project and Supervisor.

Consider the following instance of SM which is represented on a bipartite graph where the suitors and reviewers are along the left and right respectively.

./tex/stable_marriage.png

We can construct these preferences using dictionaries:

>>> suitor_preferences = {
...     "A": ["D", "E", "F"], "B": ["D", "F", "E"], "C": ["F", "D", "E"]
... }
>>> reviewer_preferences = {
...     "D": ["B", "C", "A"], "E": ["A", "C", "B"], "F": ["C", "B", "A"]
... }

Then to solve this matching game, we make use of the StableMarriage class, like so:

>>> from matching.games import StableMarriage
>>> game = StableMarriage.create_from_dictionaries(
...     suitor_preferences, reviewer_preferences
... )
>>> game.solve()
{A: E, B: D, C: F}

The Matching object

This matching is not a standard Python dictionary, though it does largely look and behave like one. It is in fact an instance of the SingleMatching class:

>>> matching = game.matching
>>> type(matching)
<class 'matching.matchings.SingleMatching'>

This dictionary-like object is primarily useful as a teaching device that eases the process of manipulating a matching after a solution has been found.

Player classes

Despite passing dictionaries of strings here, the matching displays instances of matching.player.Player:

>>> matching = game.matching
>>> for suitor in matching:
...     print(type(suitor))
<class 'matching.players.player.Player'>
<class 'matching.players.player.Player'>
<class 'matching.players.player.Player'>

This is because create_from_dictionaries creates instances of the appropriate player classes first and passes them to the game class. Using dictionaries like this can be an efficient way of creating large games but it does require the names of the players in each party to be unique.

With all games, Matching uses a Player class to represent the members of the "applying" party, i.e. residents and students. For HR and SA, there are specific classes to represent the roles of Hospital, Project and Supervisor.

A note on performance

One of the limitations of this library is the time complexities of the algorithm implementations. In practical terms, the running time of any of the algorithms in Matching is negligible but the theoretic complexity of each has not yet been attained. For example, an instance of HR with 400 applicants and 20 hospitals is solved in less than one tenth of a second:

>>> from matching.games import HospitalResident
>>> import numpy as np
>>> np.random.seed(0)
>>> num_residents, num_hospitals = 400, 20
>>> resident_prefs = {
...     r: np.argsort(np.random.random(size=num_hospitals))
...     for r in range(num_residents)
... }
>>> hospital_prefs = {
...     h: np.argsort(np.random.random(size=num_residents))
...     for h in range(num_hospitals)
... }
>>> capacities = {h: num_hospitals for h in hospital_prefs}
>>> game = HospitalResident.create_from_dictionaries(
...     resident_prefs, hospital_prefs, capacities
... )
>>> _ = game.solve() # 48.6 ms ± 963 µs per loop

Get in contact!

I hope this package is useful, and feel free to contact me here (or on Twitter: @daffidwilde) with any issues or recommendations. Pull requests are always welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].