The best match is determined by the highest magnitude weight
544488
def _best_match_syn(self, sx, sys, scope_map):
        
        SUBSTRING_WEIGHT = 0.2
        WBEST = None
        sbest = None
        sxv = self._standardize_label(sx.val)
        sxp = self._id_to_ontology(sx.class_id)
        for sy in sys:
            syv = self._standardize_label(sy.val)
            syp = self._id_to_ontology(sy.class_id)
            W = None
            if sxv == syv:
                confidence = sx.confidence * sy.confidence
                if sx.is_abbreviation() or sy.is_abbreviation:
                    confidence *= self._get_config_val(sxp, 'abbreviation_confidence', 0.5)
                    confidence *= self._get_config_val(syp, 'abbreviation_confidence', 0.5)
                W = scope_map[sx.scope()][sy.scope()] + logit(confidence/2)
            elif sxv in syv:
                W = np.array((-SUBSTRING_WEIGHT, SUBSTRING_WEIGHT, 0, 0))
            elif syv in sxv:
                W = np.array((SUBSTRING_WEIGHT, -SUBSTRING_WEIGHT, 0, 0))
            if W is not None:
                # 
                if WBEST is None or max(abs(W)) > max(abs(WBEST)):
                    WBEST = W
                    sbest = sy
        return WBEST, sbest
1055833
def assign_best_matches(self, xg):
        
        logging.info("assigning best matches for {} nodes".format(len(xg.nodes())))
        for i in xg.nodes():
            xrefmap = self._neighborscores_by_ontology(xg, i)
            for (ontid,score_node_pairs) in xrefmap.items():
                score_node_pairs.sort(reverse=True)
                (best_score,best_node) = score_node_pairs[0]
                logging.info("BEST for {}: {} in {} from {}".format(i, best_node, ontid, score_node_pairs))
                edge = xg[i][best_node]
                dirn = self._dirn(edge, i, best_node)
                best_kwd = 'best_' + dirn
                if len(score_node_pairs) == 1 or score_node_pairs[0] > score_node_pairs[1]:
                    edge[best_kwd] = 2
                else:
                    edge[best_kwd] = 1
                for (score,j) in score_node_pairs:
                    edge_ij = xg[i][j]
                    dirn_ij = self._dirn(edge_ij, i, j)
                    edge_ij['cpr_'+dirn_ij] = score / sum([s for s,_ in score_node_pairs])
        for (i,j,edge) in xg.edges(data=True):
            # reciprocal score is set if (A) i is best for j, and (B) j is best for i
            rs = 0
            if 'best_fwd' in edge and 'best_rev' in edge:
                rs = edge['best_fwd'] * edge['best_rev']
            edge['reciprocal_score'] = rs
            edge['cpr'] = edge['cpr_fwd'] * edge['cpr_rev']
923043
def best_fit(li, value):
    """"""

    index = min(bisect_left(li, value), len(li) - 1)

    if index in (0, len(li)):
        return index

    if li[index] - value < value - li[index-1]:
        return index
    else:
        return index-1
202157
public void finest(String mesg, Throwable t) {
        log(Level.FINEST, mesg, t);
    }
903761
def select_k_best(self, k):
        
        x_new = SelectKBest(chi2, k=k).fit_transform(self.x_train, self.y_train)
        return x_new
202980
public static Weight max(Weight w1, Weight w2) {
        if (w1 == null) {
            throw new IllegalArgumentException("Argument w1 cannot be null");
        }
        if (w2 == null) {
            throw new IllegalArgumentException("Argument w2 cannot be null");
        }
        if ((w1.isInfinity && w1.posOrNeg) || (w2.isInfinity && !w2.posOrNeg)) {
            return w1;
        } else if ((w2.isInfinity && w2.posOrNeg)
                || (w1.isInfinity && !w1.posOrNeg)) {
            return w2;
        } else if (w1.val >= w2.val) {
            return w1;
        } else {
            return w2;
        }
    }
1327794
def best_result(self):
        
        best_result = None
        for result in self.results:
            if best_result is None or result.figure_of_merit > best_result.figure_of_merit:
                best_result = result
        return best_result
86890
private static Result findResultWithMaxEnd(List<Result> successResults) {
        return Collections.max(
                successResults, new Comparator<Result>() {
                    @Override
                    public int compare(Result o1, Result o2) {
                        return Integer.valueOf(o1.end()).compareTo(o2.end());
                    }
                });
    }
1294793
synchronized Weight getMaximumDuration() {
        if (calcMaxDuration == null) {
            Weight max = WeightFactory.ZERO;
            for (int i = 0, n = intervals.size(); i < n; i++) {
                Object start = intervals.get(i).getStart();
                Map<?, Weight> d = BellmanFord.calcShortestDistances(start,
                        directedGraph, BellmanFord.Mode.SOURCE);
                if (d == null) {
                    throw new IllegalStateException("Negative cycle detected!");
                }
                for (int j = 0; j < n; j++) {
                    Object finish = intervals.get(j).getFinish();
                    max = Weight.max(max, d.get(finish));
                }
            }
            calcMaxDuration = max;
        }

        return calcMaxDuration;
    }
1111887
public static IBond.Order getMaximumBondOrder(IBond.Order firstOrder, IBond.Order secondOrder) {
        if (firstOrder == Order.UNSET) {
            if (secondOrder == Order.UNSET) throw new IllegalArgumentException("Both bond orders are unset");
            return secondOrder;
        }
        if (secondOrder == Order.UNSET) {
            if (firstOrder == Order.UNSET) throw new IllegalArgumentException("Both bond orders are unset");
            return firstOrder;
        }

        if (isHigherOrder(firstOrder, secondOrder))
            return firstOrder;
        else
            return secondOrder;
    }
228486
def gbest_idx(swarm):
    
    best = 0
    cmp = comparator(swarm[best].best_fitness)
    for (idx, particle) in enumerate(swarm):
        if cmp(particle.best_fitness, swarm[best].best_fitness):
            best = idx
    return best
546118
@Override
    public Status match(int cc)
    {
        int highest = -1;
        Iterator<Matcher> iterator = active.iterator();
        while (iterator.hasNext())
        {
            Matcher matcher = iterator.next();
            Status s = matcher.match(cc);
            highest = Math.max(highest, s.ordinal());
            switch (s)
            {
                case Match:
                    lastMatched = matcher;
                    clear();
                    return s;
                case WillMatch:
                    lastMatched = matcher;
                    return s;
                case Error:
                    iterator.remove();
                    break;
            }
        }
        if (active.isEmpty())
        {
            clear();
            return Status.Error;
        }
        return Status.values()[highest];
    }
346289
public static String bestMatch(Collection<String> supported, String header) {
        List<ParseResults> parseResults = new LinkedList<>();
        List<FitnessAndQuality> weightedMatches = new LinkedList<>();
        for (String r : header.split(",")) {
            parseResults.add(parseMediaRange(r));
        }

        for (String s : supported) {
            FitnessAndQuality fitnessAndQuality = fitnessAndQualityParsed(s, parseResults);
            fitnessAndQuality.mimeType = s;
            weightedMatches.add(fitnessAndQuality);
        }
        Collections.sort(weightedMatches);

        FitnessAndQuality lastOne = weightedMatches.get(weightedMatches.size() - 1);
        return Float.compare(lastOne.quality, 0) != 0 ? lastOne.mimeType : NO_MIME_TYPE;
    }
1305226
protected static boolean checkMax(ImageBorder_F32 inten, float bestScore, int c_x, int c_y) {
		for( int y = c_y -1; y <= c_y+1; y++ ) {
			for( int x = c_x-1; x <= c_x+1; x++ ) {
				if( inten.get(x,y) >= bestScore ) {
					return false;
				}
			}
		}
		return true;
	}
614940
function ruleWeight (inside, text, maxSubseqLen, i, j, k, opt) {
  var rhsLen = opt.rhs.length
  if ((rhsLen === 0 && i !== j) || (rhsLen === 1 && k < j))
    return 0
  var w = opt.weight
  for (var pos = 0; w && pos < rhsLen; ++pos) {
    var node = opt.rhs[pos]
    var start = pos ? k : i, len = pos ? (j-k) : (k-i), idx = len
    if (start && len > maxSubseqLen) {
      if (start + len === text.length)
        idx = maxSubseqLen + 1
      else
        return 0
    }
    var insideCell
    w *= (node.type === 'term'
	  ? (node.text.length === len && node.text === text.substr(start,len) ? 1 : 0)
	  : (((insideCell = inside[start][idx]) && insideCell[node.rank]) || 0))
  }
  return w
}
274626
function findBestPatternMatch(values, getPattern, candidate) {
        var matchedValue = undefined;
        // use length of prefix as betterness criteria
        var longestMatchPrefixLength = -1;
        for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
            var v = values_1[_i];
            var pattern = getPattern(v);
            if (isPatternMatch(pattern, candidate) && pattern.prefix.length > longestMatchPrefixLength) {
                longestMatchPrefixLength = pattern.prefix.length;
                matchedValue = v;
            }
        }
        return matchedValue;
    }
1319672
@Override
    public Long getMaximumFinish() {
        calculator();
        if (simple) {
            return v[3];
        } else {
            Weight maxFinish = cn.getMaximumFinish();
            return maxFinish.isInfinity() ? null : maxFinish.value();
        }
    }