Skip to content

Latest commit

 

History

History
104 lines (70 loc) · 2.49 KB

README.md

File metadata and controls

104 lines (70 loc) · 2.49 KB

IPDF - Iterated Prisoner's Dilemma Framework

Library for the iterated evolutionary tournaments between memory-based agents.

Table of Contents

  1. Installation
  2. Usage
    2.1 Strategies
    2.2 Game
    2.3 Memory based strategies storage
    2.4 Memory tournament
  3. Development

Installation

pip install ipdframework

Usage

Strategies

Memory Based

Create new instance of the memory based strategy (from responses sequence):

from ipdf.strategies.memory_based import MemoryBasedStrategy

strategy = MemoryBasedStrategy(sequence_str='101')
print(strategy.name(), '=>', strategy_1.responses)

Game

Game class allows users to emulate interactions between two strategies

from ipdf.game import Game
from ipdf.strategies.memory_based import MemoryBasedStrategy
from ipdf.payment_matrix import init_default_payment_matrix

matrix = init_default_payment_matrix()
n_moves = 20

str1 = MemoryBasedStrategy(sequence_str='1011011')
str2 = MemoryBasedStrategy(sequence_str='0110011')
game = Game(matrix, str1, str2)
game.play(n_moves)
game.log_game_info()

Memory based strategies storage

MemoryStrategiesStorage class allows you to generate and store memory-based strategies.

Used to generate a pack with evey possible strategy with certain memory depth.

from ipdf.memory_strategies_storage import MemoryStrategiesStorage

mem_depth = 1
strategies_st = MemoryStrategiesStorage(mem_depth)
strategies_st.log_storage_info()

for strategy in strategies_st.strategies():
    print(strategy.responses)

Memory tournament

Encapsulates evolutionary tournament logic.

Class allows user to emulate tournament between each and every strategy with certain memory depth. Users can set memory depth and number of interactions between each pair of strategies.

from ipdf.memory_tournament import MemoryStrategiesTournament
from ipdf.payment_matrix import init_default_payment_matrix

num_of_interactions = 50
mem_depth = 2

payment_matrix = init_default_payment_matrix()
memory_strategies_tournament = MemoryStrategiesTournament(mem_depth, payment_matrix)
memory_strategies_tournament.play(num_of_interactions)
memory_strategies_tournament.save()

Development

Python version: 3.6+

Install w/ dev dependencies:

pip install -e .[dev]

Author

M.S. CS Dmytro Tkachuk
https://dmtk.app