Skip to content

Commit

Permalink
'Refactored by Sourcery'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcery AI committed Jan 19, 2023
1 parent e71a2c2 commit 550d856
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion examples/merrill_1984_fig_2c_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions examples/merrill_1984_table_1_fig_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/wikipedia_condorcet_paradox_likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ 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:
is_CP[n_voters] += 1
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())
Expand Down

0 comments on commit 550d856

Please sign in to comment.