This repository contains the code for the "Approximating Optimal Portfolios of Counterstrategies in Large Imperfect Information Games".
The methods defined in the paper and experiments are implemented in this repository.
experimentscontains the code for running the experiments and generating the plots.portfolio_methodscontains the code for the different portfolio methods and necessary code for portfolios.game_objectscontains the code for the game objects and the different classes used in the experiments.
- Install Dependencies:
Make sure you have Python installed. Install the required dependencies using:
pip install -r requirements.txt
Note: in requirements file there is pyspiel requirement. If you have windows you would need to install it through WSL. However, the only script that uses this dependency is the one that converts the game from openspiel to efg. This file can be run in Google Collab, therefore you can skip this package. Note about gurobi: Linear programs are implemented in Gurobi. You can use the free academic license of Gurobi. If you don't have access to it, you still can run experiments for smaller games. Otherwise, the code is written in a way that you can easily replace the LP solver with your own implementation.
Games used in the paper are in the folder game_objects/games. If you want to convert a game from openspiel to normal form you can use scripts described below.
To convert a game from OpenSpiel to EFG format, use the jupyter notebook file
game_objects/openspiel2efg.ipynb
To convert a game from EFG format to normal form, use the following command:
python game_objects/convert_efg_to_nfg.py
This experiment evaluates all methods defined in the paper. It runs a series of tests on a set of games to compare the performance. It runs the experiments in parallel.
- Exploitability arrays (npy) for each method. and evaluation type (pessimistic, optimistic, and RM+).
- Portfolios generated by the methods.
To run the experiment, use the following command:
python experiments/experiment_all_methods.py --conf <config_file> --dir_path <dir_path>
Possible arguments:
--conf <config_file>a config file. You can use one fromexperiments/configs(for each of the games from the paper) or create your own.--dir_pathpath to the directory where the experiment results will be stored, you can omit this argument and the results will be stored in./experiments_9_resultsYou can also overwrite the config file with arguments, e.g.:kthe portfolio sizes, e.g.-k 4,5"seed_num, this argument determines number of runs for each method. The default value is 50.methodsare defined in the methods_names.py file. Just write them separated by commas, no spaces. e.g.--methods eps_dom,greedy_k- others
note: this will produce some .dat files in the output directory. These files can be removed after the experiment is finished.
Use the following command:
python experiments/draw_experiment_9.py
--conf <config_file> --base-path <base_path>
Necessary arguments:
base_path: Path to the directory where the experiment results folder was saved.conf: Path to the configuration file used for the experiment. It is saved by the script running experiment. Likely the path is<dir_path>/config_exp_9.jsonevaluaition_type: Type of evaluation to be used (e.g., "pessimistic", "optimistic", "RM+"). -- Alternatively you can just read the results with the following command (no plots will be generated, same arguments):python experiments/read_results_experiment_9.py
This experiment analyzes the exploitability of portfolios found by the eps_dom method. It compares the relation between exploitability and epsilon. Produced plots:
- Exploitability of the portfolio vs Epsilon for different game sizes path: {dir_path}/cost_vs_epsilon_{eval_type}.png
- Size of the portfolio vs Epsilon for different game sizes path: {dir_path}/size_vs_epsilon.png
To run the experiment, use the following command:
python experiments/experiment_eps_dom_exploitability.py
The following arguments are optional:
--dir-path: Path to the directory where the experiment results will be stored. Default isexperiments_eps_dom_exploitability_results.--n: Game sizes (number of actions for each player) to be used. Default is5,10,15.--epsilon: Epsilon values to be used. Default is0,0.25,0.5,0.75,1,1.25,1.5,1.75,2.--num-games: Number of generated games. Default is100.--seed: Seed for random number generation. Default is254.
This experiment eps_dom_pure vs greedy k. Check what is the epsilon for the same k
Produced plot:
For each n_size, plot the epsilon vs k
path: {dir_path}/eps_dom_vs_greedy_k_{n_size}.png
To run the experiment, use the following command:
python experiments/experiment_dom_vs_greedy_k.py
The following arguments are optional:
--dir-path: Path to the directory where the experiment results will be stored. Default isexperiments_eps_dom_vs_greedy_k_results.-n: Game sizes (number of actions for each player) to be used. Default is15,20,25.-k: Portfolio sizes to be used. Default is1,2,3,4,5,6,7,8,9,10.--num-games: Number of generated games. Default is100.--seed: Seed for random number generation. Default is42.
To find portfolios for a specific game, use the following command:
python experiments/experiment_find_portfolio.py
With the following arguments:
--dir-path: The output files directory. If not specified a new directory will be created with a unique name.--k: Number of strategies in the portfolio. Default is2.--method-seed: Seed for random number generation. Default is42.--evaluation-type: Type of evaluation to be used (e.g., "pessimistic", "optimistic", "RM+"). Default ispessimistic.--info-max-dim: Maximal number of dimensions for the game analysis. Default is6.--c: Constant c for the gradient methods. Default is0.3.--rnad-max-steps: Maximal number of steps for the R-NaD algorithm. Default is10000.--rnad-epsilon: Epsilon for the R-NaD algorithm. Default is1e-8.--rnad-epsilon-ne: Epsilon NE for the grounding strategy for the R-NaD algorithm. Default is0.--rnad-reg-param: Regularization parameter for the R-NaD algorithm. Default is0.20.--clustering-scheme: Clustering scheme for the GCT method. Default isall_at_once.--methods: Methods to be used for finding the portfolio. Default isOPPP,Alpha,GCT,eps_dom,eps_dom_mixed.--game-name: Name of the game to be used. Default isrps. The games are defined ingame_objects/games_collection.py.--game-file: Path to the game file. Use this if you're not usinggame-nameargument. Default isNone.
This script will generate portfolios and a file with the results of the experiment. The portfolios will be saved in the output directory.
This project is licensed under the MIT License. See the LICENSE.txt file for details.