# -*- coding: utf-8 -*- """What the check costs, as a function of how often ordinary mail is novel. The first run of check.py reported a 65.8 percent flag rate on legitimate drafts and an 85.4 percent flag rate overall. Both numbers are true of the corpus and neither is true of an inbox, because the corpus holds 40 drafts of each class, so two thirds of its legitimate traffic genuinely introduces something new. A real mailbox is overwhelmingly ordinary replies. The corpus measures the per-class behaviour, which is deterministic and sharp: every class is caught at 100 percent or flagged at 100 percent. What it cannot measure is the mix, and the mix decides the cost. **The mix is an assumption, so it is published as a range rather than as a result**, and a deployment measures its own. python sensitivity.py writes sensitivity.json """ import io import json import os HERE = os.path.dirname(os.path.abspath(__file__)) # Per-class flag rates, measured. These are the only numbers the bench produces. MEASURED = { 'clean': 0.000, 'legit-iban': 1.000, 'legit-newcontact': 0.975, 'fraud-iban': 1.000, 'fraud-recipient': 1.000, 'fraud-link': 1.000, 'fraud-attach': 1.000, } # Mixes, stated as assumptions. Each says how many of 1,000 outgoing drafts fall # in each legitimate class. Fraud is handled separately because its rate is the # thing nobody knows and the control exists for the case where it is not zero. MIXES = { 'conservative': {'clean': 1000 - 5 - 20, 'legit-iban': 5, 'legit-newcontact': 20}, 'central': {'clean': 1000 - 2 - 10, 'legit-iban': 2, 'legit-newcontact': 10}, 'quiet desk': {'clean': 1000 - 1 - 4, 'legit-iban': 1, 'legit-newcontact': 4}, } def main(): out = {'measured_per_class': MEASURED, 'mixes': {}} print('%-14s %12s %14s %18s' % ('mix', 'flags/1000', 'per 100 a day', 'minutes a day at 30s')) for name, mix in MIXES.items(): flags = sum(n * MEASURED[k] for k, n in mix.items()) per_1000 = flags per_100_day = flags / 10.0 minutes = per_100_day * 30 / 60.0 out['mixes'][name] = { 'assumed_mix_per_1000': mix, 'flags_per_1000_drafts': round(per_1000, 1), 'flag_rate': round(per_1000 / 1000.0, 4), 'flags_per_100_drafts_a_day': round(per_100_day, 1), 'review_minutes_a_day_at_30s_each': round(minutes, 1), } print('%-14s %12.1f %14.1f %18.1f' % (name, per_1000, per_100_day, minutes)) out['note'] = ( 'Per-class rates are measured on 280 drafts and are deterministic. The ' 'mixes are assumptions, not measurements, and they decide the cost ' 'entirely. A deployment measures its own mix before adopting the control.') io.open(os.path.join(HERE, 'sensitivity.json'), 'w', encoding='utf-8', newline='').write(json.dumps(out, indent=1)) print() print('recall on every fraud class is 100 percent at every mix, because the') print('check is a lookup and does not depend on how common the attack is.') if __name__ == '__main__': main()