General class

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

This general class is used for the analysis of the manipulability of some Rule by a single voter.

For instance, what proportion of voters can change the result of the rule (to their advantage) by giving false preferences ?

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 voters 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 welfares 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 = Manipulation(ratings, embeddings, RuleSVDNash())
>>> manipulation.winner_
1
>>> manipulation.welfare_
[0.6651173304239..., 1.0, 0.0]
avg_welfare_

The function computes the average welfare of the winning candidate after a voter manipulation.

Returns:The average 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 = Manipulation(ratings, embeddings, RuleSVDNash())
>>> manipulation.avg_welfare_
0.933...
is_manipulable_

This function quickly computes if the ratings is manipulable or not.

Returns:If True, the ratings is manipulable by a single voter.
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 = Manipulation(ratings, embeddings, RuleSVDNash())
>>> manipulation.is_manipulable_
True
manipulation_global_

This function applies the function manipulation_voter() to every voter.

Returns:The list of the best candidates that can be turned into the winner for each voter.
Return type:int 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 = Manipulation(ratings, embeddings, RuleSVDNash())
>>> manipulation.manipulation_global_
[1, 1, 0, 1, 1, 1, 1, 1, 0, 1]
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 of the ParametricProfile vary. The number of voters, dimensions, and candidates are those of the profile_.

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 None specified, a new matrix is generated for each test.
  • show (bool) – If True, display 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 = Manipulation(rat, emb, rule=RuleSVDNash())
>>> maps = manipulation.manipulation_map(map_size=5, show=False)
>>> maps['manipulator']
array([[0.33, 0.  , 0.  , 0.  , 0.  ],
       [0.34, 0.22, 0.  , 0.  , 0.  ],
       [0.01, 0.  , 0.  , 0.  , 0.  ],
       [0.  , 0.19, 0.  , 0.  , 0.  ],
       [0.57, 0.22, 0.  , 0.  , 0.  ]])
manipulation_voter(i)[source]

This function return, for the i^th voter, its favorite candidate that he can turn to a winner by manipulating the election.

Parameters:i (int) – The index of the voter.
Returns:The index of the best candidate that can be elected by manipulation.
Return type:int
prop_manipulator_

This function computes the proportion of voters that can manipulate the election.

Returns:The proportion of voters that can manipulate the election.
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 = Manipulation(ratings, embeddings, RuleSVDNash())
>>> manipulation.prop_manipulator_
0.2
set_profile(ratings, embeddings=None)[source]

This function update the ratings of voters on which we do the analysis.

Parameters:
Returns:

The object itself.

Return type:

Manipulation

worst_welfare_

This function computes the worst possible welfare achievable by single voter 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 = Manipulation(ratings, embeddings, RuleSVDNash())
>>> manipulation.worst_welfare_
0.665...