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_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.
- 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]
- 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