Score local alignment for a given position in the query sequence for a linear gap penalty
@param x
@param gep
@param subs
@param storing
@param scores
@param xyMax
@param score
@return
420090
public static Last[][] setScoreVector(int x, int gep, int[] subs, boolean storing, int[][][] scores,
			int[] xyMax, int score) {
		return setScoreVector(x, 0, 0, scores[0].length - 1, gep, subs, storing, scores, xyMax, score);
	}
849702
public static <S extends Sequence<S>> Alignment<S> rightTrimAlignment(Alignment<S> alignment,
                                                                         AlignmentScoring<S> scoring) {
        if (scoring instanceof LinearGapAlignmentScoring)
            return rightTrimAlignment(alignment, (LinearGapAlignmentScoring<S>) scoring);
        else if (scoring instanceof AffineGapAlignmentScoring)
            return rightTrimAlignment(alignment, (AffineGapAlignmentScoring<S>) scoring);
        else
            throw new IllegalArgumentException("Unknown scoring type");
    }
632343
public void setScore(Double score) {
    if(score == null) {
      score = Constants.DEFAULT_SCORE;
    }
    this.score = score;
  }
650342
public static ScoreComponent of(final @NonNull String name, final @NonNull String objective) {
    return of(name, objective, null);
  }
762008
private int getSubstitutionScore(float[] qv, float[] tv) {
		float score = 0.0f;
		for (int q = 0; q < qv.length; q++) {
			if (qv[q] > 0.0f) {
				for (int t = 0; t < tv.length; t++) {
					if (tv[t] > 0.0f) {
						score += qv[q]*tv[t]*getSubstitutionMatrix().getValue(cslist.get(q), cslist.get(t));
					}
				}
			}
		}
		return Math.round(score);
	}
52569
@Override
    protected double scoreImpl(List<Word> words1, List<Word> words2) {
        //用词频来标注词的权重
        taggingWeightWithWordFrequency(words1, words2);
        //构造权重快速搜索容器
        Map<String, Float> weights1 = toFastSearchMap(words1);
        Map<String, Float> weights2 = toFastSearchMap(words2);
        //所有的不重复词
        Set<Word> words = new HashSet<>();
        words.addAll(words1);
        words.addAll(words2);
        //向量的维度为words的大小，每一个维度的权重是词频
        //manhattanDistance=|x1-x2|+|y1-y2|
        AtomicFloat manhattanDistance = new AtomicFloat();
        //计算
        words
            .parallelStream()
            .forEach(word -> {
                Float x1 = weights1.get(word.getText());
                Float x2 = weights2.get(word.getText());
                if (x1 == null) {
                    x1 = 0f;
                }
                if (x2 == null) {
                    x2 = 0f;
                }
                //|x1-x2|
                float oneOfTheDimension = Math.abs(x1 - x2);
                //+
                manhattanDistance.addAndGet(oneOfTheDimension);
            });
        double score = 0;
        if(manhattanDistance.get() == 0){
            //距离为0，表示完全相同
            score = 1.0;
        }else {
            //使用BigDecimal保证精确计算浮点数
            //score = 1 / (double)(manhattanDistance.get()+1);
            score = BigDecimal.valueOf(1).divide(BigDecimal.valueOf(manhattanDistance.get()+1), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
        }
        if(LOGGER.isDebugEnabled()){
            LOGGER.debug("文本1和文本2的曼哈顿距离："+manhattanDistance.get());
            LOGGER.debug("文本1和文本2的相似度分值：1 / (double)("+manhattanDistance.get()+"+1)="+score);
        }
        return score;
    }
812858
private AbstractPlanNode indexAccessForGroupByExprs(SeqScanPlanNode root,
            IndexGroupByInfo gbInfo) {
        if (! root.isPersistentTableScan()) {
            // subquery and common tables are not handled
            return root;
        }

        String fromTableAlias = root.getTargetTableAlias();
        assert(fromTableAlias != null);

        List<ParsedColInfo> groupBys = m_parsedSelect.groupByColumns();
        Table targetTable = m_catalogDb.getTables().get(root.getTargetTableName());
        assert(targetTable != null);
        CatalogMap<Index> allIndexes = targetTable.getIndexes();

        List<Integer> maxCoveredGroupByColumns = new ArrayList<>();
        ArrayList<AbstractExpression> maxCoveredBindings = null;
        Index pickedUpIndex = null;
        boolean foundAllGroupByCoveredIndex = false;

        for (Index index : allIndexes) {
            if ( ! IndexType.isScannable(index.getType())) {
                continue;
            }

            if ( ! index.getPredicatejson().isEmpty()) {
                // do not try to look at Partial/Sparse index
                continue;
            }

            ArrayList<AbstractExpression> bindings = new ArrayList<>();
            List<Integer> coveredGroupByColumns = calculateGroupbyColumnsCovered(
                    index, fromTableAlias, bindings);

            if (coveredGroupByColumns.size() > maxCoveredGroupByColumns.size()) {
                maxCoveredGroupByColumns = coveredGroupByColumns;
                pickedUpIndex = index;
                maxCoveredBindings = bindings;

                if (maxCoveredGroupByColumns.size() == groupBys.size()) {
                    foundAllGroupByCoveredIndex = true;
                    break;
                }
            }
        }
        if (pickedUpIndex == null) {
            return root;
        }

        IndexScanPlanNode indexScanNode = new IndexScanPlanNode(
                root, null, pickedUpIndex, SortDirectionType.INVALID);
        indexScanNode.setForGroupingOnly();
        indexScanNode.setBindings(maxCoveredBindings);

        gbInfo.m_coveredGroupByColumns = maxCoveredGroupByColumns;
        gbInfo.m_canBeFullySerialized = foundAllGroupByCoveredIndex;
        return indexScanNode;
    }
550630
def score_pairwise(aseq, bseq):
    """"""
    assert len(aseq) == len(bseq)

    # Affine gap penalties -- default values from EMBOSS needle/water
    GAP_OPEN = -10.0
    GAP_EXTEND = -0.5
    GAP_CHARS = frozenset('-.')

    score = 0.0
    in_gap = True   # Don't apply the opening penalty to the N-terminal gap

    for ares, bres in zip(aseq.upper(), bseq.upper()):
        if ares in GAP_CHARS and bres in GAP_CHARS:
            # Both are gaps -- this happens in multiple sequence alignments
            continue
        match = blosum62.get((ares, bres), None)
        if match is None:
            assert GAP_CHARS.intersection((ares, bres)), \
                    "Expected one gap in: " + str((ares, bres))
            # Gap
            if not in_gap:
                score += GAP_OPEN
                in_gap = True
            score += GAP_EXTEND
        else:
            in_gap = False
            score += match

    if in_gap:
        # Correct for a penalty on the C-terminal gap
        score -= GAP_OPEN

    return score
660601
private static final double scoreAfp(AFP afp, double badRmsd, double fragScore)
	{
		//longer AFP with low rmsd is better
		double  s, w;
		//s = (rmsdCut - afptmp.rmsd) * afptmp.len; //the same scroing strategy as that in the post-processing
		w = afp.getRmsd() / badRmsd;
		w = w * w;
		s = fragScore * (1.0 - w);
		return s;
	}
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']
1335117
def hasScoreBetterThan(self, score):
        
        # Note: Do not assume that HSPs in an alignment are sorted in
        # decreasing order (as they are in BLAST output). If we could
        # assume that, we could just check the first HSP in each alignment.
        for hsp in self.hsps():
            if hsp.betterThan(score):
                return True
        return False
1355034
public static void outsideAlgorithm(final Hypergraph graph, final Hyperpotential w, final Semiring s,
            final Scores scores) {
        scores.alpha = outsideAlgorithm(graph, w, s, scores.beta);
    }
806661
private static void insideAlgorithm(final double[][] scores, final ProjTreeChart inChart, boolean singleRoot) {
        final int n = scores.length;        
        final int startIdx = singleRoot ? 1 : 0;         

        // Initialize.
        for (int s = 0; s < n; s++) {
            inChart.setScore(s, s, RIGHT, COMPLETE, 0.0);
            inChart.setScore(s, s, LEFT, COMPLETE, 0.0);
        }
                
        // Parse.
        for (int width = 1; width < n; width++) {
            for (int s = startIdx; s < n - width; s++) {
                int t = s + width;
                
                // First create incomplete items.
                for (int r=s; r<t; r++) {
                    for (int d=0; d<2; d++) {
                        double edgeScore = (d==LEFT) ? scores[t][s] : scores[s][t];
                        double score = inChart.getScore(s, r, RIGHT, COMPLETE) +
                                       inChart.getScore(r+1, t, LEFT, COMPLETE) +  
                                       edgeScore;
                        inChart.updateCell(s, t, d, INCOMPLETE, score, r);
                    }
                }
                
                // Second create complete items.
                // -- Left side.
                for (int r=s; r<t; r++) {
                    final int d = LEFT;
                    double score = inChart.getScore(s, r, d, COMPLETE) +
                                inChart.getScore(r, t, d, INCOMPLETE);
                    inChart.updateCell(s, t, d, COMPLETE, score, r);
                }
                // -- Right side.
                for (int r=s+1; r<=t; r++) {
                    final int d = RIGHT;
                    double score = inChart.getScore(s, r, d, INCOMPLETE) +
                                   inChart.getScore(r, t, d, COMPLETE);
                    inChart.updateCell(s, t, d, COMPLETE, score, r);
                }                
            }
        }
        
        if (singleRoot) {
            // Build goal constituents by combining left and right complete
            // constituents, on the left and right respectively. This corresponds to
            // left and right triangles. (Note: this is the opposite of how we
            // build an incomplete constituent.)
            for (int r=1; r<n; r++) {
                double score = inChart.getScore(1, r, LEFT, COMPLETE) +
                               inChart.getScore(r, n-1, RIGHT, COMPLETE) + 
                               scores[0][r];
                inChart.updateCell(0, r, RIGHT, INCOMPLETE, score, r);
                inChart.updateCell(0, n-1, RIGHT, COMPLETE, score, r);
            }
        }
    }
1239655
public Optional<FMeasureInfo> score(final Iterable<? extends Iterable<?>> predicted,
      final Iterable<? extends Iterable<?>> gold) {
    final List<Set<Object>> predictedAsSets = CorefScorerUtils.toSets(predicted);
    final List<Set<Object>> goldAsSets = CorefScorerUtils.toSets(gold);

    final Map<Object, Set<Object>> predictedItemToGroup =
        CollectionUtils.makeElementsToContainersMap(predictedAsSets);
    final Map<Object, Set<Object>> goldItemToGroup =
        CollectionUtils.makeElementsToContainersMap(goldAsSets);

    CorefScorerUtils.checkPartitionsOverSameElements(predictedItemToGroup.keySet(),
        goldItemToGroup.keySet());

    final Optional<Float> recall =
        mucScoreComponent(goldAsSets, predictedAsSets, predictedItemToGroup);
    final Optional<Float> precision =
        mucScoreComponent(predictedAsSets, goldAsSets, goldItemToGroup);

    if (recall.isPresent() && precision.isPresent()) {
      // why are these floats?
      return Optional.<FMeasureInfo>of(new PrecisionRecallPair(precision.get(), recall.get()));
    } else {
      return Optional.absent();
    }
  }
121882
private void initializeLookupTable(double[][] splitPositions, NumberVector query, double p) {
    final int dimensions = splitPositions.length;
    final int bordercount = splitPositions[0].length;
    lookup = new double[dimensions][bordercount];
    for(int d = 0; d < dimensions; d++) {
      final double val = query.doubleValue(d);
      for(int i = 0; i < bordercount; i++) {
        lookup[d][i] = FastMath.pow(splitPositions[d][i] - val, p);
      }
    }
  }
67968
public static Last[][] setScoreVector(int x, Subproblem subproblem, int gop, int gep, int[] subs, boolean storing,
			int[][][] scores) {
		return setScoreVector(x, subproblem.getQueryStartIndex(), subproblem.getTargetStartIndex(), subproblem.getTargetEndIndex(), gop, gep, subs, storing, scores, subproblem.isStartAnchored());
	}
660516
def score_xrefs_by_semsim(self, xg, ont=None):
        
        logging.info("scoring xrefs by semantic similarity for {} nodes in {}".format(len(xg.nodes()), ont))
        for (i,j,d) in xg.edges(data=True):
            pfx1 = self._id_to_ontology(i)
            pfx2 = self._id_to_ontology(j)
            ancs1 = self._blanket(i)
            ancs2 = self._blanket(j)
            s1,_,_ = self._sim(xg, ancs1, ancs2, pfx1, pfx2)
            s2,_,_ = self._sim(xg, ancs2, ancs1, pfx2, pfx1)
            s = 1 - ((1-s1) * (1-s2))
            logging.debug("Score {} x {} = {} x {} = {} // {}".format(i,j,s1,s2,s, d))
            xg[i][j][self.SIMSCORES] = (s1,s2)
            xg[i][j][self.SCORE] *= s