OrdinalElection#

class OrdinalElection(experiment_id=None, election_id=None, culture_id=None, votes=None, label=None, num_voters: int = None, num_candidates: int = None, fast_import=False, frequency_matrix=None, params=None, **kwargs)[source]#

Ordinal Election class.

compute_distances(distance_id='swap', object_type=None)[source]#

Return: distances between votes

compute_voting_rule(method=None, committee_size=None)[source]#

Compute winners using the given voting rule and return them.

This sets self.winners (existing behavior) and also returns the winners for convenience so callers can do w = obj.compute_voting_rule(…).

get_bordawise_vector(is_recomputed=False)[source]#

Return the Borda-style vector for the election, computing it if needed.

Parameters:

is_recomputed (bool) – If True, force recomputation even if a cached value exists.

get_frequency_matrix(is_recomputed=False)[source]#

Get frequency_matrix.

get_potes(is_recomputed=False)[source]#

Get potes.

import_ideal_points(name)[source]#

Import ideal points from a CSV file.

The file is expected to have two columns (x, y) without a header.

Parameters:

name (str) – Base name of the file to import (without path or extension).

Returns:

List of ideal points as [x, y] coordinates.

Return type:

list of [float, float]

import_ordinal_election()[source]#

Import ordinal election.

is_condorcet()[source]#

Check if election witness Condorcet winner

prepare_instance(is_exported=None, is_aggregated=True)[source]#

Prepares instance

set_microscope(radius=None, alpha=0.1, s=30, object_type=None, double_gradient=False, color='blue', marker='o', title_size=20)[source]#

Set up a Microscope (2D scatter plot) for visualizing election data.

This method configures and saves a Microscope object to self.microscope, which can be used for detailed inspection of the election’s spatial properties.

Parameters:
  • radius (float or None) – If given, set the x and y limits of the plot to be centered around the average coordinates with this radius.

  • alpha (float) – Transparency level for the points in the scatter plot.

  • s (int) – Base size for the points in the scatter plot (scaled by voter quantity).

  • object_type (str or None) – Type of objects to plot (‘vote’ or ‘candidate’). If None, inferred from self.object_type.

  • double_gradient (bool) – If True, use a double gradient based on voter coordinates for coloring.

  • color (str) – Base color for the points in the scatter plot.

  • marker (str) – Marker style for the points in the scatter plot.

  • title_size (int) – Font size for the title of the plot.

Returns:

The configured Microscope object.

Return type:

Microscope

static texify_label(name)[source]#

Convert a label string to a TeX-friendly format.

This is used for rendering labels in plots with proper mathematical formatting.

Parameters:

name (str) – The label string to convert.

Returns:

The converted label string, suitable for use in TeX/LaTeX.

Return type:

str

try_updating_params()[source]#

Update self.params based on culture_id when available.

This uses culture-specific logic (e.g. pseudo-cultures) to ensure params are consistent with the number of candidates.

votes_to_agg_voterlikeness_vector()[source]#

Converts ordinal votes to Borda vector.

votes_to_pairwise_matrix() ndarray[source]#

Convert votes to pairwise matrix.

votes_to_voterlikeness_matrix(vote_distance='swap') ndarray[source]#

convert VOTES to voter-likeness MATRIX

convert_votes_to_potes(votes) ndarray[source]#

Convert votes to positional votes (potes).

Parameters:

votes (sequence) – Iterable of vote rankings (iterables of candidate indices).

Returns:

Array of potes with shape (len(votes), num_candidates).

Return type:

np.ndarray