Skip to content

About

Code for portfolios of counterstrategies in large imperfect information games

Resources

Stars

0 stars

Watchers

5 watching

Forks

Repository files navigation

Analizing Portfolios of Counterstrategies

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.

  • experiments contains the code for running the experiments and generating the plots.
  • portfolio_methods contains the code for the different portfolio methods and necessary code for portfolios.
  • game_objects contains the code for the game objects and the different classes used in the experiments.

Requirements

  1. 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

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.

Convert from openspiel to efg

To convert a game from OpenSpiel to EFG format, use the jupyter notebook file game_objects/openspiel2efg.ipynb

Convert from efg to normal form

To convert a game from EFG format to normal form, use the following command: python game_objects/convert_efg_to_nfg.py


Experiments

experiment_all_methods

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 from experiments/configs (for each of the games from the paper) or create your own.
  • --dir_path path to the directory where the experiment results will be stored, you can omit this argument and the results will be stored in ./experiments_9_results You can also overwrite the config file with arguments, e.g.:
  • k the portfolio sizes, e.g. -k 4,5"
  • seed_num, this argument determines number of runs for each method. The default value is 50.
  • methods are 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.

generate plots for this experiment

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.json
  • evaluaition_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

experiment_eps_dom_exploitability

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 is experiments_eps_dom_exploitability_results.
  • --n: Game sizes (number of actions for each player) to be used. Default is 5,10,15.
  • --epsilon: Epsilon values to be used. Default is 0,0.25,0.5,0.75,1,1.25,1.5,1.75,2.
  • --num-games: Number of generated games. Default is 100.
  • --seed: Seed for random number generation. Default is 254.

experiment_dom_vs_greedy_k

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 is experiments_eps_dom_vs_greedy_k_results.
  • -n: Game sizes (number of actions for each player) to be used. Default is 15,20,25.
  • -k: Portfolio sizes to be used. Default is 1,2,3,4,5,6,7,8,9,10.
  • --num-games: Number of generated games. Default is 100.
  • --seed: Seed for random number generation. Default is 42.

Find portfolios for a specific game

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 is 2.
  • --method-seed: Seed for random number generation. Default is 42.
  • --evaluation-type: Type of evaluation to be used (e.g., "pessimistic", "optimistic", "RM+"). Default is pessimistic.
  • --info-max-dim: Maximal number of dimensions for the game analysis. Default is 6.
  • --c: Constant c for the gradient methods. Default is 0.3.
  • --rnad-max-steps: Maximal number of steps for the R-NaD algorithm. Default is 10000.
  • --rnad-epsilon: Epsilon for the R-NaD algorithm. Default is 1e-8.
  • --rnad-epsilon-ne: Epsilon NE for the grounding strategy for the R-NaD algorithm. Default is 0.
  • --rnad-reg-param: Regularization parameter for the R-NaD algorithm. Default is 0.20.
  • --clustering-scheme: Clustering scheme for the GCT method. Default is all_at_once.
  • --methods: Methods to be used for finding the portfolio. Default is OPPP,Alpha,GCT,eps_dom,eps_dom_mixed.
  • --game-name: Name of the game to be used. Default is rps. The games are defined in game_objects/games_collection.py.
  • --game-file: Path to the game file. Use this if you're not using game-name argument. Default is None.

This script will generate portfolios and a file with the results of the experiment. The portfolios will be saved in the output directory.


License

This project is licensed under the MIT License. See the LICENSE.txt file for details.

About

Code for portfolios of counterstrategies in large imperfect information games

Resources

Stars

0 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages