ElectionExperiment#

class ElectionExperiment(is_shifted=False, **kwargs)[source]#
add_election(culture_id='none', label=None, color='black', alpha: float = 1.0, show: bool = True, marker='x', ms=20, starting_from: int = 0, size: int = 1, num_candidates: int | None = None, num_voters: int | None = None, election_id: str | None = None, instance_id: str | None = None, frequency_matrix=None, is_temporary: bool = False, params: dict | None = None)[source]#

Adds election to the experiment.

Parameters:
  • culture_id (str) – Culture id.

  • label (str) – Label.

  • color – Color.

  • alpha (float) – Alpha.

  • show (bool) – If true the election is shown.

  • marker (str) – Marker.

  • ms (int) – Marker size.

  • starting_from (int) – Starting index.

  • size (int) – Size.

  • num_candidates (int) – Number of candidates.

  • num_voters (int) – Number of voters.

  • election_id (str) – Election id.

  • instance_id (str) – Instance id.

  • frequency_matrix (list) – Frequency matrix.

  • is_temporary (bool) – If true the election is temporary.

  • params (dict) – Model parameters.

Returns:

List of IDs of added instances.

Return type:

list

add_election_to_family(election=None, family_id=None) None[source]#

Adds an election to a family.

Parameters:
  • election (Election) – The election to add to the family.

  • family_id (str) – The id of the family to add the election to.

Return type:

None

add_empty_family(culture_id: str = 'none', label: str | None = None, color: str = 'black', alpha: float = 1.0, show: bool = True, marker: str = 'o', num_candidates: int | None = None, num_voters: int | None = None, family_id: str | None = None)[source]#

Adds an empty family of elections to the experiment.

Parameters:
  • culture_id (str) – Culture id.

  • label (str) – Label.

  • color (str) – Color.

  • alpha (float) – Alpha.

  • show (bool) – If true the family is shown.

  • marker (str) – Marker.

  • num_candidates (int) – Number of candidates.

  • num_voters (int) – Number of voters.

  • family_id (str) – Family id.

add_existing_family_from_dir(dir: str | None = None, culture_id: str | None = None, **kwargs) list[source]#

Adds family of elections to the experiment from the given directory.

Parameters:
  • dir (str) – Directory.

  • culture_id (str) – Culture id.

  • **kwargs (dict) – Additional parameters.

Returns:

List of the families.

Return type:

list

add_family(culture_id: str = 'none', size: int = 1, label: str | None = None, color: str = 'black', alpha: float = 1.0, show: bool = True, marker: str = 'o', ms: int = 20, starting_from: int = 0, num_candidates: int | None = None, num_voters: int | None = None, frequency_matrix=None, is_temporary: bool = False, family_id: str | None = None, single: bool = False, path: dict | None = None, params: dict | None = None) list[source]#

Adds family of elections to the experiment.

Parameters:
  • culture_id (str) – Culture id.

  • label (str) – Label.

  • color – Color.

  • alpha (float) – Alpha (i.e., transparency).

  • show (bool) – If true the family is shown.

  • marker (str) – Marker.

  • ms (int) – Marker size.

  • starting_from (int) – Starting index.

  • size (int) – Size.

  • num_candidates (int) – Number of candidates.

  • num_voters (int) – Number of voters.

  • frequency_matrix (list) – Frequency matrix.

  • is_temporary (bool) – If true the election is temporary.

  • family_id (str) – Family id.

  • single (bool) – If true only one election is added.

  • path (dict) – Path.

  • params (dict) – Model parameters.

Returns:

List of IDs of added instances.

Return type:

list

add_instances_to_experiment() None[source]#

Add instances to the experiment.

Returns:

None

compute_feature(feature_id: str | None = None, feature_params: dict | None = None, overwrite: bool = False, saveas: str | None = None, **kwargs) dict[source]#

Computes a feature for each in instances in the experiment.

Parameters:
  • feature_id (str) – The id of the feature to compute.

  • feature_params (dict) – The parameters of the feature to compute.

  • overwrite (bool) – Whether to overwrite the feature if it already exists.

  • saveas (str)

Returns:

A dictionary with the computed feature for each instance.

Return type:

dict

compute_rules(list_of_rules: list, committee_size: int = 10, resolute: bool = False) None[source]#

Computes the winning committees for a list of rules.

Parameters:
  • list_of_rules (list) – A list of rules to compute the winning committees for.

  • committee_size (int) – The size of the winning committees.

  • resolute (bool) – Whether to compute the resolute committees.

Return type:

None

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

Computes voting rule for all elections in the experiment.

Parameters:
  • method (str) – Name of the boting rule to be computed.

  • committee_size (int) – Size of the committee.

Return type:

None

import_committees(list_of_rules) None[source]#

Imports the winning committees for a list of rules.

Parameters:

list_of_rules (list) – A list of rules to import the winning committees for.

Return type:

None

import_controllers() list[source]#

Import controllers from a file

Returns:

List of families.

Return type:

list

prepare_elections(export_points=False, is_aggregated=True) None[source]#

Prepares elections for a given experiment.

Parameters:
  • export_points (bool) – Whether to store points in the instance.

  • is_aggregated (bool) – Whether to aggregate the instances.

Return type:

None

set_default_committee_size(committee_size: int) None[source]#

Sets default size of the committee

Parameters:

committee_size (int) – Committee size.

Return type:

None

set_default_num_candidates(num_candidates: int) None[source]#

Sets default number of candidates

Parameters:

num_candidates (int) – Number of candidates.

Return type:

None

set_default_num_voters(num_voters: int) None[source]#

Sets default number of voters

Parameters:

num_voters (int) – Number of voters.

Return type:

None