WorkSession#

class actinvoting.WorkSession(culture, c, alpha=None, tau=None)[source]#

A working session specifying the culture, the candidate of interest and the vector of threshold alpha.

This is used to study the probability that candidate c is an alpha-winner in a profile drawn from the culture.

Parameters:
  • culture (Culture) – The culture, i.e., the probability distribution over the rankings.

  • c (int) – The candidate of interest.

  • alpha (list of sympy.Rational, optional) – The vector of thresholds alpha. By convention, it is of size m and the coefficient alpha[c] is not used. If alpha is not specified, it is set to [1/2, 1/2, …, 1/2], corresponding to the usual notion of Condorcet winner.

  • tau (list of sympy.Rational, optional) – The log saddle point. If not specified, it is computed by maximizing the psi function. The advantage of specifying it is that it can be used for formal computations (whereas when it is computed by the work session itself, this is done by numerical optimization).

property characteristic_polynomial#

The characteristic polynomial P of the culture.

Returns:

The characteristic polynomial.

Return type:

sympy.Expr

property critical_candidates#

The critical candidates.

In practice, we compute the critical candidates as those for which tau[j] is numerically close enough to 0.

Returns:

The critical candidates.

Return type:

set of int

property cumulant#

The cumulant generating function K.

Returns:

The cumulant generating function K(t) = log(P(e^t)).

Return type:

sympy.Expr

property det_hessian_of_k_at_tau#

The determinant of the Hessian of the cumulant at the log saddle point.

Returns:

The determinant of the Hessian of the cumulant at the log saddle point.

Return type:

sympy.Expr

equivalent(n)[source]#

The equivalent of the probability that candidate c is an alpha-winner in a profile of size n.

Parameters:

n (int) – The number of voters.

Returns:

The value of the theoretical equivalent of the probability.

Return type:

float

exact_probability(n)[source]#

The exact probability that candidate c is an alpha-winner in a profile of size n.

Take self.polynom_of_duels, raise to the power n, then take the coefficients of all the monomials such that for each adversary j, the exponent of x[j] is less than beta[j] n.

Be careful, this is computationally expensive.

Parameters:

n (int) – The number of voters.

Returns:

The exact probability.

Return type:

float

property hessian_of_k_at_tau#

The Hessian of the cumulant at the log saddle point.

Returns:

The Hessian of the cumulant at the log saddle point.

Return type:

sympy.Matrix

property hessian_of_k_at_tau_computed_from_h_p_zeta#

The Hessian of the cumulant at the log saddle point, computed from the Hessian of the characteristic polynomial.

Returns:

The Hessian of the cumulant at the log saddle point, computed from the Hessian of the characteristic polynomial. This must equal to hessian_of_k_at_tau. It can be used as a sanity check. Furthermore, due to the symbolic computation via sympy, it may happen that one expression is simpler than the other.

Return type:

sympy.Matrix

property hessian_of_p_at_zeta#

The Hessian of the characteristic polynomial at the saddle point.

Returns:

The Hessian of the characteristic polynomial at the saddle point.

Return type:

sympy.Matrix

property integral_of_gaussian_m#

The integral appearing in the theoretical equivalent.

Returns:

The integral.

Return type:

float

property integral_of_gaussian_m_with_error#

The integral appearing in the theoretical equivalent, along the margin of error in the numerical integration.

Returns:

The integral along with the margin of error.

Return type:

tuple of float

property inverse_of_hessian_of_k_at_tau#

The inverse of the Hessian of the cumulant at the log saddle point.

Returns:

The inverse of the Hessian of the cumulant at the log saddle point.

Return type:

sympy.Matrix

property matrix_m#

The matrix M.

This is the submatrix of the inverse of the Hessian of the cumulant at the log saddle point corresponding to the critical candidates. It appears in the theoretical equivalent.

Returns:

The matrix M.

Return type:

np.ndarray

property n_critical_candidates#

The number of critical candidates.

Returns:

The number of critical candidates.

Return type:

int

property n_subcritical_candidates#

The number of subcritical candidates.

Returns:

The number of subcritical candidates.

Return type:

int

property p_of_zeta#

The value of the characteristic polynomial at the saddle point.

Returns:

The value of the characteristic polynomial at the saddle point.

Return type:

sympy.Expr

property psi#

The psi function.

Returns:

The psi function, i.e., psi(t) = -K(t) + beta^T t.

Return type:

sympy.Expr

property subcritical_candidates#

The subcritical candidates.

In practice, we compute the subcritical candidates as those for which tau[j] is less than 0, but not numerically too close to 0 (cf. critical candidates).

Returns:

The subcritical candidates.

Return type:

set of int

property tau#

The log saddle point.

In the paper, tau is of size m-1, but here we return the full m-size vector. We set conventionally tau[c] = 0.

Returns:

The log saddle point, i.e., the unique argmax of psi.

Return type:

list of sympy.Rational

property zeta#

The saddle point.

In the paper, zeta is of size m-1, but here we return the full m-size vector. We set conventionally zeta[c] = 1.

Returns:

The saddle point, i.e., e^tau.

Return type:

list of sympy.Rational