diff --git a/.gitignore b/.gitignore index 819bd6f..43c83c3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ **.csv **.spec **.tex -**.sh **.pkl **/dist **/build diff --git a/batch-run.py b/batch-run.py index a231eca..dbec3f4 100644 --- a/batch-run.py +++ b/batch-run.py @@ -19,11 +19,11 @@ def main(): help='The identifier of this execution, to be used for naming the output files.') parser.add_argument('--seed', default=42, help='Seed for reproducibility (set seed=None if reproducibility is not required). Default is 42.') - parser.add_argument('--max_iterations', type=int, default=1000, + parser.add_argument('--max_iterations', type=int, default=5000, help='The maximum number of iterations of the system. Default is 1000.') parser.add_argument('--n', nargs="+", type=int, default=1000, help='The number of players (natural number). Default is 100.') - parser.add_argument('--k', nargs="+", type=int, default=[95, 110, 2], + parser.add_argument('--k', nargs="+", type=int, default=[100, 200, 2], help='The k value of the system (natural number). Default is 10.') parser.add_argument('--alpha', nargs="+", type=float, default=0.3, help='The alpha value of the system (decimal number between 0 and 1). Default is 0.3') @@ -66,6 +66,7 @@ def main(): "median_pools_per_operator": sim.get_median_pools_per_operator, "avgSatRate": sim.get_avg_sat_rate, "nakamotoCoeff": sim.get_nakamoto_coefficient, + "StatisticalDistance": sim.get_controlled_stake_distr_stat_dist, # "NCR": sim.get_NCR, #"MinAggregatePledge": sim.get_min_aggregate_pledge, # "pledge_rate": sim.get_pledge_rate, @@ -93,7 +94,7 @@ def main(): run_data_MP = batch_run_MP.get_model_vars_dataframe() # print(run_data_MP.head()) - output_dir = "output" + output_dir = "output/19-11-21" pickled_batch_run_data = output_dir + "/batch-run-data.pkl" with open(pickled_batch_run_data, "wb") as pkl_file: pkl.dump(run_data_MP, pkl_file) @@ -101,7 +102,7 @@ def main(): variable_param = list(variable_params.keys())[0] colours = [np.random.rand(3, ) for i in range(len(model_reporters))] for i, model_reporter in enumerate(model_reporters): - plot_aggregate_data(run_data_MP, variable_param, model_reporter, colours[i], args_dict["execution_id"]) + plot_aggregate_data(run_data_MP, variable_param, model_reporter, colours[i], args_dict["execution_id"], output_dir) # ordered dicts with data from each step of each run (the combinations of variable params act as the keys) # for example data_collector_model[(0.1, 0.02, 1)] shows the values of the parameters collected at model level @@ -112,8 +113,8 @@ def main(): plt.show() -def plot_aggregate_data(df, variable_param, model_reporter, color, exec_id): - figures_dir = "output/figures/" +def plot_aggregate_data(df, variable_param, model_reporter, color, exec_id, output_dir): + figures_dir = output_dir + "/figures/" plt.figure() plt.scatter(df[variable_param], df[model_reporter], color=color) plt.xlabel(variable_param) diff --git a/experiments.sh b/experiments.sh new file mode 100755 index 0000000..3c86b82 --- /dev/null +++ b/experiments.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +python3.9 main.py --simulation_id=baseline-100-10 --n=100 --k=10 --alpha=0.3 + +python3.9 main.py --simulation_id=baseline-1000-100 --n=1000 --k=100 --alpha=0.3 + +python3.9 main.py --simulation_id=abstention-30-100-10 --n=100 --k=10 --alpha=0.3 --abstention_rate=0.3 + +python3.9 main.py --simulation_id=parameter-change-k-100 --n=100 --k 10 20 --alpha=0.3 + +python3.9 main.py --simulation_id=parameter-change-alpha-100-10 --n=100 --k=10 --alpha 0.03 0.3 + +python3.9 main.py --simulation_id=parameter-change-k-1000 --n=1000 --k 100 200 --alpha=0.3 + +python3.9 main.py --simulation_id=parameter-change-alpha-1000-100 --n=1000 --k=100 --alpha 0.03 0.3 + +python3.9 main.py --simulation_id=alpha-zero-100-10 --n=100 --k=10 --alpha=0 + +python3.9 main.py --simulation_id=alpha-zero-1000-100 --n=1000 --k=100 --alpha=0 + +python3.9 batch-run.py --execution_id=varying-k-100 --n=100 --k 1 51 1 --alpha=0.3 + +python3.9 batch-run.py --execution_id=varying-alpha-1000-100 --n=1000 --k=100 --alpha 0 10 0.25 + +python3.9 batch-run.py --execution_id=varying-abstention-rate-1000-100 --n=1000 --k=100 --alpha=0.3 --abstention_rate 0 0.91 0.01 + +python3.9 batch-run.py --execution_id=varying-k-1000 --n=1000 --k 1 251 2 --alpha=0.3 + + + + diff --git a/logic/model_reporters.py b/logic/model_reporters.py index 53688d6..0ecb575 100644 --- a/logic/model_reporters.py +++ b/logic/model_reporters.py @@ -164,9 +164,11 @@ def get_controlled_stake_mean_abs_diff(model): def get_controlled_stake_distr_stat_dist(model): """ :param model: - :return: the statistical difference of the distributions of the stake that players control + :return: the statistical distance of the distributions of the stake that players control (how they started vs how they ended up) """ + if not model.has_converged(): + return -1 active_players = {player_id: player for player_id, player in model.get_players_dict().items() if not player.abstains} pools = model.get_pools_list() diff --git a/logic/sim.py b/logic/sim.py index 46cbf42..8920ab5 100644 --- a/logic/sim.py +++ b/logic/sim.py @@ -245,7 +245,7 @@ def dump_state_to_csv(self): "Private" if pool.is_private else "Public"] for pool in pools]) - output_dir = "output/" + output_dir = "output/19-11-21/" path = pathlib.Path.cwd() / output_dir pathlib.Path(path).mkdir(parents=True, exist_ok=True) filename = (path / (self.simulation_id + '-final_configuration.csv')) \ diff --git a/logic/stakeholder.py b/logic/stakeholder.py index d72a946..81071a1 100644 --- a/logic/stakeholder.py +++ b/logic/stakeholder.py @@ -173,7 +173,7 @@ def calculate_delegator_utility(self, pool, stake_allocation): m_factor = (1 - pool.margin) * q u_0 = (r - pool.cost) u = m_factor * u_0 - utility = max(0, u) + utility = u if u > 0 else 0 return utility # how does a myopic player decide whether to open a pool or not? -> for now we assume that all players play non-myopically when it comes to pool moves diff --git a/main.py b/main.py index 28944d8..4575cac 100644 --- a/main.py +++ b/main.py @@ -10,9 +10,9 @@ def main(): print("Let the Pooling Games begin!") parser = argparse.ArgumentParser(description='Pooling Games') - parser.add_argument('--n', type=int, default=1000, + parser.add_argument('--n', type=int, default=100, help='The number of players (natural number). Default is 100.') - parser.add_argument('--k', nargs="+", type=int, default=40, + parser.add_argument('--k', nargs="+", type=int, default=10, help='The k value of the system (natural number). Default is 10.') parser.add_argument('--alpha', nargs="+", type=float, default=0.3, help='The alpha value of the system (decimal number between 0 and 1). Default is 0.3') @@ -91,8 +91,8 @@ def main(): with open(pickled_simulation_filename, "wb") as pkl_file: pkl.dump(sim, pkl_file) - output_dir = "output/" - figures_dir = "output/figures/" + output_dir = "output/19-11-21/" + figures_dir = output_dir + "figures/" path = pathlib.Path.cwd() / figures_dir pathlib.Path(path).mkdir(parents=True, exist_ok=True) @@ -112,16 +112,16 @@ def main(): pivot_steps = sim.pivot_steps plot_line(simulation_id, sim_df["#Pools"], 'C0', "Number of pools over time", "Round", - "#Pools", "poolCount", equilibrium_steps, pivot_steps, True) + "#Pools", "poolCount", equilibrium_steps, pivot_steps, figures_dir, True) plot_line(simulation_id, sim_df["AvgPledge"], 'red', "Average pledge over time", "Round", - "Average pledge", "avgPledge", equilibrium_steps, pivot_steps, True) + "Average pledge", "avgPledge", equilibrium_steps, pivot_steps, figures_dir, True) plot_line(simulation_id, sim_df["TotalPledge"], 'purple', "Total pledge over time", "Round", - "Total pledge", "totalPledge", equilibrium_steps, pivot_steps, True) + "Total pledge", "totalPledge", equilibrium_steps, pivot_steps, figures_dir, True) plot_line(simulation_id, sim_df["MeanAbsDiff"], 'green', "Mean Absolute Difference of Controlled Stake", "Round", - "Mean abs diff", "meanAbsDiff", equilibrium_steps, pivot_steps, False) + "Mean abs diff", "meanAbsDiff", equilibrium_steps, pivot_steps, figures_dir, False) '''pool_sizes_by_step = sim_df["PoolSizes"] # todo fix # print(pool_sizes_by_step) @@ -136,8 +136,7 @@ def main(): def plot_line(simulation_id, data, color, title, x_label, y_label, filename, equilibrium_steps, pivot_steps, - show_equilibrium=False): - figures_dir = "output/figures/" + figures_dir, show_equilibrium=False): path = pathlib.Path.cwd() / figures_dir pathlib.Path(path).mkdir(parents=True, exist_ok=True) @@ -153,7 +152,7 @@ def plot_line(simulation_id, data, color, title, x_label, y_label, filename, equ for i, step in enumerate(pivot_steps): label = "Parameter change" if i == 0 else "" plt.plot(step, data[step], 'x', label=label, c=pivot_colour) - plt.title(title) + #plt.title(title) plt.xlabel(x_label) plt.ylabel(y_label) plt.legend()