Positional scoring rules¶
General class¶
-
class
embedded_voting.
RulePositional
(points, rule=None)[source]¶ This class enables to extend a voting rule to an ordinal input with a positional scoring rule.
Parameters: - points (list) – The vector of the positional scoring rule. Should be of the same length than the number of candidates. In each ranking, candidate ranked at position i get points[i] points.
- rule (Rule) – The aggregation rule used to determine the aggregated scores of the candidates.
-
fake_ratings_
¶ The modified ratings of voters (with ordinal scores) on which we run the election.
Type: ratings
-
points
¶ The vector of the positional scoring rule. Should be of the same length than the number of candidates. In each ranking, candidate ranked at position i get points[i] points.
Type: np.ndarray
-
base_rule
¶ The aggregation rule used to determine the aggregated scores of the candidates.
Type: Rule
-
_score_components
¶ The number of components in the score of every candidate. If > 1, we perform a lexical sort to obtain the ranking.
Examples
>>> ratings = np.array([[.1, .2, .8, 1], [.7, .9, .8, .6], [1, .6, .1, .3]]) >>> embeddings = Embeddings([[1, 0], [1, 1], [0, 1]], norm=True) >>> election = RuleSVDNash()(ratings, embeddings) >>> election.ranking_ [3, 0, 1, 2] >>> election_bis = RulePositional([2, 1, 1, 0])(ratings, embeddings) >>> election_bis.fake_ratings_ Ratings([[0. , 0.5, 0.5, 1. ], [0.5, 1. , 0.5, 0. ], [1. , 0.5, 0. , 0.5]]) >>> election_bis.set_rule(RuleSVDNash())(ratings, embeddings).ranking_ [1, 3, 0, 2]
-
plot_fake_ratings
(plot_kind='3D', dim=None, list_candidates=None, list_titles=None, row_size=5, show=True)[source]¶ This function plot the candidates in the fake ratings, obtained using the scoring vector
points
.Parameters: - plot_kind (str) – The kind of plot we want to show.
Can be
'3D'
or'ternary'
. - dim (list) – The 3 dimensions we are using for our plot.
By default, it is set to
[0, 1, 2]
. - list_candidates (int list) – The list of candidates we want to plot.
Should contains integers lower than
n_candidates
. By default, we plot all candidates. - list_titles (str list) – Contains the title of the plots. Should be the same length than list_candidates.
- row_size (int) – Number of subplots by row. By default, it is set to 5 plots by rows.
- show (bool) – If True, displays the figure at the end of the function.
- plot_kind (str) – The kind of plot we want to show.
Can be
-
set_rule
(rule)[source]¶ This function updates the
base_rule
used for the election.Parameters: rule (Rule) – The new rule to use. Returns: The object itself. Return type: RulePositional
Particular cases¶
-
class
embedded_voting.
RulePositionalPlurality
(n_candidates, rule=None)[source]¶ This class enables to extend a voting rule to an ordinal input with Plurality rule (vector
[1, 0, ..., 0]
).Parameters: rule (Rule) – The aggregation rule used to determine the aggregated scores of the candidates. Examples
>>> ratings = np.array([[.1, .2, .8, 1], [.7, .9, .8, .6], [1, .6, .1, .3]]) >>> embeddings = Embeddings(np.array([[1, 0], [1, 1], [0, 1]]), norm=True) >>> election = RulePositionalPlurality(4, rule=RuleSVDNash(use_rank=True))(ratings, embeddings) >>> election.fake_ratings_ Ratings([[0., 0., 0., 1.], [0., 1., 0., 0.], [1., 0., 0., 0.]]) >>> election.ranking_ [0, 1, 3, 2]
-
class
embedded_voting.
RulePositionalVeto
(n_candidates, rule=None)[source]¶ This class enables to extend a voting rule to an ordinal input with Veto rule (vector
[1, ..., 1, 0]
).Parameters: rule (Rule) – The aggregation rule used to determine the aggregated scores of the candidates. Examples
>>> ratings = np.array([[.1, .2, .8, 1], [.7, .9, .8, .6], [1, .6, .1, .3]]) >>> embeddings = Embeddings(np.array([[1, 0], [1, 1], [0, 1]]), norm=True) >>> election = RulePositionalVeto(n_candidates=4, rule=RuleSVDNash())(ratings, embeddings) >>> election.fake_ratings_ Ratings([[0., 1., 1., 1.], [1., 1., 1., 0.], [1., 1., 0., 1.]]) >>> election.ranking_ [1, 3, 0, 2]
-
class
embedded_voting.
RulePositionalKApproval
(n_candidates, k=2, rule=None)[source]¶ This class enables to extend a voting rule to an ordinal input with k-Approval rule (vector
[1, 1, ..., 0]
with k ones).Parameters: - k (int) – The k parameter of the k-approval. By default, it is set to 2.
- rule (Rule) – The aggregation rule used to determine the aggregated scores of the candidates.
Examples
>>> ratings = np.array([[.1, .2, .8, 1], [.7, .9, .8, .6], [1, .6, .1, .3]]) >>> embeddings = Embeddings(np.array([[1, 0], [1, 1], [0, 1]]), norm=True) >>> election = RulePositionalKApproval(n_candidates=4, k=2, rule=RuleSVDNash(use_rank=True))( ... ratings, embeddings) >>> election.fake_ratings_ Ratings([[0., 0., 1., 1.], [0., 1., 1., 0.], [1., 1., 0., 0.]]) >>> election.ranking_ [1, 2, 0, 3]
-
class
embedded_voting.
RulePositionalBorda
(n_candidates, rule=None)[source]¶ This class enables to extend a voting rule to an ordinal input with Borda rule (vector
[m-1, m-2, ..., 1, 0]
).Parameters: rule (Rule) – The aggregation rule used to determine the aggregated scores of the candidates. Examples
>>> ratings = np.array([[.1, .2, .8, 1], [.7, .9, .8, .6], [1, .6, .1, .3]]) >>> embeddings = Embeddings(np.array([[1, 0], [1, 1], [0, 1]]), norm=True) >>> election = RulePositionalBorda(n_candidates=4, rule=RuleSVDNash())(ratings, embeddings) >>> election.fake_ratings_ Ratings([[0. , 0.33333333, 0.66666667, 1. ], [0.33333333, 1. , 0.66666667, 0. ], [1. , 0.66666667, 0. , 0.33333333]]) >>> election.ranking_ [1, 3, 2, 0]