// 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(last(l1), first(l2)); int falsePositives = countPred(l1, d -> d > threshold); // can be optimized int falseNegatives = countPred(l2, d -> d <= threshold); // ditto int i1 = binarySearch_insertionPoint(l1, threshold); int i2 = binarySearch_insertionPoint(l2, threshold); if (falsePositives > falseNegatives) { // TODO } else if (falseNegatives > falsePositives) { while (i2+1 < l(l2)) { double threshold2 = avg(l2.get(i), l2.get(i+1)); if (l2.get(i2) > threshold2) } } ret t3(threshold, falsePositives, falseNegatives); }