diff --git a/examples/merrill_1984_fig_2c_2d.py b/examples/merrill_1984_fig_2c_2d.py index 3230bdd..4e950d1 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 @@ -94,7 +95,7 @@ {'CW'})} start_time = time.monotonic() - for iteration in range(n): + for _ in range(n): 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 c5e11b5..210449f 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): +for _ in range(n): 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(count['SU max'].items())) -table.append(['SU max', *np.array(y)/y_cw*100]) - -# Likelihood of Condorcet Winner (normalized by n iterations) -table.append(['CW', *np.asarray(y_cw)/n*100]) - +table.extend( + ( + ['SU max', *np.array(y) / y_cw * 100], + ['CW', *np.asarray(y_cw) / n * 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 ae280be..863841c 100644 --- a/examples/wikipedia_condorcet_paradox_likelihood.py +++ b/examples/wikipedia_condorcet_paradox_likelihood.py @@ -53,7 +53,7 @@ def func(): for n_voters in WP_table: # Reuse the same chunk of memory to save time election = np.empty((n_voters, n_cands), dtype=np.uint8) - for iteration in range(batch): + for _ in range(batch): election[:] = impartial_culture(n_voters, n_cands) CW = condorcet(election) if CW is None: @@ -61,7 +61,7 @@ def func(): return is_CP -p = Parallel(n_jobs=-3, verbose=5)(delayed(func)() for i in range(n)) +p = Parallel(n_jobs=-3, verbose=5)(delayed(func)() for _ in range(n)) is_CP = sum(p, Counter()) x, y = zip(*WP_table.items())