CulturePerturbed#

class actinvoting.CulturePerturbed(m, theta, seed=None)[source]#

Perturbed Culture.

The pole (a.k.a. reference ranking) is ranking = [0, 1, 2, 3, …], i.e. borda = [m-1, m-2, …].

Parameters:
  • m (int) – Number of candidates.

  • theta (sympy.Rational) – Concentration parameter, giving the additional probability of the pole. For theta = 1, the culture is a Dirac. For theta = 0, it is the Impartial Culture.

  • seed (int) – Random seed.

Examples

Usual case:

>>> culture = CulturePerturbed(m=3, theta=sympy.Rational(1, 2), seed=42)
>>> profile = culture.random_profile(n=10000)
>>> print(profile)
Profile((0, 1, 2): 5778,
        (0, 2, 1): 864,
        (1, 0, 2): 883,
        (1, 2, 0): 830,
        (2, 0, 1): 835,
        (2, 1, 0): 810)

As expected, there are approximately 5000 voters (0, 1, 2) due to the Dirac part, and the other 5000 voters are approximately equally shared between all rankings, including the pole.

>>> culture.proba_high_low(c=0, higher={}, lower={1, 2})
2/3
>>> culture.proba_high_low(c=1, higher={}, lower={0, 2})
1/6

Particular case of a Dirac:

>>> culture = CulturePerturbed(m=6, theta=1)
>>> culture.proba_ranking([0, 1, 2, 3, 4, 5])
1
>>> culture.proba_ranking([2, 5, 0, 1, 3, 4])
0
>>> culture.proba_borda([5, 4, 3, 2, 1, 0])
1
>>> culture.proba_borda([3, 2, 5, 1, 0, 4])
0
>>> culture.random_ranking()
array([0, 1, 2, 3, 4, 5])
>>> culture.random_borda()
array([5, 4, 3, 2, 1, 0])

Particular case of the Impartial Culture:

>>> culture = CulturePerturbed(m=6, theta=0, seed=42)
>>> culture.proba_ranking([0, 1, 2, 3, 4, 5])
1/720
>>> culture.proba_ranking([2, 5, 0, 1, 3, 4])
1/720
>>> culture.proba_borda([5, 4, 3, 2, 1, 0])
1/720
>>> culture.proba_borda([3, 2, 5, 1, 0, 4])
1/720
>>> culture.random_ranking()
array([3, 4, 2, 0, 5, 1])
>>> culture.random_borda()
array([2, 5, 0, 3, 1, 4])
property average_profile#

Average profile.

Returns:

A profile where the weight for each ranking is the corresponding probability in the culture.

Return type:

Profile

proba_borda(borda)[source]#

Probability of a ranking, given in Borda format.

Parameters:

borda (List) – A ranking in Borda format. E.g. [3, 1, 2, 0] corresponds to the preference ranking 0 > 2 > 1 > 3.

Returns:

The probability to draw this ranking.

Return type:

float or sympy expr

proba_high_low(c, higher, lower)[source]#

Probability that a random ranking places candidate c below certain adversaries and above the other ones.

Parameters:
  • c (int) – A candidate.

  • higher (Set) – The adversaries that should be higher than c.

  • lower (Set) – The adversaries that should be lower than c. Note that together, c, higher and lower must cover all the candidates.

Returns:

Probability that for a random ranking in this culture, candidates from higher are higher than c and those from lower are lower than c.

Return type:

float

proba_ranking(ranking)[source]#

Probability of a ranking.

Parameters:

ranking (List) – A ranking. E.g. [0, 2, 1, 3] corresponds to the preference ranking 0 > 2 > 1 > 3.

Returns:

The probability to draw this ranking.

Return type:

float or sympy expr

random_borda()[source]#

Random ranking in Borda format.

Returns:

A random ranking in Borda format. E.g. [3, 1, 2, 0] corresponds to the preference ranking 0 > 2 > 1 > 3.

Return type:

ndarray

random_profile(n)[source]#

Random profile.

Parameters:

n (int) – Number of voters.

Returns:

A random profile.

Return type:

Profile

random_ranking()[source]#

Random ranking.

Returns:

A random ranking. E.g. [0, 2, 1, 3] corresponds to the preference ranking 0 > 2 > 1 > 3.

Return type:

ndarray