diff --git a/examples/merrill_1984_fig_2c_2d.py b/examples/merrill_1984_fig_2c_2d.py index 98bf8cc9..cdd6426e 100644 --- a/examples/merrill_1984_fig_2c_2d.py +++ b/examples/merrill_1984_fig_2c_2d.py @@ -41,6 +41,7 @@ running as many simulations, however the Coombs results are consistently high. """ + import time from collections import Counter import numpy as np @@ -93,7 +94,7 @@ ranked_methods.keys() | rated_methods.keys() | {'CW'})} start_time = time.monotonic() - for iteration in range(n_elections): + for _ in range(n_elections): for n_cands in n_cands_list: v, c = normal_electorate(n_voters, n_cands, dims=D, corr=corr, disp=disp) diff --git a/examples/merrill_1984_table_1_fig_1.py b/examples/merrill_1984_table_1_fig_1.py index 8861ff16..9de59784 100644 --- a/examples/merrill_1984_table_1_fig_1.py +++ b/examples/merrill_1984_table_1_fig_1.py @@ -24,6 +24,7 @@ | SU max | 100.0 | 84.1 | 79.6 | 78.4 | 77.3 | 77.5 | | CW | 100.0 | 91.7 | 83.1 | 75.6 | 64.3 | 52.9 | """ + import time from collections import Counter import numpy as np @@ -51,7 +52,7 @@ start_time = time.monotonic() -for iteration in range(n_elections): +for _ in range(n_elections): for n_cands in n_cands_list: utilities = random_utilities(n_voters, n_cands) @@ -126,11 +127,12 @@ # Likelihood that social utility maximizer is Condorcet Winner x, y = zip(*sorted(condorcet_winner_count['SU max'].items())) -table.append(['SU max', *np.array(y)/y_cw*100]) - -# Likelihood of Condorcet Winner (normalized by n elections) -table.append(['CW', *np.asarray(y_cw) / n_elections * 100]) - +table.extend( + ( + ['SU max', *np.array(y) / y_cw * 100], + ['CW', *np.asarray(y_cw) / n_elections * 100], + ) +) print(tabulate(table, ["Method", *x], tablefmt="pipe", floatfmt='.1f')) plt.plot([], [], 'k:', lw=0.8, label='Merrill') # Dummy plot for label diff --git a/examples/wikipedia_condorcet_paradox_likelihood.py b/examples/wikipedia_condorcet_paradox_likelihood.py index 3518858a..53d8c7a3 100644 --- a/examples/wikipedia_condorcet_paradox_likelihood.py +++ b/examples/wikipedia_condorcet_paradox_likelihood.py @@ -52,7 +52,7 @@ def simulate_batch(n_voters): condorcet_paradox_count = Counter() # Reuse the same chunk of memory to save time election = np.empty((n_voters, n_cands), dtype=np.uint8) - for iteration in range(batch_size): + for _ in range(batch_size): election[:] = impartial_culture(n_voters, n_cands) CW = condorcet(election) if CW is None: