コード例 #1
0
    #"EqualSay_G1_Default",
    #"Random_Dictator",
    #"Player1_Dictator",
    #"EqualSay_G2_Default",
    #"EqualSay_G1_Default",
    #"Player1_Dictator",
    #"Random_Dictator",
]

#transition = transitions[0]
transition = "EqualSay_G1_Default"

# 1.0 - 10**(-2) = 0.99 -> exponent = num decimal places
delta = 1.0 - 10**(-11)
S8_game = S_8_Game(c=c, b1=1.8, b2=b2, game_transition_dynamics=transition)
S12_game = S_12_Game(c=c, b1=1.8, b2=b2, game_transition_dynamics=transition)
S16_game = S_16_Game(c=c, b1=1.8, b2=b2, game_transition_dynamics=transition)

games = [S8_game, S12_game, S16_game]

folder_timestamp = time.strftime("date_%Y_%m_%d_%H_%M_%S")
params_str = "c_{:.2f}_b2_{:.2f}_delta_{:.10f}".format(c, b2, delta)

b1_list = np.arange(1.0, 3.2, 0.14)


def run_dict(b1_list):
    d = {}

    parent_folder = "data/full_coop_spe/dict/{:s}/"\
         .format(params_str)
コード例 #2
0
transitions = [
    #"EqualSay_G1_Default",
    #"Random_Dictator",
    #"Player1_Dictator",
    "EqualSay_G2_Default",
    #"EqualSay_G1_Default",
    #"Player1_Dictator",
    #"Random",
]

transition = transitions[0]

# 1.0 - 10**(-2) = 0.99 -> exponent = num decimal places
delta = 1.0 - 10**(-5)
S08_game = S_8_Game(c=c, b1=1.8, b2=b2, game_transition_dynamics=transition)
S12_game = S_12_Game(c=c, b1=1.8, b2=b2, game_transition_dynamics=transition)
S16_game = S_16_Game(c=c, b1=1.8, b2=b2, game_transition_dynamics=transition)

games = [S08_game, S12_game, S16_game]

s_08_strat = (1, 0, 0, 1, 1, 0, 0, 0)
s_12_strat = (1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0)

v_s08 = S08_game.get_stationary_dist(s_08_strat, s_08_strat, S08_game.f)
v_s12 = S12_game.get_stationary_dist(s_12_strat, s_12_strat, S12_game.f)

print("v_s08: ", v_s08[0])
print("v_s12: ", v_s12[0])

s_08_strat_allc2 = (1, 1, 1, 1, 0, 0, 0, 0)
s_08_strat_allc1 = (1, 1, 1, 1, 1, 1, 1, 1)
コード例 #3
0
lst1 = [10**-4, 10**-3, 10**-2, 10**-1, 10**0, 10**1, 10**2]
lst2 = [2, 4, 8, 16, 32, 64, 128]

lst3 = [10**-1, 10**0, 10**1]
lst4 = [10**-4, 10**-3, 10**-2, 10**-2, 10**-1]

lst5 = [10**-4]

param_to_change, param_list = ("N", lst2)

fixed_b1 = 1.8
hacky_spe_b1 = 1.84

transition = "EqualSay_G2_Default"
game = S_12_Game(c=c, b1=fixed_b1, b2=b2, game_transition_dynamics=transition)

# define folder name
folder_timestamp = time.strftime("date_%Y_%m_%d_%H_%M_%S")
subfolder = "param_effect_fixed/{:s}/{:s}/".format(param_to_change,
                                                   folder_timestamp)

data_folder = "data/{:s}".format(subfolder)
img_folder = data_folder


def do_runs(param_value, params_dict, spe_d):

    data_filename = "{:s}{:s}_{:2f}.csv".format(
        data_folder, param_to_change, param_value)  #get_filename(param_value)
コード例 #4
0
data_folder = get_folder(folder_timestamp, directory="data/game_comp/")
img_folder = get_folder(folder_timestamp, directory="imgs/game_comp/")

print("\nData Folder: {:s}\n".format(data_folder))

#b1_list = np.arange(1.0, 3.2, 0.56)
#b1_list = [1.8]
#b1_list = np.arange(1.0, 3.2, 0.14)

transition = transitions[0]
games = [
    #S_2_Game(c=1.0, b1=1.2),
    #S_4_Game(c=1.0, b1=b2),
    #S_4_Game(c=1.0, b1=b1),
    #S_8_Game(c=1.0, b1=b1, b2=b2,  game_transition_dynamics=transitions[0]),
    S_12_Game(c=1.0, b1=b1, b2=b2, game_transition_dynamics=transitions[0]),
    #S_16_Game(c=1.0, b1=b1, b2=b2, game_transition_dynamics=transitions[0]),
]


def do_run(run_id, data_folder, game_str, num_timesteps, params_dict, game_b1):
    data_filename = data_folder + game_str + "_game_b1_{:.2f}".format(game_b1) \
         + "_run_{:d}".format(run_id) + ".csv"

    # announce what we are calculating
    print("Game: {:s}, Run: {:d}".format(game_str, run_id))

    # get data
    start_time = time.time()
    player_c_list = get_evolution_all(num_timesteps, params_dict, game_b1)
    elapsed_time = time.time() - start_time
コード例 #5
0
transitions = [
    #"NA",
    "EqualSay_G2_Default",
    #"EqualSay_G1_Default",
    #"Unilateral_Dictator",
    #"Random_Dictator",
    #"Random",
]

# b1_list = np.arange(1.0, 3.2, 0.14)

games = [
    #S_2_Game(c=1.0, b1=1.2),
    #S_4_Game(c=1.0, b1=2.0),
    #S_8_Game(c=1.0, b1=2.0, b2=1.2,  game_transition_dynamics=transitions[0]),
    S_12_Game(c=1.0, b1=2.0, b2=1.2, game_transition_dynamics=transitions[0]),
    S_16_Game(c=1.0, b1=2.0, b2=1.2, game_transition_dynamics=transitions[0]),
]

save_params_dict = {

    # test params
    "num_runs": num_runs,
    "num_timesteps": num_timesteps,

    # evolutionary params
    "N": 100,
    "eps": 0.001,
    "beta": 2.0,
    "strategy_type": "pure",  # or "stochastic"
コード例 #6
0
print("\nFolder: {:s}\n".format(folder))

b1_list = [1.8]

b1 = 1.8

c = 1.0
b2 = 1.2

#np.arange(1.0, 3.2, 0.14)
# games   = [
# 			S_4_Game(c=1.0, b1=2.0),
# 			S_12_Game(c=1.0, b1=2.0, b2=1.2), S_16_Game(c=1.0, b1=2.0, b2=1.2)
# 		]
games = [S_8_Game(c, b1, b2), S_12_Game(c, b1, b2), S_16_Game(c, b1, b2)]


def get_filepath(game_str, eps, beta, num_timesteps):
    params_str = "{:s}_T_{:.2e}".format(game_str, num_timesteps)
    filepath = folder + params_str + ".csv"
    return filepath


def write_b1_effect_data():

    eps, beta = get_params(["eps", "beta"], params_dict)

    for num_timesteps in num_timesteps_list:

        for game in games:
コード例 #7
0
from class_one_games import S_2_Game, S_4_Game
from class_two_games import S_8_Game, S_12_Game, S_16_Game
from simulation_evolution_avgs import *

import pandas as pd
import pathlib  # to create directory if needed

from parameters import *
from helper_functions import save_dict, read_dict

param_to_change, param_list = ("N", [128])

b1_list = np.arange(1.0, 3.2, 0.14)
game = S_12_Game(c=c,
                 b1=1.8,
                 b2=b2,
                 game_transition_dynamics="EqualSay_G2_Default")

# define folder name
folder_timestamp = time.strftime("date_%Y_%m_%d_%H_%M_%S")
subfolder = "param_effect/{:s}/{:s}/".format(param_to_change, folder_timestamp)

data_folder = "data/{:s}".format(subfolder)
img_folder = data_folder


def save_params(folder, params_filename="params"):
    # create directory
    pathlib.Path(folder).mkdir(parents=True, exist_ok=True)

    dict_to_save = {key: val for key, val in save_params_dict.items()}
コード例 #8
0
import numpy as np
import matplotlib.pyplot as plt
import time

from class_one_games import S_2_Game, S_4_Game
from class_two_games import S_12_Game, S_16_Game
from helper_functions import *

from simulation_evolution_avgs import *

# Parameters
num_timesteps = 10**4

game = S_12_Game(c=1.0, b1=2.0, b2=1.2, \
    game_transition_dynamics = "EqualSay_G2_Default", num_timesteps= num_timesteps)
params_dict = {
    "game": game,
    "N": 100,
    "eps": 0.001,
    "beta": 2.0,
    "host": tuple(0.005 for _ in range(game.strat_len)),
    "strategy_type": "pure",  # or "stochastic"
}

b1_list = np.arange(1.0, 3.2, 0.42)
start_time = time.time()
#g1_cc_avg, g2_cc_avg, g1_rate = get_evolution_avgs(num_timesteps, params_dict)
get_b1_evolution_data(num_timesteps, b1_list, params_dict)
elapsed_time = time.time() - start_time

print("Elapsed Time: {:.2f} min".format(elapsed_time / 60.0))