Skip to content
Open
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
10 changes: 9 additions & 1 deletion examples/merrill_1984_fig_2c_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import time
from collections import Counter
import numpy as np
from scipy.stats import binomtest
import matplotlib.pyplot as plt
from tabulate import tabulate
from elsim.methods import (fptp, runoff, irv, approval, borda, coombs,
Expand Down Expand Up @@ -140,7 +141,14 @@
'Plurality'):
x, y = zip(*sorted(condorcet_winner_count[method].items()))
CE = np.array(y)/y_cw
plt.plot(x, CE*100, '-', label=method)

# Add 95% confidence interval error bars (Clopper-Pearson exact method)
ci = np.empty((2, len(y)))
for i in range(len(y)):
ci[:, i] = binomtest(y[i], y_cw[i]).proportion_ci()
yerr = ci - CE
yerr[0] = -yerr[0]
plt.errorbar(x, CE*100, yerr*100, fmt='-', label=method)
table.append([method, *CE*100])

print(tabulate(table, ["Method", *x], tablefmt="pipe", floatfmt='.1f'))
Expand Down
10 changes: 9 additions & 1 deletion examples/merrill_1984_table_1_fig_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import time
from collections import Counter
import numpy as np
from scipy.stats import binomtest
import matplotlib.pyplot as plt
from tabulate import tabulate
from elsim.methods import (fptp, runoff, irv, approval, borda, coombs,
Expand Down Expand Up @@ -113,7 +114,14 @@
'Black'):
x, y = zip(*sorted(condorcet_winner_count[method].items()))
CE = np.array(y)/y_cw
plt.plot(x, CE*100, '-', label=method)

# Add 95% confidence interval error bars (Clopper-Pearson exact method)
ci = np.empty((2, len(y)))
for i in range(len(y)):
ci[:, i] = binomtest(y[i], y_cw[i]).proportion_ci()
yerr = ci - CE
yerr[0] = -yerr[0]
plt.errorbar(x, CE*100, yerr*100, fmt='-', label=method)
table.append([method, *np.array(y)/y_cw*100])

# Likelihood that social utility maximizer is Condorcet Winner
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/results/Wikipedia_Condorcet_paradox_likelihood.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion examples/wikipedia_condorcet_paradox_likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"""
from collections import Counter
import numpy as np
from scipy.stats import binomtest
import matplotlib.pyplot as plt
from tabulate import tabulate
from joblib import Parallel, delayed
Expand Down Expand Up @@ -71,7 +72,14 @@ def simulate_batch(n_voters):

x, y = zip(*sorted(condorcet_paradox_counts.items()))
CP = np.asarray(y) / n_elections # Likelihood of paradox
plt.plot(x, CP*100, '-', label='Simulation')

# Add 95% confidence interval error bars (Clopper-Pearson exact method)
ci = np.empty((2, len(y)))
for i in range(len(y)):
ci[:, i] = binomtest(y[i], n_elections).proportion_ci()
yerr = ci - CP
yerr[0] = -yerr[0]
plt.errorbar(x, CP*100, yerr*100, fmt='-', label='Simulation')

plt.legend()
plt.grid(True, color='0.7', linestyle='-', which='major', axis='both')
Expand Down