// find best threshold value to separate list1 (smaller values) from list2 (bigger values), minimizing false positives + false negatives // returns (threshold, false positives, false negatives) static T3 findBestThreshold(Cl list1, Cl list2) { if (empty(list1) || empty(list2)) null; L l1 = sorted(list1); L l2 = sorted(list2); double threshold = avg(doubleMax(l1), doubleMin(l2)); int falsePositives = countPred(l1, d -> d > threshold); // can be optimized int falseNegatives = countPred(l2, d -> d <= threshold); // ditto if (falsePositives > falseNegatives) { } else if (falseNegatives > falsePositives) { } ret t3(threshold, falsePositives, falseNegatives); }