General class

class embedded_voting.ManipulationCoalition(ratings, embeddings, rule=None)[source]

This general class is used for the analysis of the manipulability of the rule by a coalition of voter.

It only look if there is a trivial manipulation by a coalition of voter. That means, for some candidate c different than the current winner w, gather every voter who prefers c to w, and ask them to put c first and w last. If c is the new winner, then the ratings can be manipulated.

Parameters:
  • ratings (Ratings or np.ndarray) – The ratings of voters to candidates
  • embeddings (Embeddings) – The embeddings of the voters
  • rule (Rule) – The aggregation rule we want to analysis.
ratings

The ratings of voter on which we do the analysis.

Type:Profile
rule

The aggregation rule we want to analysis.

Type:Rule
winner_

The index of the winner of the election without manipulation.

Type:int
scores_

The scores of the candidates without manipulation.

Type:float list
welfare_

The welfare of the candidates without manipulation.

Type:float list

Examples

>>> np.random.seed(42)
>>> ratings_dim_candidate = [[1, .2, 0], [.5, .6, .9], [.1, .8, .3]]
>>> embeddings = EmbeddingsGeneratorPolarized(10, 3)(.8)
>>> ratings = RatingsFromEmbeddingsCorrelated(coherence=.8, ratings_dim_candidate=ratings_dim_candidate)(embeddings)
>>> manipulation = ManipulationCoalition(ratings, embeddings, RuleSVDNash())
>>> manipulation.winner_
1
>>> manipulation.welfare_
[0.6651173304239..., 1.0, 0.0]
is_manipulable_

A function that quickly computes if the ratings is manipulable.

Returns:If True, the ratings is manipulable for some candidate.
Return type:bool

Examples

>>> np.random.seed(42)
>>> ratings_dim_candidate = [[1, .2, 0], [.5, .6, .9], [.1, .8, .3]]
>>> embeddings = EmbeddingsGeneratorPolarized(10, 3)(.8)
>>> ratings = RatingsFromEmbeddingsCorrelated(coherence=.8, ratings_dim_candidate=ratings_dim_candidate)(embeddings)
>>> manipulation = ManipulationCoalition(ratings, embeddings, RuleSVDNash())
>>> manipulation.is_manipulable_
True
manipulation_map(map_size=20, ratings_dim_candidate=None, show=True)[source]

A function to plot the manipulability of the ratings when the polarisation and the coherence vary.

Parameters:
  • map_size (int) – The number of different coherence and polarisation parameters tested. The total number of test is map_size ^2.
  • ratings_dim_candidate (np.ndarray) – Matrix of shape n_dim, n_candidates containing the scores given by each group. More precisely, ratings_dim_candidate[i,j] is the score given by the group represented by the dimension i to the candidate j. If not specified, a new matrix is generated for each test.
  • show (bool) – If True, displays the manipulation maps at the end of the function.
Returns:

The manipulation maps : manipulator for the proportion of manipulator, worst_welfare and avg_welfare for the welfare maps.

Return type:

dict

Examples

>>> np.random.seed(42)
>>> emb = EmbeddingsGeneratorPolarized(100, 3)(0)
>>> rat = RatingsFromEmbeddingsCorrelated(n_dim=3, n_candidates=5)(emb)
>>> manipulation = ManipulationCoalition(rat, emb, RuleSVDNash())
>>> maps = manipulation.manipulation_map(map_size=5, show=False)
>>> maps['worst_welfare']
array([[0.91880682, 1.        , 1.        , 1.        , 0.93714861],
       [0.9354928 , 0.75627811, 1.        , 1.        , 1.        ],
       [0.6484071 , 1.        , 1.        , 1.        , 1.        ],
       [0.68626628, 0.9024018 , 1.        , 1.        , 1.        ],
       [0.91491621, 0.9265847 , 1.        , 1.        , 1.        ]])
trivial_manipulation(candidate, verbose=False)[source]

This function computes if a trivial manipulation is possible for the candidate passed as parameter.

Parameters:
  • candidate (int) – The index of the candidate for which we manipulate.
  • verbose (bool) – Verbose mode. By default, is set to False.
Returns:

If True, the ratings is manipulable for this candidate.

Return type:

bool

Examples

>>> np.random.seed(42)
>>> ratings_dim_candidate = [[1, .2, 0], [.5, .6, .9], [.1, .8, .3]]
>>> embeddings = EmbeddingsGeneratorPolarized(10, 3)(.8)
>>> ratings = RatingsFromEmbeddingsCorrelated(coherence=.8, ratings_dim_candidate=ratings_dim_candidate)(embeddings)
>>> manipulation = ManipulationCoalition(ratings, embeddings, RuleSVDNash())
>>> manipulation.trivial_manipulation(0, verbose=True)
1 voters interested to elect 0 instead of 1
Winner is 0
True
worst_welfare_

A function that compute the worst welfare attainable by coalition manipulation.

Returns:The worst welfare.
Return type:float

Examples

>>> np.random.seed(42)
>>> ratings_dim_candidate = [[1, .2, 0], [.5, .6, .9], [.1, .8, .3]]
>>> embeddings = EmbeddingsGeneratorPolarized(10, 3)(.8)
>>> ratings = RatingsFromEmbeddingsCorrelated(coherence=.8, ratings_dim_candidate=ratings_dim_candidate)(embeddings)
>>> manipulation = ManipulationCoalition(ratings, embeddings, RuleSVDNash())
>>> manipulation.worst_welfare_
0.6651173304239...