Features Rule¶
-
class
embedded_voting.
RuleFeatures
(score_components=1, embeddings_from_ratings=None)[source]¶ Voting rule in which the aggregated score of a candidate is the norm of the feature vector of this candidate.
Intuitively, for each candidate, her feature on embedding dimension d is the ideal rating that a voter of group d should put to that candidate. In this model, the actual rating of a voter for this candidate would be a mean of the features, weighted by the voter’s embedding: embeddings[voter, :] @ features[candidate, :]. Considering all the voters and all the candidates, we then obtain ratings = embeddings @ features.T, i.e. features = (inv(embeddings) @ ratings).T.
Since embeddings is not always invertible, we consider in practice features = (pinv(embeddings) @ ratings).T. This can be seen as a least-square approximation of the inital model.
Finally, the score of a candidate is the Euclidean norm of her vector of features.
Examples
>>> ratings = Ratings(np.array([[.5, .6, .3], [.7, 0, .2], [.2, 1, .8]])) >>> embeddings = Embeddings(np.array([[1, 1], [1, 0], [0, 1]]), norm=True) >>> election = RuleFeatures()(ratings, embeddings) >>> election.scores_ [0.669..., 0.962..., 0.658...] >>> election.ranking_ [1, 0, 2] >>> election.winner_ 1 >>> election.welfare_ [0.0353..., 1.0, 0.0]
-
features_
¶ This function return the feature vector of all candidates.
Returns: The matrix of features. Its shape is n_candidates
,n_dim
.Return type: np.ndarray
-
plot_features
(plot_kind='3D', dim: list = None, row_size=5, show=True)[source]¶ This function plot the features vector of all candidates in the given dimensions.
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]
. - row_size (int) – The number of subplots by row. By default, it is set to 5 plots by row.
- show (bool) – If True, plot the figure at the end of the function.
- plot_kind (str) – The kind of plot we want to show.
Can be
-