Counterfactual Regret Minimization Open-Source Implementations
Project description
CFRainbow
Implementations Of Counterfactual Regret Minimization In Its Many Shapes & Colors
CFRainbow provides implementations of the basic CFR algorithm and some of the improved variants of CFR for computing Nash Equilibria in the 2-player 0-sum case as well as Correlated Equilibria in the general-sum case.
The pacakge is loosely built for modularity and general applicability by building on the Openspiel framework by Deepmind. CFRainbow is not built for performance and will not scale well to large game implementations. Most algorithms are implemented with basic python data structures.
The package is in the early WIP phase.
Usage
The easiest way to use CFRainbow is to import the desired algorithm from the package, a regret minimizer, and the run
method with a pyspiel game object or its OpenSpiel name as input.
For example, to use the Vanilla CFR algorithm:
import cfrainbow
from cfrainbow import cfr, rm
cfrainbow.run(
cfr.VanillaCFR,
n_iter=1000,
game="kuhn_poker",
regret_minimizer=rm.RegretMatcher
)
This will run the algorithm for the number of iterations given and compute the exploitability.
You can also use the solver object directly and call iterate
on it after instantiating it with the correct arguments.
For example:
from cfrainbow import cfr, rm
from cfrainbow.utils import load_game, KuhnPolicyPrinter, normalize_policy_profile
root_state = load_game("kuhn_poker").new_initial_states()
solver = cfr.VanillaCFR(
root_state,
regret_minimizer_type=rm.RegretMatcher,
alternating=True, # whether to do alternating or simultaneous updates
)
# iterate for a given number of iterations.
for i in range(1000):
solver.iterate()
avg_policy = normalize_policy_profile(solver.average_policy())
print(
KuhnPolicyPrinter(digits=2).print_profile(avg_policy)
)
Output (Infostate --> Action Policy):
PLAYER 0:
P1: Jack | P2: ? | cb --> ['check: 1.00', 'bet: 0.00']
P1: Jack | P2: ? --> ['check: 0.81', 'bet: 0.19']
P1: Queen | P2: ? | cb --> ['check: 0.48', 'bet: 0.52']
P1: Queen | P2: ? --> ['check: 0.99', 'bet: 0.01']
P1: King | P2: ? | cb --> ['check: 0.00', 'bet: 1.00']
P1: King | P2: ? --> ['check: 0.42', 'bet: 0.58']
PLAYER 1:
P1: ? | P2: Queen | c --> ['check: 0.99', 'bet: 0.01']
P1: ? | P2: Queen | b --> ['check: 0.66', 'bet: 0.34']
P1: ? | P2: King | c --> ['check: 0.00', 'bet: 1.00']
P1: ? | P2: King | b --> ['check: 0.00', 'bet: 1.00']
P1: ? | P2: Jack | c --> ['check: 0.67', 'bet: 0.33']
P1: ? | P2: Jack | b --> ['check: 1.00', 'bet: 0.00']
Note that in alternating updates each iteration is a single player's policy update. In simultaneous updates both players' policy updates constitute one iteration.
Available Algorithms
The following list shows the available algorithms that have been implemented (โ๏ธ), those that are still work in progress (๐จ๐ทโโ๏ธ), and those that are planned to be implemented in the future (๐ ):
Algorithm | Status | Convergence Tests | Paper Results Reproducing |
---|---|---|---|
Best-Response CFR | โ๏ธ | โ๏ธ | ๐จ๐ทโ |
Discounted CFR | โ๏ธ | โ๏ธ | ๐จ๐ทโ |
Exponential CFR | โ๏ธ | โ๏ธ | โ |
Internal CFR | ๐จ๐ทโโ๏ธ | ๐จ๐ทโ | ๐จ๐ทโ |
Joint-Reconstruction CFR | ๐จ๐ทโโ๏ธ | ๐จ๐ทโ | ๐จ๐ทโ |
Chance Sampling Monte Carlo CFR | โ๏ธ | โ๏ธ | ๐จ๐ทโ |
External Sampling Monte Carlo CFR | โ๏ธ | โ๏ธ | ๐จ๐ทโ |
Outcome Sampling Monte Carlo CFR | โ๏ธ | โ๏ธ | ๐จ๐ทโ |
Predictive Plus CFR | โ๏ธ | โ๏ธ | ๐จ๐ทโ |
Pure CFR | โ๏ธ | โ๏ธ | ๐จ๐ทโ |
Sampling CFR | โ๏ธ | ๐จ๐ทโ | ๐จ๐ทโ |
Vanilla CFR | โ๏ธ | โ๏ธ | ๐จ๐ทโ |
Lazy CFR | ๐ | ๐ | ๐ |
Installation
Web Install
Pip
To install CFRainbow from PyPi using pip, run the following command:
pip install cfrainbow
Poetry
If you're using Poetry to manage your Python packages, you can add CFRainbow to your project by adding the following to your pyproject.toml file:
[tool.poetry.dependencies]
cfrainbow = "*"
Then run:
poetry install
to install your own package. Poetry will then install cfrainbow
as dependency alongside your own package.
Source Install
To install CFRainbow from master, please follow these steps:
git clone https://github.com/maichmueller/cfrainbow.git
cd cfrainbow
and install the package with pip
pip install .
or poetry
poetry install
use the option --no-dev
to ensure a non-editable installation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cfrainbow-0.1.1.tar.gz
.
File metadata
- Download URL: cfrainbow-0.1.1.tar.gz
- Upload date:
- Size: 34.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a884e9f8f7e030662cd6d64a11fbd0a0d7211b4116ad080b7afc053e5612ddd7 |
|
MD5 | a7cc528ce6a485eddd3b23c6f431df45 |
|
BLAKE2b-256 | 3bf64b04747aa3c58b95d04ed06302aa53d86374945cab3be40992bdd3e2ad4a |
File details
Details for the file cfrainbow-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: cfrainbow-0.1.1-py3-none-any.whl
- Upload date:
- Size: 44.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9ef4375179f898d7d086d9febc344c43d99bf56d7f571174c5d67f8e1cb81a3 |
|
MD5 | 62f824496f77c40cb515e3b4b5843a87 |
|
BLAKE2b-256 | 5f9ead8d1029211591a5f5e3c8d5572f754625e788da852de3ec8fb8845c1c54 |