# Kotze-Pereira transformation

The Kotze-Pereira transformation (KP transform) converts scored ballots into Approval ballots, which allows any Approval PR method to be run on scored ballots. Because the score winner will always have the most approvals after the transformation, a PR method that elects the approval winner in the single-winner case will also elect the score winner in the single-winner case when converted to a score method using the transformation. Score methods using this transformation are also generally satisfy Scale invariance (multiplying all score by a constant leaves the result unaffected), except when the change in score causes differences in surplus handling due to quotas being met or not met. The transformation was independently invented by Kotze in 2011 and Toby Pereira in 2015. It was named by Forest Simmons in 2015.

## Explanation

A voter whose scores are (with the max score being 10) A=10 B=6 C=4, would have their 1 ballot transformed into 0.4 ABC, 0.2 AB, and 0.4 A Approval ballots. This is because the lowest score they gave to any candidate is a 4 out of 10, which is 40% support, so a corresponding 40% portion of their ballot is treated as approving all candidates scored a 4/10 or higher (Candidates A, B, and C); the next-lowest score they gave was a 6/10, 60% support, but because 40% of the ballot was already converted into Approval ballots, only the remaining 60% - 40% = 20% portion is converted, and all candidates scored a 6 out of 10 or higher (Candidates A and B) are treated as approved in this 20% portion; finally, within the remaining 40% portion of the ballot, the next-lowest score the voter gave is a 10/10, so all candidates scored a 10 or higher (Candidate A) are considered approved on this portion of the ballot.

To avoid having fractional approval ballots, some suggest that the KP transform should be done in such a way that one voter's score ballot always produces the smallest number of approval ballots such that they all are integer amounts; with the above example, this would mean multiplying the number of Approval ballots in each set by 5, yielding 2 ABC, 1 AB, and 2 A Approval ballots.

## The formal definition

Replace any ballot which rates the C candidates with scores S1≥S2≥S3≥...≥SC by these C weighted approval (meaning with {0,1}-scores only) ballots

```(1,1,1,...,1,1)	   with weight    SC
(1,1,1,...,1,0)	   with weight    SC-1-SC
...
(1,1,0,...,0,0)	   with weight    S2-S3
(1,0,0,...,0,0)	   with weight    S1-S2```

Note: the candidates were ordered by decreasing scores on the ballot under consideration. That assures that all the weights come out positive. For example, the score ballot (9,5,3) in a three-candidate election would be replaced by 3×(1,1,1) + 2×(1,1,0) + 4×(1,0,0).

A "ballot with weight w" is to be interpreted the same as "w voters cast that ballot." This transform converts scores into approvals so that any method that uses approval ballots can be converted to a method that uses score ballots without having to individually define how to do so for each method.

Note that the Approval ballots yielded by the KP transform can be converted into ranked ballots by considering all approved candidates on a ballot as ranked co-1st, and all disapproved candidates as ranked co-equal last. With the above example of 0.4 ABC, 0.2 AB, and 0.4 A Approval ballots, this would converted into 0.4 A=B=C, 0.2 A=B(>C), and 0.4 A(>B=C) ranked ballots. This allows ranked PR methods to be done on rated ballots.

## Whole Ballot formulation

In the whole ballot formulation there is never any fractional approval ballots. All score ballots are turned into the same number of whole approval ballots. The number of ballots is the same as the maximum score.

### Example Ballot

An illustrative ballot for a max score 5 system is. A:1 B:3 C:4 D:0

The KP-Transform turns this into 5 approval ballots.

Ballot A B C D
1 1 1 1 0
2 0 1 1 0
3 0 1 1 0
4 0 0 1 0
5 0 0 0 0

### Python Implementation

The whole ballot formulation is particularly simple computationally. Given a Pandas dataframe S with columns representing candidates and rows representing voters the entries would encode the score of all the ballots. For a max score of K and an output set of approval ballots A.

```import pandas as pd
import numpy as np

groups = []
for threshold in range(K):
groups.append(np.where(S.values > threshold, 1, 0))

A = pd.DataFrame(np.concatenate(groups), columns=S.columns)
```

## Scale Invariance example for RRV

Reweighted Range Voting is one example of a method where the Kotze-Pereira Transformation will provide Scale invariance. This example will use Jefferson RRV because it's marginally easier to work with, but it's basically the same with any divisors.

Let's say we have 5 candidates to elect and there are multiple A and B candidates, and we have the following approval ballots.

200 voters: A

100 voters: B

In this case A would win 3, B would win 1 out of the first 4, and there would be a tie for the final seat. After the initial 4 have been elected, the weighted approvals for A would be 200/4 = 50, and for B it would be 100/2 = 50. So a tie. But now let's move onto score voting (out of 10)

200 voters: A1=10, A2=10, A3=9, A4=9

100 voters: B1=10, B2=9

A1, A2, and B1 would be elected as the first three. This gives us the proportional 2:1 ratio and this is the same as approval currently (because they had max scores). The A votes are now worth 1/3, and the B votes worth 1/2. A3 would be the next elected. But because of the score of 9, there isn't a full deweighting. Each A vote would now be worth 1/(1 + 29/10) = 10/39 or about 0.256. Both A4 and B2 have been given a score of 9 by their voters. The total score for A4 is 200 x 0.9 x 10/39 = 46.15. For B2 it is 100 x 0.9 x 0.5 = 45. So A4 would be elected instead of there being a tie. OK, so it's only a tie being broken, but if there were 101 B voters, then B2 should win the final seat but 101 x 0.9 x 0.5 = 45.45, so it wouldn't be enough to take the final seat. The wrong candidate would win the final seat.

With KP, the initial ballots would be transformed to:

200 ballots: A1, A2

1800 ballots: A1, A2, A3, A4

100 ballots: B1

900 ballots: B1, B2

Imagine A1, A2, B1, A3 are already elected. The new weighted total approvals for A4 would be 1800 x 1/4 = 450. For B2 it would be 900 x 1/2 = 450. This is the exact tie we want. So Scale invariance is preserved.