Tutorial 10: Experiment replication¶
In order to resolve ties, an allocator could use a random generator to break it. In this tutorial we will learn how we can replicate some computation.
Let’s create a one-seat constituency where the winner is chosen by first-past-the-post and all the candidates received the same amount of vote:
1name: Spider-Man Pointing
2method: first_past_the_post
3candidates:
4- name: Spiderman 1
5 vote: 2000
6- name: Spiderman 2
7 vote: 2000
8- name: Spiderman 3
9 vote: 2000
If we compute the result, all of candidates can be chosen with the same probability:
$ interregnum-cli calc spiderman-pointing.yaml spiderman-pointing-result.yaml
Let’s examine the result:
1# spiderman-pointing-result.yaml
2
3type: district
4name: Spider-Man Pointing
5method: first_past_the_post
6initial_seats: min_seats
7resume_allocation: false
8candidates:
9- name: Spiderman 1
10 groups: []
11- name: Spiderman 2
12 groups: []
13- name: Spiderman 3
14 groups: []
15result:
16 allocation:
17 - name:
18 name: Spiderman 2
19 alliance: Spiderman 2
20 votes: 0
21 seats: 1
22 data:
23 log:
24 - EVENT: tie
25 candidates:
26 - name: Spiderman 1
27 alliance: Spiderman 1
28 - name: Spiderman 2
29 alliance: Spiderman 2
30 - name: Spiderman 3
31 alliance: Spiderman 3
32 condition:
33 best_score: 0
34 - EVENT: winner
35 target:
36 name: Spiderman 1
37 alliance: Spiderman 1
38 criterion: tie_break_random
39 quota: 0
40 threshold: 0
41 remaining_seats: 0
42 rounds: 1
43 deterministic: false
44 random_state:
45 deterministic: false
46 uses: 1
47 seed: 1839732977
48 original_state: null
In this case the winner is Spiderman 2, but the result was non-deterministic.
If we look at the event log, we can see that there is a tie between the 3 Spidermen, and then a winner was chosen randomly.
23log:
24- EVENT: tie
25 candidates:
26 - name: Spiderman 1
27 alliance: Spiderman 1
28 - name: Spiderman 2
29 alliance: Spiderman 2
30 - name: Spiderman 3
31 alliance: Spiderman 3
32 condition:
33 best_score: 0
34- EVENT: winner
35 target:
36 name: Spiderman 1
37 alliance: Spiderman 1
38 criterion: tie_break_random
39 quota: 0
40threshold: 0
41remaining_seats: 0
42rounds: 1
If we want to reproduce this result, we can use the seed provided in the section random_state:
44random_state:
45 deterministic: false
46 uses: 1
47 seed: 1839732977
48 original_state: null
Now let’s add that random generator seed to our initial schema:
1name: Spider-Man Pointing
2method: first_past_the_post
3random_seed: 1839732977
4candidates:
5- name: Spiderman 1
6 vote: 2000
7- name: Spiderman 2
8 vote: 2000
9- name: Spiderman 3
10 vote: 2000
Now, the result should be the same every time it is computed. Be aware that the implementation of this feature can vary depending of the allocator, so you should consult the API documentation in each case.