This is a library of functions for running many simulations of different elections (Impartial Culture, spatial model, ...) held using different voting methods (Borda count, Approval voting, ...).
Goals:
- Fast (~25,000 elections per second)
- Flexible
- Well-documented, easily-used and improved upon by other people
- Well-tested and bug-free
- Able to reproduce peer-reviewed research
Current dependencies are numpy and scipy.
Optionally, elsim can use numba for speed. If not available, the code will still run, just more slowly.
One possibility is to install with pip:
pip install git+https://github.com/endolith/elsim.git
Currently just the docstrings of the submodules and functions themselves, in numpydoc format.
Specify an election with three candidates (0, 1, 2), where two voters rank candidates 0 > 2 > 1, two voters rank candidates 1 > 2 > 0, and one ranks candidates 2 > 0 > 1:
>>> election = [[0, 2, 1],
[0, 2, 1],
[1, 2, 0],
[1, 2, 0],
[2, 0, 1]]Calculate the winner using Black's method:
>>> from elsim.methods import black
>>> black(election)
2Candidate 2 is the Condorcet winner, and wins under Black's method.
See /examples folder for more on what it can do.
Tests can be run by installing pytest, hypothesis, and then running pytest in the project folder.
File issues on the Github issue tracker.
- 1D:
- http://zesty.ca/voting/voteline/ (Flash, 5 candidates, normal/uniform/bimodal distribution)
- https://demonstrations.wolfram.com/ComparingVotingSystemsForANormalDistributionOfVoters/
- 2D:
- ND: