Application-oriented mathematical algorithms for group testing
AApplication-oriented mathematical algorithms forgroup testing
Endre Cs´oka ∗ Alfr´ed R´enyi Institute of Mathematics, Budapest, Hungary
Abstract
We have a large number of samples and we want to find the infected ones usingas few number of tests as possible. We can use group testing which tells abouta small group of people whether at least one of them is infected. Group testingis particularly efficient if the infection rate is low. The goal of this article is tosummarize and extend the mathematical knowledge about the most efficient grouptesting algorithms. focusing on real-life applications instead of pure mathematicalmotivations and approaches.
Contents P (cid:47) K K < P < K K < P < K . . . . . . . . . . . . . 74.2 Extension to the case K < P < K . . . . . . . . . . . . . . . . . . . . . . 8 ∗ Supported by ERC Synergy grant No. 810115. a r X i v : . [ q - b i o . Q M ] M a y Introduction
Group testing algorithms have a huge mathematical literature, but these focus on theoret-ically interesting idealized models. This makes sense if we want to develop mathematicaltechniques, but these papers are too far from direct applications. The current COVID-19epidemic has created an urgent need for a more application-oriented summary and exten-sion of our knowledge about testing algorithms, considering the mathematically ugly butpractically important details.
The mathematical model.
We have N number of samples , each of them is positive with a (small) probability P , independently, and the rest are negative . Pool means aset of at most K samples. We can a test a pool, and it outputs whether there is at leastone positive sample in the pool. The goal is to identify the positive samples with theleast expected number of tests T . We can use an adaptive strategy, meaning that we canchoose the pools depending on the earlier test results.In this paper, we will use this mathematical model but also considering the following realistic refinements and goals . • We should not use the same sample for too many times and for too many rounds . Inmore detail, the samples are continuously arriving at a speed of our choice (roughly),and we can make tests in rounds with a limited testing capacity (approx. 100) perround. We prefer getting faster results compared to the arrival time of the sample,and we also prefer using our full testing capacity. • There is a small probability of false test results, and the larger the pool size thelower the confidence. Moreover, the test results are not completely binary. Mosttest results are clearly positive or negative, but there are some likely positive or likelynegative results with different confidence levels. Samples have a level of positivity,pooling takes approximately the average of these levels, and pools with lower positivelevels are more likely to give negative (or more likely negative) test results. • We may be able to collect some preliminary information about the infection prob-abilities, and there are positive correlations between some samples, but collectingthese information has a logistical cost. • The pooling algorithm will run partially manually, therefore we also try to offeralgorithms which are easy to implement, and which are not too strongly dependenton the infection rate P because we do not know P exactly.We think of K as constant, we will use the default value K = 10, and N as a largenumber, say, N > N → ∞ , and we will applyapproximations such as log K log log K ≈ The quality of pooling is about reproducibility and not about reliability. It means that weare only speaking about positive and negative samples, and our analysis is independentfrom what the test result tells about the person being infected. Therefore, for us, havingno false test results (which we will not assume very strictly) only means the followings.1. If we test the same single sample twice, then the two results should be the same.This (positive or negative) result is the type of the sample.2. If we test a pool of size at most K , then the result is positive if and only if at leastone of the samples is positive.For interpretation, a sample may refer to a joint sample of an entire household. Be-cause combining their biological samples saves some testing resources, and if any personof a household gets a positive result, then the entire household should be put into quar-antine anyway. This can be an important technique for application, and this affects theinterpretation of the pool size limit K and the infection rate P , but otherwise this isindependent from the mathematical analysis of pooling.“Next round” in our model may mean the second next round in practice, becausewe may need some time for preparation of the pools. Calculating with 3 hours longPolymerase Chain Reaction (PCR) tests, one more round means 6 hours delay in theresult. Using two machines with starting times shifted by 1 . . Finding the algorithm minimizing the expected number of tests in the strict mathematicalsense can be extremely hard. (The nature of the problem is similar to the “Subset Sum”problem.) But it is easy to find nearly optimal algorithms. Therefore, out of them, wetry to find the ones which are good at the other goals.The information-theoretical lower bound tells that we always need at least (cid:0) − P log ( P ) − (1 − P ) log (1 − P ) (cid:1) · N ≤ T (1)number of tests. This bound is pretty sharp if K log K < P < − P log ( P ) − (1 − P ) log (1 − P ) is the so-called “information content” or entropy of the3andom type of one sample, depending on the probability P of being positive. Assumingthat the types are independent (which is not really true in practice), we need to get N times this much information from the tests. A test can give at most 1 unit or 1 bit ofinformation. It gives exactly 1 bit if and only if it has a probability 50% for being positive(See Figure 1/a) given the earlier test results, and independently of the parallel tests.But we cannot approximate this probability 50% if P is too low. For those cases, weneed different bounds.We have the following lower bound which is pretty sharp for P < /K . N · (cid:0) − PK + 2 P (cid:1) ≤ T (2)(provided that P ≤ /K .)For low but not very low probabilities, namely, for K < P < K log K , we have thefollowing inequality: 2 − PK ≤ TN = t or t · (cid:18) − − PKt log 1 − PKt − (cid:16) − − PKt (cid:17) log (cid:16) − − PKt (cid:17)(cid:19) ≥ − P log P − (1 − P ) log(1 − P ) . (3)This bound is based on the fact that at least (1 − P ) NK test results must be negative, so ifthis is already more than half of the tests, then the probabilities cannot be close to 50%. The maximum of these three lower bounds, as in Figure 1/b is pretty sharp (for 0 < P <
Figure 1/a: The information content of a bi-nary variable (state of sample or test result)depending on the probability. E.g. if a test ispositive with a probability 50%, then it gives1 bit of information, and if a sample is pos-itive with probability 10%, then it requires0 .
47 bit of information. Figure 1/b: The figure shows the lowerbounds for the tests per samples ratio de-pending on the rate P of positive samples.The blue curve is the very same as on theleft, and the red dashed line and green dot-ted curve assume K = 10. P < K log K , then we should (almost) always use pools of size K , never use a samplein two parallel pooled tests, and it is somewhat better if we try to test pools with as closeprobabilities for being positive as possible. The lower P is the more useful it is to have alarger pool bound K . In particular, if P < K , then we only need 1 test per K samplesplus approx. 2 tests per positive sample. For small P , having preliminary informationabout which samples are somewhat more likely positive is not very useful.In contrast, for large P , the pool size limit K is not important, because we can find anapproximately optimal algorithm using smaller pool sizes. In this case, we can make useof the preliminary information about the individual probabilities of the samples, but it isenough to classify the samples into two or three classes, e.g. does or does not have anysymptoms. We can make negligible use of any further refinement of the prior probabilities.For a large infection rate P , constructing an almost efficient algorithm can be trans-lated to the following simple goal. We should always use pools where the result has around50% chance of being positive, and the parallel tests should be almost independent. Theseare the only things we should care about in order to be efficient. But for practical use,I would suggest to aim for a better trade-off of about 40-50%, because smaller probabil-ity implies smaller pools and using a sample in a smaller expected number a tests. Thebest trade-off depends on many parameters, but as long as these probabilities are alwaysbetween 30% and 60%, the algorithm is still pretty good. P (cid:47) K Number of tests : less than
N/K + 3
P N + K P N < (1 /K + 4 P ) N .A positive result requires 2 rounds with a 3rd round for final confirmation.A negative result requires typically 1, sometimes 2, very rarely 3 rounds.Pros: Easy to execute. It has a slightly higher tolerance for false test results, and gives aricher feedback about them.Cons: It requires at least P · N more tests than the optimal one, and becomes much moreinefficient with higher P . The algorithm.
In short, we test the samples in disjoint pools of size K , until a samplegets one negative or two positive pooled results. In the latter case, we make a confirmationtest for that single sample.In more detail, as soon as a sample has a negative pooled result, we report the sampleas negative. If a sample has two pooled positive results, then we report it as likely positive,but we make a final confirmation test for that single sample, with no pooling. If a samplehas one positive (and no negative) pooled result, then we call it a suspicious sample. Ineach round, beyond the confirmation tests, we choose the (fixed number of) disjoint poolsof K samples as follows. We distribute the suspicious samples into the pools as equallyas possible. Then we complete each pool with different unexamined samples to a total of K samples.Note that if the pools contain more than 2 suspicious samples, then it signals a higherinfection rate where this algorithm is less efficient.In case if we get a positive pooled result, but later all K samples get negative results,then it signals an error. Maybe the best way to fix it is to repeat the test which waspositive, or putting back the K samples to the list of unexamined samples.5 mprovement. There are plenty of possibilities for little improvements, but the simplestone is the following. If a sample has two clear, strong positive results, and all of its fellowsfrom the first positive pool got clear negative results in the second round, then we omitthe confirmation test for that sample.
Number of tests : approx. (1 /K + 2 P ) N provided that P < . K .A positive result requires typically 2, sometimes more rounds.A negative result requires typically 1, sometimes more rounds.Pros: Very efficient with the number of tests.Cons: Algorithmically more difficult. It is more sensitive for false test results. The algorithm.
Throughout the algorithm, the samples will be classified into 5 states:negative ( − ), unexamined (A), suspicios (B), likely positive (C), positive (+). States A,B, C express 0, 1, 2 active positive pool results, respectively. Initially, every sample is instate A. If a sample becomes likely positive (C), then we recommend putting them intoquarantine immediately.In every round, we choose the (fixed number of) pools by the following rule. We addone suspicious (B) sample into each pool until there is no more suspicious (B) sample. Orif suspicious samples arrive faster than this handling speed (which signals P > . /K ),then we can allow 2 suspicious samples per pool (or we should change the strategy tothe one in the next section). We complete every pool with unexamined (A) samples tothe size of K . If a test result is negative, then we change the state of all samples in itto negative ( − ). If a test result is positive, then each sample in it gets promoted to thenext state: A → B or B → C. We keep the records of every positive test until either ofthe following event happens. Out of the K samples, if all but one samples s are in thenegative ( − ) state, then we change the state of s to positive (+). Or if any of the samplesare in the positive (+) state, then we relegate every other sample in it: C → B, B → A(we withdraw the promotion).In case if we get a positive pooled result, but later all K samples get negative results,then it signals an error. Maybe the best way to fix it is to repeat the test which waspositive, or putting back the K samples to the list of unexamined samples.We may need to handle a very few samples which get stuck in state C. This is a minorissue except in the case of a higher infection rate P. We have multiple options as follows. Version A. (Simple.) We do nothing, namely, every person with likely positive (C)sample stays in quarantine.
Version B. (Safe.) If a sample stays in state C for a fixed number of rounds, or at theend, we make a confirmation test for that single sample.
Version C. (Efficient.) If we see a deadlock, which is a cycle in the hypergraph of likelypositive (C) samples and positive pools, then we test every second or third sample in thecycle. (Even more efficient if we test them in a pool with K − Version D.
An adaptive refined combination of the previous strategies, especially if thelogistics is directed by computer. 6
Efficient algorithms for infection rate K < P < K K < P < K Number of tests : approx. (1 /K + 4 P ) N , but the factor of 4 depends on P and theversion of the algorithm.A positive result requires approx. 4 rounds.A negative result requires 1 - 2 rounds in average.Pros: Very efficient with the number of tests.Cons: Algorithmically difficult. The algorithm.
The samples will be classified into 6 states: negative ( − ), unexamined(A), suspicios (B), very suspicious (C), likely positive (D), positive (+). States A, B, C,D express 0, 1, 2, 3 active positive pool results, respectively. Initially, every sample isin state A. If a sample becomes very suspicious (C), or at latest when it becomes likelypositive (D), then we recommend putting them into quarantine immediately.In every round, we choose the pools by the following rule. We make pools usingall suspicious (B) and very suspicious (C) samples, and with as many unexamined (A)samples as needed to make pools of size K , and we make it with as equal probabilities forthe pool being positive as we can.In particular, in the case of P < K √ K , for each very suspicious (C) sample, we makea pool with this sample and K − K . If a test resultis negative, then we change the state of all samples in it to negative ( − ).If a test result is positive, then each sample in it gets promoted to the next state: A → B, B → C or C → D. We keep the records of every positive test until either of thefollowing event happens. If all but one sample s are in the negative ( − ) state, then wechange the state of s to positive (+). Or if any of the samples are in the positive (+)state, then we relegate every other sample in it: D → C, C → B or B → A (we withdrawthe promotion).We may need to handle a very few samples which get stuck in state D. This is a minorissue except in the case of a higher infection rate. We have multiple options as follows. Version A.
We do nothing, namely, every person with likely positive (D) sample staysin quarantine.
Version B.
If a sample stays in state D for a fixed number of rounds, or at the end, wemake a confirmation test for that single sample. The larger P the less we should waitwith confirmation.Or somewhat independently of these versions, we can use one of the following variantsof the algorithm. Variant 1.
A safer but less efficient variant is that we change the status of a sample s to positive (+) only if not one but two records of positive pools imply that s must be thepositive sample. Variant 2.
If the pooling algorithm is directed by a computer, then these algorithms(including the one in the previous section) can be very slightly improved, and classes A,7, C, D could be replaced essentially with probabilities. In each round, we should makepools of approximately equal probabilities of being positive (any reasonable heuristicalalgorithm would be good here). This could also handle the case of non-binary test resultsbut different levels of ambiguity in them. K < P < K In this parameter regime, the best algorithm depends on many factors, and we haveto choose between efficiency and simplicity. But in the case if the pool size limit K iscritical, and smaller pools would provide better confidence, then probably the best solutionis decreasing K from the 2nd or 3rd round, hereby testing smaller pools. In addition oralternatively, for the samples reaching the “likely positive” (D) state, we consider them asan input of an algorithm designed for a higher infection rate. (This is a generalization ofVersion B.)But if computer support is available, then we can slightly improve the algorithmaccording to Variant 2, or following the guidelines in Section 2.1. Number of tests : approx. 2 √ P · N if P (cid:39) K , otherwise N · (cid:0) K − (1 − P ) K (cid:1) .A positive result requires 2 rounds.A negative result requires 1 or 2 rounds.Pros: Better tolerance for test errors, easy to execute, fast result, universal with noassumption on the infection rate.Cons: Not very efficient with the number of tests, especially around the infection rate P ≈ K log ( K ) . It may use twice (more than (cid:113) K log ( K ) times) as much tests as the mostefficient algorithm. The algorithm.
Let k ≈ min (cid:16) K, (cid:113) P (cid:17) . Test the new samples k by k in disjoint pools,and if a result is positive, then in the next round, test all samples in the pool one by one.(If none of these k tests are positive, then it signals a test error. In this case, we couldsimply repeat the procedure from testing again the same pool of k samples.) Version 1.
For a positive pool of k samples, we test only k − k samples inthe next round. If any of them is positive, then the k th sample should be put back to thelist of unexamined samples (and maybe make sure that next time it will not be the k thsample again). If all of them are negative, then the k th one must be positive. Optionally,we can make a confirmation test next round, but we should not wait for it with reportingthe positive result. Version 2.
After a positive pooled result of K samples, in the next round we test themin disjoint pools of size L = (cid:100)√ K (cid:101) by L , leaving approximately L samples untested. Thenin the third round, we test the individual samples which got the second positive pooledresult. About the samples which were untested in the second round, we test them in thethird round individually if none of the pools in the second round were positive, otherwisewe put them back to the list of unexamined samples.8 ersion 3. We can modify Version 2 so that we test some pools in the second round sothat some samples are tested in multiple pools. This can provide more efficient algorithms,but the algorithm depends on the level of disadvantages of using larger pools, on the rateof false test results, and on K and P . This algorithm is primarily suggested for those who are familiar with the well-known butINEFFICIENT ALGORITHM SHOWN IN THE FIGURE. Our algorithm is an improve-ment of that one.
Number of tests : close to the entropy bound (1) if P (cid:39) K , otherwise at most 1 /K + P log( K ).A positive result requires log ( k ) + 1 rounds in average, worst case is 2 log ( k ) rounds.A negative result requires 2 rounds in average, but the worst case is 2 log ( k ) rounds.Pros: Universal with no assumption on the infection rate, very efficient if P > K . Easyto execute for those who are familiar with the classical inefficient algorithm.Cons: Requires too many rounds. It is not efficient with the number of tests for infectionrate P < K . Around the infection rate P ≈ K log ( K ) , it may use up to 20% more testsas the most efficient algorithm. The algorithm.
For k ≈ min (cid:0) K, log(0 . / log(1 − P ) (cid:1) (where “0 .
55” is 1 − (the approx.40-50% mentioned in Section 2.1)), we test the samples k by k in disjoint pools, and if aresult is positive, then we repeat the following procedure starting with these k suspicioussamples in X . As long as we have more than 1 suspicious samples in X , we test a poolwith half of them, rounded down (preferably choosing the samples which arrived earlier).Figure 2: DO NOT USE THIS ALGORITHM! This is a visualization of the advantages ofpooling, and it shows a well-known but inefficient algorithm. Our algorithm in Section 5.2is an improvement of this one. (For example, always dividing into not 2 but 3 parts wouldalready improve this algorithm.) The figure is taken from medium.com.9f positive, then we continue the procedure with this half of samples X and the other half X = X \ X should be put back to the list of unexamined samples. If negative, then wecontinue the algorithm with the other half of samples X . If 1 suspicious sample remainsin X , then we report it positive. Variant 1.
If a test result was not very clear, or we continued with the second half ofsamples for too many consequtive rounds, or by any reason we start to have doubt thatthere is indeed a positive sample in the current set of suspicious samples, then next roundwe test a pool with more than half of the suspicious samples, but at most all but oneof them. If the test result of all but one suspicious samples was still negative, then nextround we make a confirmation test for that only remaining sample.
Variant 2.
Independently from Variant 1, if we see that a halved pool X was positive,but less strongly positive than the bigger pool X = X ∪ X , then test the other half X ,as well. This variant is not recommended for P < K . The best algorithm is highly dependent on the fine parameters of the problem and ourpreferences, as listed in the introduction. We list the most likely suggestions consider-ing efficiency, simplicity and fast result, focusing on the case if we have no preliminaryinformation about which samples are more likely positive. We list them with decreasingorder of P . Section 2 helps finding a pretty efficient algorithm considering any possibleparameters and preferences. Phase 1. If P >
38% (or in the idealized model,
P > −√ ≈ . Phase 2.
For 23% ≤ P ≤ k = 2.) If the result is positive, then the safer and faster butless efficient option is testing both samples in the next round. But, especially for lower P and less correlation between two neighboring samples, we can improve it by the followingmodification.If we pool the samples (1 , ,
3) with a new sample 3, because sample2 is not more suspicious than an unexamined sample. This algorithm saves 11.2% of thetests at an infection rate P = 30% and 18 .
9% at rate P = 25%, in the idealized model.(We conjecture that this algorithm minimizes the number of tests for 27% < P < As a more generaly tool , if we know that at least one of samples 1 and 2 must bepositive, and this and the prior probabilities are all we know about them, then in thenext round, we test only sample 1. If the result is negative, then we know that sample2 must be positive. Or if sample 1 is positive, then we put back sample 2 to the list ofunexamined samples. 10 hase 3.
For 15% ≤ P ≤ , , ,
4) and (2 , ,
4) was positive but (2 ,
4) was negative, then we report that sample 1 ispositive, samples 2 and 4 are negative, and we put sample 3 back to the list of unexaminedsamples.If both are positive, then we test samples 1 and 2 alone. If both are positive, thenwe put samples 3 and 4 back to the unexamined tests. If one is positive and the otheris negative, then we report sample 4 to be positive and we put sample 3 back to theunexamined tests. If both are negative, then we report both samples 3 and 4 as positive.At an infection rate of 20%, this algorithm saves 27 .
6% of the tests compared to thetrivial algorithm, and 4 .
2% compared to the algorithm in Phase 2.
Phases 4-5.
For 10% < P < < P < < P <
Phases 7-8.
For 7% < P < < P < < P < , ,
3) and(1 , , , ,
3) and (1 , ,
5) are positive, then we test the pool(1 , ,
3) is positive, then we apply the algorithm inPhase 2 for samples 2 and 3, and Phase 3 for samples 1 , , , ,
3) and (1 , ,
5) are positive and (1 , ,
5) was the more stronglypositive one, then we test the pool (4 ,
5) instead.)
Phase 10.
For 5% < P < P ), and if positive,then we test two pools of 4 samples: (1 , , ,
4) and (1 , , , , , ,
4) and (1 , , ,
7) are positive, then we test the pool (2 , , , , , ,
4) is positive, then we apply the algorithm in Phase 3for samples 2 , ,
4, and Phase 3 for samples 1 , , , , , ,
4) and (1 , , ,
7) are positive and (1 , , ,
7) was the morestrongly positive one, then we test the pool (5 , ,
7) instead.)
Acknowledgements
I want to say thank you to Vikt´oria L´az´ar, P´eter Vilmos and the Suppress19 group forpractical information about pooled testing.11 eferences [1] Gyula Katona. On separating systems of a finite set.
Journal of Combinatorial Theory ,1(2):174–194, 1966.[2] Yaakov Malinovsky. Conjectures on optimal nested generalized group testing algo-rithm. arXiv preprint arXiv:1805.01345 , 2018.[3] Claude E Shannon. A mathematical theory of communication.
Bell system technicaljournal , 27(3):379–423, 1948.[4] Noam Shental, Shlomia Levy, Shosh Skorniakov, Vered Wuvshet, Yonat Shemer-Avni,Angel Porgador, and Tomer Hertz. Efficient high throughput sars-cov-2 testing todetect asymptomatic carriers. medRxiv , 2020.[5] P´eter Ung´ar. The cutoff point for group testing.