Generate Weighted Majority Graphs

Generate Linearly Edge-Ordered Tournaments

pref_voting.generate_weighted_majority_graphs.generate_edge_ordered_tournament(num_cands, parity='even')[source]

Generate a random uniquely weighted MarginGraph for num_cands candidates.

Parameters:

num_cands (int) – the number of candidates

Returns:

a uniquely weighted margin graph

Return type:

MarginGraph

Note

This function randomly generates a tournament with a linear order over the edges. A tournament is an asymmetric directed graph with an edge between every two nodes. The linear order of the edges is represented by assigning to each edge a number \(2, \ldots, 2*n\), where \(n\) is the number of the edges.

… For Large Numbers of Voters

pref_voting.generate_weighted_majority_graphs.generate_edge_ordered_tournament_infinite_limit(num_candidates, cov_matrix=None)[source]

Using the ideas from Section 9 of the paper An Analysis of Random Elections with Large Numbers of Voters by Matthew Harrison-Trainor (https://arxiv.org/abs/2009.02979) and the code provided at https://github.com/MatthewHT/RandomMarginGraphs/, generate a qualitative margin graph for num_candidates candidates.

Important

The weights of the generated margin graphs are real numbers, representing a linear ordering of the edges. Only qualitative margin graph invariant voting methods, such as Split Cycle, Beat Path, Minimax, Ranked Pairs, etc., should be used on the generated graphs.

Parameters:

num_candidates (int) – the number of candidates

Returns:

MarginGraph

Generate Margin Graphs

pref_voting.generate_weighted_majority_graphs.generate_margin_graph(num_cands, weight_domain=None, parity='even')[source]

Generate a random MarginGraph (allowing for ties in the margins) for num_cands candidates.

Parameters:

num_cands (int) – the number of candidates

Returns:

MarginGraph

pref_voting.generate_weighted_majority_graphs.generate_margin_graph_bradley_terry(num_cands, num_voters, score_prob_mod=<function <lambda>>)[source]

Generates a margin graph for num_cands candidates by first sampling candidate scores from score_prob_mod and then sampling votes from the Bradley-Terry model using the sampled scores.

Parameters:
  • num_cands (int) – Number of candidates

  • num_voters (int) – Number of voters

  • score_prob_mod (function, optional) – A function that takes a candidate and returns a score. Defaults to lambda c: np.random.uniform(0,1).

Returns:

A margin graph

Return type:

MarginGraph

Enumerate Canonical Objects

pref_voting.generate_weighted_majority_graphs.enumerate_canonical_edge_ordered_tournaments(num_cands, parity='even')[source]

A canonical edge-ordered tournament (ceot) is a representative from an isomorphism class of linearly edge-ordered tournaments. Enumerate all ceots for num_cands candidates, representing a ceot as a MarginGraph where the margins represent the linear order of the edges.

Parameters:
  • num_cands (int) – the number of candidates

  • parity (str, optional) – The parity of the margins, either ‘even’ or ‘odd’.

Returns:

A generator of MarginGraph for num_candidates

Warning

It is only feasible to run this function for up to 5 candidates.

pref_voting.generate_weighted_majority_graphs.enumerate_uniquely_weighted_margin_graphs(num_cands, weight_domain)[source]

Enumerate all representatives from isomorphism classes of margin graphs with weights drawn from weight_domain.

Parameters:
  • num_cands (int) – the number of candidates

  • weight_domain (List[int]) – The list of weights in the margin graph.

Returns:

A generator of MarginGraph for num_candidates

Warning

It is only feasible to run this function for up to 5 candidates.