Skip to content

Instantly share code, notes, and snippets.

@darius
Last active July 10, 2020 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darius/ecb7a372ff55f3b29e4797b47bc9cc42 to your computer and use it in GitHub Desktop.
Save darius/ecb7a372ff55f3b29e4797b47bc9cc42 to your computer and use it in GitHub Desktop.
"""
Evaluation of Group Testing for SARS-Cov-2 RNA.pdf
"""
from __future__ import division
import itertools, random
def runs(n, R, C, npositive):
return [run(R, C, npositive) for _ in range(n)]
# R, C: Dimensions (rows/columns) of the well plate.
# prevalence: Rate of positive samples.
def run(R, C, prevalence):
all_rows = set(range(R))
all_cols = set(range(C))
# All of the well coordinates, and a set of positive ones
# sprinkled at random.
wells = list(itertools.product(all_rows, all_cols))
positive_wells = [coords for coords in wells
if random.random() < prevalence]
# Test pooled samples for rows and columns;
# exclude the negative rows and columns.
pos_rows = {r for (r,c) in positive_wells}
pos_cols = {c for (r,c) in positive_wells}
remaining_samples = [(r,c) for (r,c) in wells
if r in pos_rows
and c in pos_cols]
def show_well_plate():
for r in range(R):
for c in range(C):
if (r,c) in positive_wells: print '*',
elif (r,c) in remaining_samples: print '.',
else: print ' ',
print
total_test_count = R + C + len(remaining_samples)
return total_test_count
def average(xs): return sum(xs) / len(xs)
trials = 10000
prevalence = 0.01
def experiment(R, C):
better_by = R*C / average(runs(trials, R, C, prevalence))
return better_by
## experiment(8, 12)
#. 4.448171847705716
## experiment(10, 10)
#. 4.5975954575756885
## experiment(16, 24)
#. 6.991300928168024
## experiment(20, 20)
#. 7.145434603196153
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment