Voting-Systems-Simulation

Simulation for various voting systems

Check out on GitHub

Voting-Systems-Simulation

Lire en Français

Documentation:


Summary

What it is

This repository contains a script that performs simulations of various voting methods on randomly generated data.

The opinions on the topic of your choice are represented as points in a finite dimensional vector space. This means elector and candidate positions are represented as coordinates in a vector space that can be a plane, a three dimensional space, or more.

Here is an image of what it looks like

Elector and candidate positions illustration

The goals of the simulation are to see if there is any differences between the numerous voting methods, and if those differences exists, determine which ones better.

If you are just interested in the results and feel trustful, you can read the Related work section and then skip to Interpretation of the results section.

You might also be interested by this revue which compares many voting methods, explains how they work and their flaws.

Voting-Systems-Comparison

This simulation is inspired by various videos

How to run

If you want to run the simulation, you can do as following

git clone https://github.com/Relex12/Voting-Systems-Simulation.git
cd Voting-Systems-Simulation
python3 simulation.py

This will give something similar into the output

plurality:               6
two round:               9
instant runoff:          9
condorcet:               3
borda:                   3
approval:                3
majority judgement:      3

and produce an image as img/positions.png of the position of the electors and the candidates.

CLI arguments

You can print the help message by running: python3 simulation.py -h

usage: simulation.py [-h] [-v] [-d DIMENSION] [-e ELECTORS] [-c CANDIDATES]
                     [-t THRESHOLD] [--noplot] [-r REPEAT] [-o OUTPUT]
                     [--test TEST]

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -d DIMENSION, --dimension DIMENSION
                        number of dimensions to use
  -e ELECTORS, --electors ELECTORS
                        number of electors for the simulation
  -c CANDIDATES, --candidates CANDIDATES
                        number of candidates for the simulation
  -t THRESHOLD, --threshold THRESHOLD
                        rejection threshold for scoring methods
  --noplot              creates the positions image
  -r REPEAT, --repeat REPEAT
                        number of repetitions of the simulation
  -o OUTPUT, --output OUTPUT
                        output file to write the results
  --test TEST           number of times to test the method given in the test()
                        function

Introduction to the code

The code is divided in two modules

Documentation

The documentation of simulation.py and voting.py modules is made with pdoc3. It is available in the doc/ folder on the repo. You can check it out online:

To generate the documentation, run pdoc --html -o doc/ *.py . You can also view the documentation in your browser at localhost:8080 by running pdoc --http : *.py.

Undecidability rate

Sometimes, some methods are just not able to pick a winner, because of the Condorcet paradox or because of an equality case. When this occurs, a None object is returned by the corresponding function. To estimate this rate, the methods have been tested 100000 (one hundred thousand) times each, using the --test command line argument, with the default values of 2 dimensions, 50 electors and 10 candidates. Here are the results

Method Estimated rate (%)
Plurality 0.0
Two rounds 0.0
Instant Runoff 0.0
Condorcet 2.11
Borda 0.002
Approval 11.235
Majority jugement 2.01

Notes:

Flaws in the modeling

Before reading the interpretation of the results, there might be a few flaws in the simulation you have to be aware of. Considering these flaws doesn’t mean the simulation is bad, it simply means that in a real world problem, such an approach could only be used by an omniscient entity, or is likely to produce significant deviations from the observed results.

Note: For some of these flaws , you might want to consider that the variables that are used in the simulation are given by a logistic regression performed on the real variables used to evaluate everyone’s position. That means that you will have to evaluate positions on more variables, which is incompatible with the omniscient position evaluation flaw. Moreover, a logistic regression will induce at least slight a small approximation, that might highlight the dimensional representation flaw.

Interpretation of the results

For better understanding of the results, you can run the simulation several times and try to understanding what is going on between the method results and the generated position set.

The first thing we can observe is that the results are pretty different from one method to another. We can see that some methods often give similar results, that looks like a correlation, but it does not correspond every time. A statistical analysis is needed to establish stronger correlations. We can find out that some of these methods give a winner near the average position of electors, while other methods favor candidates without too many competitors in their area.

If there is only one question to remember it is this one:

Would you prefer to choose as winner a candidate against whom no one is really against or a candidate who has more supporters than opponents compared to his competitors?

Personal interpretation: In this and the next paragraph, and only in these, I give my opinion about how I interpret the results: I think that methods that promote candidates isolated from others are not the best, because the results depend more on the position of the other candidates than on those of the electors. However, it is the position of the electorate that the vote is supposed to reflect. In this way, the best voting methods are, in my opinion, those that allow electors to judge the candidates independently.

In systems that favor isolated candidates, candidates who might better reflect electors’ positions must struggle against each other, and it is this competition that allows isolated candidates to win.

Remaining work

To improve the simulation, the first thing to be done is to add other voting methods. Only seven of them have been implemented here, many others exist, and many variant of these method are also possible, giving sometimes different results.

Once we have more voting methods implemented, it would be great to make a statistical correlation study between the methods. The idea would be to run the simulation many times and store the results in a file, and then to estimate for each pair of methods the agreement rate, that is the frequency with which the methods give the same result.

Finally, to complete this analysis, variables like distribution indicators (median, average and standard deviation, for electors and candidates) and density indicators (for electors and candidates) must be also be used to find correlations and to be able to make a rigorous conclusion on the subject of voting methods.

License

The project is a small one. The code is given to the GitHub Community for free, only under the MIT License, that is not too restrictive.