- class svvamp.ProfileSubsetCandidates(parent_profile, candidates_subset)[source]#
Sub-profile for a subset of the original candidates.
This class is used internally by SVVAMP. It is not intended for the end user.
- Parameters:
Notes
N.B.: if candidates_subset is a list of integers, it must be sorted in ascending order.
N.B.: in this object, candidates are re-numbered, for example [0, 1, 2]. So, if the winner of an election is w in the sub-profile, it corresponds to candidates_subset[w] in the parent profile (supposing that candidates_subset is given as a list of indexes, not as a list of booleans).
Examples
>>> initialize_random_seeds() >>> preferences_ut_test = np.random.randint(-5, 5, (10, 5)) >>> parent_profile = Profile(preferences_ut=preferences_ut_test) >>> profile = ProfileSubsetCandidates(parent_profile=parent_profile, candidates_subset=[0, 1, 2]) >>> profile.labels_candidates ['0', '1', '2'] >>> profile.preferences_borda_ut array([[2. , 0. , 1. ], [2. , 0. , 1. ], [1. , 0. , 2. ], [0. , 1.5, 1.5], [0. , 2. , 1. ], [1.5, 0. , 1.5], [0. , 1. , 2. ], [0.5, 0.5, 2. ], [1.5, 1.5, 0. ], [1. , 0. , 2. ]]) >>> profile.matrix_duels_ut array([[0, 5, 3], [3, 0, 2], [6, 7, 0]]) >>> profile.matrix_duels_rk array([[0, 6, 3], [4, 0, 2], [7, 8, 0]]) >>> profile.matrix_victories_ut_abs array([[0. , 0.5, 0. ], [0. , 0. , 0. ], [1. , 1. , 0. ]]) >>> profile.matrix_victories_ut_abs_ctb array([[0., 1., 0.], [0., 0., 0.], [1., 1., 0.]]) >>> profile.matrix_victories_ut_rel array([[0., 1., 0.], [0., 0., 0.], [1., 1., 0.]]) >>> profile.matrix_victories_ut_rel_ctb array([[0., 1., 0.], [0., 0., 0.], [1., 1., 0.]]) >>> profile.matrix_victories_rk array([[0., 1., 0.], [0., 0., 0.], [1., 1., 0.]]) >>> profile.matrix_victories_rk_ctb array([[0., 1., 0.], [0., 0., 0.], [1., 1., 0.]]) >>> profile.total_utility_c array([ 2, -8, 6])
Instead, the subset of candidates can be given by a list of Booleans:
>>> profile = ProfileSubsetCandidates( ... parent_profile=parent_profile, ... candidates_subset=[True, True, True, False, False] ... ) >>> profile.n_c 3
- property labels_candidates#
List of
n_c
strings (names of the candidates).
- property matrix_duels_rk#
2d array of integers.
matrix_duels_rk[c, d]
is the number of voters who rank candidatec
befored
(in the sense ofpreferences_rk
). By convention, diagonal coefficients are set to 0.>>> from svvamp import Profile >>> profile = Profile(preferences_rk=[[0, 1, 2], [0, 1, 2]]) >>> profile.matrix_duels_rk array([[0, 2, 2], [0, 0, 2], [0, 0, 0]])
- property matrix_duels_ut#
2d array of integers.
matrix_duels_ut[c, d]
is the number of voters who have a strictly greater utility forc
than ford
. By convention, diagonal coefficients are set to0
.>>> from svvamp import Profile >>> profile = Profile(preferences_rk=[[0, 1, 2], [0, 1, 2]]) >>> profile.matrix_duels_ut array([[0, 2, 2], [0, 0, 2], [0, 0, 0]])
- property matrix_victories_rk#
2d array of values in {0, 0.5, 1}. Matrix of victories based on
matrix_duels_rk
.matrix_victories_rk[c, d]
is:1 iff
matrix_duels_rk[c, d] > matrix_duels_rk[d, c]
, i.e. iffmatrix_duels_rk[c, d] > V / 2
.0.5 iff
matrix_duels_rk[c, d] = matrix_duels_rk[d, c]
, i.e. iffmatrix_duels_rk[c, d] = V / 2
.0 iff
matrix_duels_rk[c, d] < matrix_duels_rk[d, c]
, i.e. iffmatrix_duels_rk[c, d] < V / 2
.
By convention, diagonal coefficients are set to 0.
Examples
A victory:
>>> profile = Profile(preferences_rk=[[0, 1], [0, 1]]) >>> profile.matrix_victories_rk array([[0., 1.], [0., 0.]])
A tie:
>>> profile = Profile(preferences_rk=[[0, 1], [1, 0]]) >>> profile.matrix_victories_rk array([[0. , 0.5], [0.5, 0. ]])
- property matrix_victories_rk_ctb#
2d array of values in {0, 1}. Matrix of victories based on
matrix_duels_rk
, with tie-breaks on candidates.matrix_victories_rk_ctb[c, d]
is:1 iff
matrix_duels_rk[c, d] > matrix_duels_rk[d, c]
, ormatrix_duels_rk[c, d] = matrix_duels_rk[d, c]
andc < d
.0 iff
matrix_duels_rk[c, d] < matrix_duels_rk[d, c]
, ormatrix_duels_rk[c, d] = matrix_duels_rk[d, c]
andd < c
.
By convention, diagonal coefficients are set to 0.
Examples
A victory (without tie-breaking):
>>> profile = Profile(preferences_rk=[[0, 1], [0, 1]]) >>> profile.matrix_victories_rk_ctb array([[0., 1.], [0., 0.]])
A victory with tie-breaking:
>>> profile = Profile(preferences_rk=[[0, 1], [1, 0]]) >>> profile.matrix_victories_rk_ctb array([[0., 1.], [0., 0.]])
- property matrix_victories_ut_abs#
2d array of values in {0, 0.5, 1}. Matrix of absolute victories based on
matrix_duels_ut
.matrix_victories_ut_abs[c, d]
is:1 iff
matrix_duels_ut[c, d] > V / 2
.0.5 iff
matrix_duels_ut[c, d] = V / 2
.0 iff
matrix_duels_ut[c, d] < V / 2
.
By convention, diagonal coefficients are set to 0.
Examples
A victory:
>>> profile = Profile(preferences_ut=[[1, 0], [1, 0]]) >>> profile.matrix_victories_ut_abs array([[0., 1.], [0., 0.]])
A half-victory, but the other candidate has lost:
>>> profile = Profile(preferences_ut=[[1, 0], [42, 42]]) >>> profile.matrix_victories_ut_abs array([[0. , 0.5], [0. , 0. ]])
A half-victory for each candidate:
>>> profile = Profile(preferences_ut=[[1, 0], [0, 1]]) >>> profile.matrix_victories_ut_abs array([[0. , 0.5], [0.5, 0. ]])
A defeat for each candidate:
>>> profile = Profile(preferences_ut=[[0, 0], [0, 0]]) >>> profile.matrix_victories_ut_abs array([[0., 0.], [0., 0.]])
- property matrix_victories_ut_abs_ctb#
2d array of values in {0, 1}. Matrix of absolute victories based on
matrix_duels_ut
, with tie-breaks on candidates.matrix_victories_ut_abs_ctb[c, d]
is:1 iff
matrix_duels_ut[c, d] > V / 2
, ormatrix_duels_ut[c, d] = V / 2
andc < d
.0 iff
matrix_duels_ut[c, d] < V / 2
, ormatrix_duels_ut[c, d] = V / 2
andd < c
.
By convention, diagonal coefficients are set to 0.
Examples
A victory (without tie-breaking):
>>> profile = Profile(preferences_ut=[[1, 0], [1, 0]]) >>> profile.matrix_victories_ut_abs_ctb array([[0., 1.], [0., 0.]])
A victory with tie-breaking:
>>> profile = Profile(preferences_ut=[[1, 0], [0, 1]]) >>> profile.matrix_victories_ut_abs_ctb array([[0., 1.], [0., 0.]])
Another case of victory with tie-breaking:
>>> profile = Profile(preferences_ut=[[1, 0], [42, 42]]) >>> profile.matrix_victories_ut_abs_ctb array([[0., 1.], [0., 0.]])
A defeat for each candidate:
>>> profile = Profile(preferences_ut=[[0, 0], [0, 0]]) >>> profile.matrix_victories_ut_abs_ctb array([[0., 0.], [0., 0.]])
- property matrix_victories_ut_rel#
2d array of values in {0, 0.5, 1}. Matrix of relative victories based on
matrix_duels_ut
.matrix_victories_ut_rel[c, d]
is:1 iff
matrix_duels_ut[c, d] > matrix_duels_ut[d, c]
.0.5 iff
matrix_duels_ut[c, d] = matrix_duels_ut[d, c]
.0 iff
matrix_duels_ut[c, d] < matrix_duels_ut[d, c]
.
By convention, diagonal coefficients are set to 0.
Examples
A relative victory (which is not an absolute victory):
>>> profile = Profile(preferences_ut=[[1, 0], [0, 0], [0, 0]]) >>> profile.matrix_victories_ut_rel array([[0., 1.], [0., 0.]])
A tie:
>>> profile = Profile(preferences_ut=[[1, 0], [0, 1], [0, 0]]) >>> profile.matrix_victories_ut_rel array([[0. , 0.5], [0.5, 0. ]])
- property matrix_victories_ut_rel_ctb#
2d array of values in {0, 1}. Matrix of relative victories based on
matrix_duels_ut
, with tie-breaks on candidates.matrix_victories_ut_rel_ctb[c, d]
is:1 iff
matrix_duels_ut[c, d] > matrix_duels_ut[d, c]
, ormatrix_duels_ut[c, d] = matrix_duels_ut[d, c]
andc < d
.0 iff
matrix_duels_ut[c, d] < matrix_duels_ut[d, c]
, ormatrix_duels_ut[c, d] = matrix_duels_ut[d, c]
andd < c
.
By convention, diagonal coefficients are set to 0.
Examples
A relative victory (without tie-breaking):
>>> profile = Profile(preferences_ut=[[1, 0], [0, 0], [0, 0]]) >>> profile.matrix_victories_ut_rel_ctb array([[0., 1.], [0., 0.]])
A relative victory with tie-breaking:
>>> profile = Profile(preferences_ut=[[1, 0], [0, 1], [0, 0]]) >>> profile.matrix_victories_ut_rel_ctb array([[0., 1.], [0., 0.]])
- property preferences_borda_rk#
2d array of integers.
preferences_borda_rk[v, c]
gains 1 point for each candidated
such that voterv
ranksc
befored
. So, these Borda scores are between0
andC - 1
.
- property preferences_borda_ut#
2d array of floats.
preferences_borda_ut[v, c]
gains 1 point for eachd
such thatv
strictly prefersc
tod
(in the sense of utilities), and 0.5 point for eachd
such thatv
is indifferent betweenc
andd
. So, these Borda scores are between0
andC - 1
.
- property preferences_rk#
2d array of integers.
preferences_rk[v, k]
is the candidate at rankk
for voterv
. For example,preferences_rk[v, 0]
isv
’s preferred candidate.
- property preferences_ut#
2d array of floats.
preferences_ut[v, c]
is the utility of candidatec
as seen by voterv
.
- property total_utility_c#
1d array of numbers.
total_utility_c[c]
is the total utility for candidatec
(i.e. the sum ofc
’s column in matrixpreferences_ut
).Examples
>>> from svvamp import Profile >>> profile = Profile(preferences_ut=[[5, 1, 2], [4, 10, 1]]) >>> profile.total_utility_c array([ 9, 11, 3])