Skip to content

This repo implements the Schulze method, a Condorcet-type election method.

License

Notifications You must be signed in to change notification settings

geomstats/condorcet-method

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

condorcet-method

This repo implements the Schulze method, a Condorcet-type election method. Please refer to Wikipedia for all the mathematical details.

How to run the method

1. Prepare your data

The first step is to import your data in a dataframe. The structure has to be the following:

  • Each voter has to correspond to a line
  • Each row contains, ordered from the left to the right columns, the preferences of the voter
  • Each entry corresponds to the name of teh candidates: make sure not to make spelling mistakes

To see a concrete example, have a look at Run_ranking.ipynb.

2. Run the election method to discover the winning candidates

To run the model once the dataframe df is ready, it is just one line:

condorcet.compute_ranks(df) 

As in the example in the notebook, the output is a list of lists, where the position of the inner list corresponds to the ranking and if the inner lists are longer than one element, it is because there is a tie.

3. Dive deeper

You can extract the d[V,W] and p[V,W] matrices with the methods:

  • condorcet._compute_d(weighted_ranks, candidate_names)
  • condorcet._compute_p(dmat, candidate_names)

To extract the candidate names and the weighted ranks to be input to the above methods, please use:

  • weighted_ranks = condorcet.weighted_ranks_from_df(df)
  • candidate_names = condorcet.candidate_names_from_df(df)

Code tests

The Wikipedia example is reproduced in the example notebook and all the entries of the p and d matrices match the original ones.

A short unit test can be run with the command pytest once in the repo root folder. To run the test, pytest is required. You can install it with pip install pytest.

About

This repo implements the Schulze method, a Condorcet-type election method.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 84.7%
  • Python 15.3%