r2b2.simulation.athena

Module Contents

class r2b2.simulation.athena.AthenaOneRoundRisk(alpha, delta, reported, sample_size, db_mode=True, db_host='localhost', db_name='r2b2', db_port=27017, user='writer', pwd='icanwrite', *args, **kwargs)[source]

Bases: r2b2.simulator.Simulation

Simulate a 1-round Athena audit for a given sample size to compute risk limit.

trial(self, seed)[source]

Execute a 1-round athena audit (using r2b2.athena.Athena)

analyze(self, verbose: bool = False, hist: bool = False)[source]

Analyze trials to get experimental risk.

Parameters
  • verbose (bool) – If true, analyze will print simulation analysis information.

  • hist (bool) – If true, analyze will generate and display 2 histograms: winner ballots found in the sample size and computed risk.

run(self, n: int)

Execute n trials of the simulation.

Executes n simulation trials by generating a random seed, running a trial with the given seed, and writing the trial entry to the trials collection.

Parameters

n (int) – Number of trials to execute and write to database.

get_seed(self)

Generate a random seed.

Note

This method generates 8 random bytes using os sources of randomness. If a different source of randomness is desired, overwrite the method per implementation.

output(self, fd: str = None)

Write output of simulation to JSON file.

Parameters

fd (str) – filename to write output to. If no file is passed, formatted JSON is simply printed.

output_audit(self)

Create audit output in JSON format.

Note

This functionality is separated into a method so specific audit implementations may override it and customize their output in non-database mode.

class r2b2.simulation.athena.AthenaOneRoundStoppingProb(alpha, delta, reported, sample_size, db_mode=True, db_host='localhost', db_name='r2b2', db_port=27017, user='writer', pwd='icanwrite', *args, **kwargs)[source]

Bases: r2b2.simulator.Simulation

Simulate a 1-round Athena audit for a given sample size to compute stopping probability.

trial(self, seed)[source]

Execute a 1-round athena audit (using r2b2.athena.Athena)

analyze(self, verbose: bool = False, hist: bool = False)[source]

Analyse trials to get experimental stopping probability

run(self, n: int)

Execute n trials of the simulation.

Executes n simulation trials by generating a random seed, running a trial with the given seed, and writing the trial entry to the trials collection.

Parameters

n (int) – Number of trials to execute and write to database.

get_seed(self)

Generate a random seed.

Note

This method generates 8 random bytes using os sources of randomness. If a different source of randomness is desired, overwrite the method per implementation.

output(self, fd: str = None)

Write output of simulation to JSON file.

Parameters

fd (str) – filename to write output to. If no file is passed, formatted JSON is simply printed.

output_audit(self)

Create audit output in JSON format.

Note

This functionality is separated into a method so specific audit implementations may override it and customize their output in non-database mode.