In [9]:
import numpy as np
import pandas as pd
In [10]:
amplifiers = np.genfromtxt('amplifiers_0.csv',delimiter=',').astype(int)
print(amplifiers)
normals = 1-amplifiers
print(normals)
In [ ]:
In [11]:
weights_biased = np.atleast_2d(np.genfromtxt('weights-biased_0.csv', delimiter=','))
weights_unbiased = np.atleast_2d(np.genfromtxt('weights-unbiased_0.csv', delimiter=','))
condorcet_biased = np.atleast_2d(np.genfromtxt('condorcet-biased_0.csv', delimiter=','))
unanimity_biased = np.atleast_2d(np.genfromtxt('unanimity_0.csv', delimiter=','))
In [12]:
print(weights_biased[:,amplifiers.astype(bool)].mean(axis=0))
print(weights_biased[:,normals.astype(bool)].mean(axis=0))
In [13]:
print(weights_unbiased[:,amplifiers.astype(bool)].mean(axis=0))
print(weights_unbiased[:,normals.astype(bool)].mean(axis=0))
In [14]:
print(condorcet_biased[:,amplifiers.astype(bool)].mean(axis=0))
print(condorcet_biased[:,normals.astype(bool)].mean(axis=0))
In [15]:
print(unanimity_biased[:,amplifiers.astype(bool)].mean(axis=0))
print(unanimity_biased[:,normals.astype(bool)].mean(axis=0))
In [16]:
n_experiments = 200
all_weights_ub_amp_means = []
all_weights_ub_namp_means = []
all_weights_amp_means = []
all_weights_namp_means = []
all_condorcet_amp_means = []
all_condorcet_namp_means = []
all_unanimity_amp_means = []
all_unanimity_namp_means = []
for i in range(n_experiments):
amplifiers = np.genfromtxt('amplifiers_%d.csv' %i ,delimiter=',').astype(int)
normals = 1-amplifiers
if(sum(amplifiers) == 0 or sum(normals) == 0):
continue
weights_biased = np.atleast_2d(np.genfromtxt('weights-biased_%d.csv' % i, delimiter=','))
#print("----- WEIGHTS ")
#print("----- amplifiers")
#print(weights_biased[:,amplifiers.astype(bool)])
#print(weights_biased[:,amplifiers.astype(bool)].mean())
all_weights_amp_means += [weights_biased[:,amplifiers.astype(bool)].mean()]
#print("----- non amplifiers")
#print(weights_biased[:,normals.astype(bool)])
#print(weights_biased[:,normals.astype(bool)].mean())
all_weights_namp_means += [weights_biased[:,normals.astype(bool)].mean()]
weights_unbiased = np.atleast_2d(np.genfromtxt('weights-unbiased_%d.csv' % i, delimiter=','))
all_weights_ub_amp_means += [weights_unbiased[:,amplifiers.astype(bool)].mean()]
all_weights_ub_namp_means += [weights_unbiased[:,normals.astype(bool)].mean()]
condorcet_biased = np.atleast_2d(np.genfromtxt('condorcet-biased_%d.csv' % i, delimiter=','))
#print("----- CONDORCET ")
#print("----- amplifiers")
#print(condorcet_biased[:,amplifiers.astype(bool)])
#print(condorcet_biased[:,amplifiers.astype(bool)].mean())
all_condorcet_amp_means += [condorcet_biased[:,amplifiers.astype(bool)].mean()]
#print("----- non amplifiers")
#print(condorcet_biased[:,normals.astype(bool)])
#print(condorcet_biased[:,normals.astype(bool)].mean())
all_condorcet_namp_means += [condorcet_biased[:,normals.astype(bool)].mean()]
unanimity_biased = np.atleast_2d(np.genfromtxt('unanimity_%d.csv' % i, delimiter=','))
all_unanimity_amp_means += [unanimity_biased[:,amplifiers.astype(bool)].mean()]
all_unanimity_namp_means += [unanimity_biased[:,normals.astype(bool)].mean()]
In [17]:
all_weights_amp_means
Out[17]:
In [18]:
all_weights_namp_means
Out[18]:
In [19]:
all_condorcet_amp_means
Out[19]:
In [20]:
all_condorcet_namp_means
Out[20]:
In [21]:
# Credit: Josh Hemann
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
from collections import namedtuple
n_groups = 5
means_men = (20, 35, 30, 35, 27)
std_men = (2, 3, 4, 1, 2)
means_women = (25, 32, 34, 20, 25)
std_women = (3, 5, 2, 3, 3)
fig, ax = plt.subplots()
index = np.arange(n_groups)
bar_width = 0.35
opacity = 0.4
error_config = {'ecolor': '0.3'}
rects1 = ax.bar(index, means_men, bar_width,
alpha=opacity, color='b',
yerr=std_men, error_kw=error_config,
label='Men')
rects2 = ax.bar(index + bar_width, means_women, bar_width,
alpha=opacity, color='r',
yerr=std_women, error_kw=error_config,
label='Women')
ax.set_xlabel('Group')
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(index + bar_width / 2)
ax.set_xticklabels(('A', 'B', 'C', 'D', 'E'))
ax.legend()
fig.tight_layout()
plt.show()
In [22]:
# Credit: Josh Hemann
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
from collections import namedtuple
n_groups = 4 # weighted and condorcet
# within each group amplifiers and non-amplifiers correspond to men and women
all_weights_ub_amp_means = np.array(all_weights_ub_amp_means)
all_weights_ub_namp_means = np.array(all_weights_ub_namp_means)
all_weights_amp_means = np.array(all_weights_amp_means)
all_weights_namp_means = np.array(all_weights_namp_means)
all_condorcet_amp_means = np.array(all_condorcet_amp_means)
all_condorcet_namp_means = np.array(all_condorcet_namp_means)
all_unanimity_amp_means = np.array(all_unanimity_amp_means)
all_unanimity_namp_means = np.array(all_unanimity_namp_means)
means_amp = (all_weights_ub_amp_means.mean(), all_weights_amp_means.mean(), all_condorcet_amp_means.mean(), all_unanimity_amp_means.mean())
std_amp = (all_weights_ub_amp_means.std(), all_weights_amp_means.std(), all_condorcet_amp_means.std(), all_unanimity_amp_means.std())
means_namp = (all_weights_ub_namp_means.mean(), all_weights_namp_means.mean(), all_condorcet_namp_means.mean(), all_unanimity_namp_means.mean())
std_namp = (all_weights_ub_namp_means.std(), all_weights_namp_means.std(), all_condorcet_namp_means.std(), all_unanimity_namp_means.std())
fig, ax = plt.subplots()
index = np.arange(n_groups)
bar_width = 0.35
opacity = 0.4
error_config = {'ecolor': '0.3'}
rects1 = ax.bar(index, means_amp, bar_width,
alpha=opacity, color='b',
yerr=std_amp, error_kw=error_config,
label='Amplifiers')
rects2 = ax.bar(index + bar_width, means_namp, bar_width,
alpha=opacity, color='r',
yerr=std_namp, error_kw=error_config,
label='Non-amplifiers')
ax.set_xlabel('Group')
ax.set_ylabel('Satisfaction degrees')
ax.set_title('Satisfaction degrees by voting function and group')
ax.set_xticks(index + bar_width / 2)
ax.set_xticklabels(('WCSP Unbiased', 'WCSP Biased', 'Condorcet', 'Pareto / Unanimity'))
ax.legend()
fig.tight_layout()
plt.savefig("lunch-selection-comparison.pdf")
plt.show()
In [23]:
all_weights_amp_means
Out[23]:
In [24]:
means_amp
Out[24]:
In [25]:
means_namp
Out[25]:
In [26]:
means_amp
Out[26]:
In [ ]: