Experiment Module¶
Experiment is a convenient way to configure and run your computations.
Experiment¶
-
class
pmp.experiments.Experiment(config=None)¶ Experiment to run
-
add_election(rule, k, id)¶ - Parameters
rule (Rule) – Scoring rule for added election
k (int) – Size of the winning committee for added election
id (str) – Text id for the election. Builds up first part of output filenames
For multi-rule experiments. It’s preferred way of defining elections in experiments.
-
get_generated_dir_path()¶ - Returns
Path to the root directory where files are generated
- Return type
str
-
run(visualization=False, n=1, save_win=False, save_in=False, save_out=False, log_on=True, elect_configs=None, split_dirs=True)¶ - Parameters
visualization (bool) –
n (int) –
save_win (bool) –
save_in (bool) –
save_out (bool) –
log_on (bool) –
elect_configs (List[ElectionConfig]) – Election configs. If given, experiment ignores it’s one-rule configuration
split_dirs (bool) – When True create separate directory for each election related files
Run experiment. Experiment runs elections configured in following precedence: * from elect_configs parameter, if present * set up from election_configurations added by add_election, if added * set up from set_election
-
set_election(rule, k)¶ - Parameters
rule (Rule) – Scoring rule being set
k (int) – Size of the committee being set
[Deprecated] Set election parameters the rule and the size of the committee. Overrides previous experiment setup. Only for setting up one-rule experiments.
-
set_generated_dir_path(dir_path)¶ - Parameters
dir_path (str) – Path to the root directory where files are generated
-
set_inout_filename(name)¶ - Parameters
name (str) – Inout filename
Set filename of files containing generated candidates and voters. Overrides previous value. Only for setting up one-rule experiments.
-
set_result_filename(name)¶ - Parameters
name (str) – Result filename
[Deprecated] Set result name. It builds up first part of names of all files being generated during experiment. Overrides previous value. Only for setting up one-rule experiments.
-
ExperimentConfig¶
-
class
pmp.experiments.ExperimentConfig(id='')¶ Store candidates and voters configuration. Above properties can be stored as static values or generating functions, so different setup is generated each time.
-
get_candidates()¶ - Returns
Copy of candidates
- Return type
List
-
impartial(m, n)¶ Candidates in impartial only as a list of consecutive integers starting from 0
-
set_candidates(list_of_candidates)¶ - Parameters
list_of_candidates (List) – List of candidates
-
ElectionConfig¶
-
class
pmp.experiments.ElectionConfig(rule, k, id)¶ Election configuration used by an Experiment
Histogram¶
-
class
pmp.experiments.Histogram(minx, maxx, miny, maxy, opacity_mask=(1.0, 1.0, 1.0), ppu=None, W=256, H=256)¶ Two-dimensional histogram.
-
accumulate(points)¶ - Parameters
points (List[Tuple[float, float]]) – List of points to be accumulated into histogram.
-
draw_fixed_points(points, color, size=0)¶ - Parameters
points (List[Tuple[float, float]]) – List of points to be draw.
color (Tuple[int, int, int]) – RGB color of points.
size (int) – Size of points. When equal 0 draw single pixel.
Draw fixed points over the main histogram layer.
-
save_image(path)¶ Saves the histogram image. Fixed points are drawn above the histogram itself.
-
Helpers¶
-
pmp.experiments.helpers.process_win_dir(path, strategy)¶ - Parameters
path (str) – path of processed directory
strategy (Callable[List, List, List, List, str]) – Run with {candidates, voters, preferences, winners, election}
Helper for processing experiment-generated directories. Visits all election directories stored in path directory. After loading .win file runs strategy with candidates, voters, preferences, winners, election args. Election is a string id.