Skip to content

Commit

Permalink
WIP: Dominion tools
Browse files Browse the repository at this point in the history
  • Loading branch information
pbstark committed Oct 29, 2024
1 parent 036774f commit 546dbf5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 41 deletions.
51 changes: 13 additions & 38 deletions examples/ONEAudit-demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"* `quantile`: quantile of the sample size to use for setting initial sample size\n",
"* `cvr_file`: filename for CVRs (input)\n",
"* `manifest_file`: filename for ballot manifest (input)\n",
"* `use_style`: Boolean. If True, use card style information (inferred from CVRs) to target samples. If False, sample from all cards, regardless of the contest.\n",
"* `use_style`: Boolean. If True, use card style information (inferred from CVRs) to target samples. If False, sample from all cards, regardless of the contest. This should come from external touchstones such as physical inventories or voter participation records, not from the voting system. In particualar, it is dangerous to assume that every card containing a contest has a corresponding CVR that contains the contest.\n",
"* `sample_file`: filename for sampled card identifiers (output)\n",
"* `mvr_file`: filename for manually ascertained votes from sampled cards (input)\n",
"* `log_file`: filename for audit log (output)\n",
Expand Down Expand Up @@ -259,32 +259,33 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"# contests to audit. Edit with details of your contest (eg., Contest 339 is the DA race)\n",
"contest_dict = {'1':{\n",
"# contests to audit. Edit with details of your contest \n",
"contest_dict = {\n",
" '1':{\n",
" 'name': 'PRESIDENT OF THE UNITED STATES-DEM',\n",
" 'risk_limit': 0.05,\n",
" 'cards': 443578,\n",
" 'cards': 152649,\n",
" 'choice_function': Contest.SOCIAL_CHOICE_FUNCTION.PLURALITY,\n",
" 'n_winners': 1,\n",
" 'candidates': ['5',],\n",
" 'winner': ['5'],\n",
" 'n_winners': 1,\n",
" 'candidates': ['1','2','3','4','5','6','7','8'],\n",
" 'winner': ['5'],\n",
" 'assertion_file': None,\n",
" 'audit_type': Audit.AUDIT_TYPE.CARD_COMPARISON,\n",
" 'test': NonnegMean.alpha_mart,\n",
" 'estim': NonnegMean.optimal_comparison\n",
" },\n",
" '2':{\n",
" 'name': 'PRESIDENT OF THE UNITED STATES-REP',\n",
" 'name': 'PRESIDENT OF THE UNITED STATES-REP',\n",
" 'risk_limit': 0.05,\n",
" 'cards': 443578,\n",
" 'cards': 15591,\n",
" 'choice_function': Contest.SOCIAL_CHOICE_FUNCTION.PLURALITY,\n",
" 'n_winners': 1,\n",
" 'candidates': ['9','10','11','12'],\n",
" 'winner': ['11'],\n",
" 'candidates': ['10','11','12','13','14','15','16','17','9'],\n",
" 'winner': ['11'],\n",
" 'assertion_file': None,\n",
" 'audit_type': Audit.AUDIT_TYPE.CARD_COMPARISON,\n",
" 'test': NonnegMean.alpha_mart,\n",
Expand All @@ -295,32 +296,6 @@
"contests = Contest.from_dict_of_dicts(contest_dict)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Example of other social choice functions:\n",
"\n",
" contests = {'city_council':{'name': 'City Council',\n",
" 'risk_limit':0.05,\n",
" 'cards': None,\n",
" 'choice_function': Contest.SOCIAL_CHOICE_FUNCTION.PLURALITY,\n",
" 'n_winners':3,\n",
" 'candidates':['Doug','Emily','Frank','Gail','Harry'],\n",
" 'winner' : ['Doug', 'Emily', 'Frank']\n",
" },\n",
" 'measure_1':{'name': 'Measure 1',\n",
" 'risk_limit':0.05,\n",
" 'cards': 65432,\n",
" 'choice_function': Contest.SOCIAL_CHOICE_FUNCTION.SUPERMAJORITY,\n",
" 'share_to_win':2/3,\n",
" 'n_winners':1,\n",
" 'candidates':['yes','no'],\n",
" 'winner' : ['yes']\n",
" } \n",
" }"
]
},
{
"cell_type": "code",
"execution_count": 10,
Expand Down
8 changes: 5 additions & 3 deletions shangrla/formats/Dominion.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def get_contest_data(
def make_contest(
id,
data,
risk_limit=0.05,
risk_limit: float=0.05,
assertion_files={},
audit_type=Audit.AUDIT_TYPE.CARD_COMPARISON,
test=NonnegMean.alpha_mart,
Expand Down Expand Up @@ -370,9 +370,11 @@ def generate_contest_dict(
candidate_manifest,
assertion_files,
):
"""Given a list of CVRs, a contest manifest and a candidate manifest, and optionally a dict
"""
Given a list of CVRs, a contest manifest and a candidate manifest, and optionally a dict
of assertion files (where the key is the contest ID and the value, a filename, is a string),
return a dict of contests ready to process with SHANGRLA"""
return a dict of contests ready to process with SHANGRLA
"""

# First, get the vote and card tallies from the CVR list. The returned value is a dict of
# dicts with two top level keys "votes" and "cards".
Expand Down

0 comments on commit 546dbf5

Please sign in to comment.