Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
"""

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 96-96 refactored with the following changes:

import time
from collections import Counter
import numpy as np
Expand Down Expand Up @@ -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)
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 |
"""

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 54-133 refactored with the following changes:

This removes the following comments ( why? ):

# Likelihood of Condorcet Winner (normalized by n elections)

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_elections):
for _ in range(n_elections):
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(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
Expand Down
2 changes: 1 addition & 1 deletion examples/wikipedia_condorcet_paradox_likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function simulate_batch refactored with the following changes:

election[:] = impartial_culture(n_voters, n_cands)
CW = condorcet(election)
if CW is None:
Expand Down