<jupyter_start><jupyter_text>Efficiency and Performance<jupyter_code>%matplotlib inline
import time
import pymarket as pm
import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Create a set of markets with varying number of participants<jupyter_code>markets = []
range_players = np.arange(20, 200, 20)
M = len(range_players)

for i in range_players:
    bids = pm.datasets.generate(i, i, 2, 1)
    mar = pm.Market()
    for b in bids:
        mar.accept_bid(*b)
    markets.append(mar)<jupyter_output><empty_output><jupyter_text>Run the diferent markets<jupyter_code>elapsed = np.zeros(M)
for i in range(M):
    mar = markets[i]
    start = time.time()
    mar.run('huang')
    stop = time.time()
    elapsed[i] = stop - start
fig, ax = plt.subplots()
ax.plot(range_players, elapsed)
_ = ax.set_xlabel('Number of Players')
_ = ax.set_ylabel('Elapsed Time (s)')
_ = ax.set_title('Performance')<jupyter_output><empty_output><jupyter_text>Obtains the statistics (optimization problems have to be solved)<jupyter_code>traded = np.zeros(M)
welfare = np.zeros(M)
stats_time = np.zeros(M)

limit = M
for i in range(limit):
    mar = markets[i]
    start = time.time()
    stats = mar.statistics()
    stop = time.time()
    stats_time[i] = stop - start
    welfare[i] = stats['percentage_welfare']
    traded[i] = stats['percentage_traded']<jupyter_output><empty_output><jupyter_text>Plots the results<jupyter_code>fig, ax = plt.subplots(1, 3, figsize=(18, 6))

ax[0].plot(range_players[:limit], stats_time[:limit])
ax[0].set_ylabel('Elapsed Time (s)')

ax[1].plot(range_players[:limit], welfare[:limit])
ax[1].set_ylabel(' % Total welfare')

ax[2].plot(range_players[:limit], traded[:limit])
ax[2].set_ylabel(' % Total traded')

for ax_ in ax:
    ax_.set_xlabel('Number of Players')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1419284940411701, 'fraction_numerical': 0.010834236186348862, 'mean_word_length': 5.347079037800687, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '389984', 'license': 'MIT', 'n_tokens_mistral': 715, 'n_tokens_neox': 699, 'n_words': 143, 'path': 'docs/Efficiency and performance.ipynb', 'repo_name': 'taqtiqa-mark/pymarket', 'size': '1846'}