Simple wrapper around ROUGE-L implementation.

    :param hypotheses: Hypotheses stream.
    :param references: Reference stream.
    :return: ROUGE-L score as float between 0 and 1.
485593
def raw_corpus_rougel(hypotheses: Iterable[str], references: Iterable[str]) -> float:
    
    return rouge.rouge_l(hypotheses, references)
1198362
def get_similar(obj, labels, default=None, min_similarity=0.5):
    
    raise NotImplementedError(
        "Unfinished implementation, needs to be in fuzzy_get where list of scores & keywords is sorted.")
    labels = listify(labels)

    def not_found(*args, **kwargs):
        return 0

    min_score = int(min_similarity * 100)
    for similarity_score in [100, 95, 90, 80, 70, 50, 30, 10, 5, 0]:
        if similarity_score <= min_score:
            similarity_score = min_score
        for label in labels:
            try:
                result = obj.get(label, not_found)
            except AttributeError:
                try:
                    result = obj.__getitem__(label)
                except (IndexError, TypeError):
                    result = not_found
            if result is not not_found:
                return result
        if similarity_score == min_score:
            if result is not not_found:
                return result
947055
def compute_bleu_summaries(hook_args):
  
  decode_hparams = hook_args.decode_hparams

  if not (decode_hparams.decode_reference and decode_hparams.decode_to_file):
    return None

  values = []
  bleu = 100 * bleu_hook.bleu_wrapper(
      decode_hparams.decode_reference, decode_hparams.decode_to_file)
  values.append(tf.Summary.Value(tag="BLEU", simple_value=bleu))
  tf.logging.info("%s: BLEU = %6.2f" % (decode_hparams.decode_to_file, bleu))
  if hook_args.hparams.mlperf_mode:
    current_step = decode_hparams.mlperf_decode_step
    mlperf_log.transformer_print(
        key=mlperf_log.EVAL_TARGET, value=decode_hparams.mlperf_threshold)
    mlperf_log.transformer_print(
        key=mlperf_log.EVAL_ACCURACY,
        value={
            "epoch": max(current_step // decode_hparams.iterations_per_loop - 1,
                         0),
            "value": bleu
        })
    mlperf_log.transformer_print(key=mlperf_log.EVAL_STOP)

  if bleu >= decode_hparams.mlperf_threshold:
    decode_hparams.set_hparam("mlperf_success", True)

  return values
1340535
def score_evidence_list(self, evidences):
        """"""
        def _score(evidences):
            if not evidences:
                return 0
            # Collect all unique sources
            sources = [ev.source_api for ev in evidences]
            uniq_sources = numpy.unique(sources)
            # Calculate the systematic error factors given unique sources
            syst_factors = {s: self.prior_probs['syst'][s]
                            for s in uniq_sources}
            # Calculate the radom error factors for each source
            rand_factors = {k: [] for k in uniq_sources}
            for ev in evidences:
                rand_factors[ev.source_api].append(
                    evidence_random_noise_prior(
                        ev,
                        self.prior_probs['rand'],
                        self.subtype_probs))
            # The probability of incorrectness is the product of the
            # source-specific probabilities
            neg_prob_prior = 1
            for s in uniq_sources:
                neg_prob_prior *= (syst_factors[s] +
                                   numpy.prod(rand_factors[s]))
            # Finally, the probability of correctness is one minus incorrect
            prob_prior = 1 - neg_prob_prior
            return prob_prior
        pos_evidence = [ev for ev in evidences if
                        not ev.epistemics.get('negated')]
        neg_evidence = [ev for ev in evidences if
                        ev.epistemics.get('negated')]
        pp = _score(pos_evidence)
        np = _score(neg_evidence)
        # The basic assumption is that the positive and negative evidence
        # can't simultaneously be correct.
        # There are two cases to consider. (1) If the positive evidence is
        # incorrect then there is no Statement and the belief should be 0,
        # irrespective of the negative evidence.
        # (2) If the positive evidence is correct and the negative evidence
        # is incorrect.
        # This amounts to the following formula:
        # 0 * (1-pp) + 1 * (pp * (1-np)) which we simplify below
        score = pp * (1 - np)
        return score
373935
def _as_reference_point(self) -> np.ndarray:
        
        ref_val = []
        for fn, f in self._classification.items():
            if f[0] == "<":
                ref_val.append(self._method.problem.ideal[fn])
            elif f[0] == "<>":
                ref_val.append(self._method.problem.nadir[fn])
            else:
                ref_val.append(f[1])

        return np.array(ref_val)
996670
def raw_corpus_bleu(hypotheses: Iterable[str], references: Iterable[str], offset: Optional[float] = 0.01) -> float:
    
    return sacrebleu.raw_corpus_bleu(hypotheses, [references], smooth_floor=offset).score / 100.0
135990
def get_annotation_sufficiency(
            self,
            profile: List[str],
            negated_classes: List[str],
            categories: Optional[List] = None,
            negation_weight: Optional[float] = .25,
            category_weight: Optional[float] = .5) -> AnnotationSufficiency:
        

        if categories is None:
            categories = [enum.value for enum in HpoUpperLevel]
        ic_map = self.ic_store.get_profile_ic(profile + negated_classes)

        # Simple score is the weighted average of the present and
        # explicitly stated negative/absent phenotypes
        #
        # Note that we're deviating from the publication
        # to match the reference java implementation where
        # mean_max_ic is replaced with max_max_ic:
        # https://github.com/owlcollab/owltools/blob/452b4a/
        # OWLTools-Sim/src/main/java/owltools/sim2/AbstractOwlSim.java#L1038
        simple_score = self._get_simple_score(
            profile, negated_classes, self.ic_store.statistics.mean_mean_ic,
            self.ic_store.statistics.max_max_ic, self.ic_store.statistics.mean_sum_ic,
            negation_weight, ic_map
        )

        categorical_score = self._get_categorical_score(
            profile, negated_classes, categories,
            negation_weight, ic_map
        )
        scaled_score = self._get_scaled_score(
            simple_score, categorical_score, category_weight)

        return AnnotationSufficiency(
            simple_score=simple_score,
            scaled_score=scaled_score,
            categorical_score=categorical_score
        )
139638
def BP(candidate, references):
    
    c = len(candidate)
    ref_lens = (len(reference) for reference in references)
    r = min(ref_lens, key=lambda ref_len: (abs(ref_len - c), ref_len))

    if c > r:
        return 1
    else:
        return math.exp(1 - r / c)
303769
def _evaluate_tempyREPR(self, child, repr_cls):
        """"""
        score = 0
        if repr_cls.__name__ == self.__class__.__name__:
            # One point if the REPR have the same name of the container
            score += 1
        elif repr_cls.__name__ == self.root.__class__.__name__:
            # One point if the REPR have the same name of the Tempy tree root
            score += 1

        # Add points defined in scorers methods of used TempyPlaces
        for parent_cls in _filter_classes(repr_cls.__mro__[1:], TempyPlace):
            for scorer in (
                method for method in dir(parent_cls) if method.startswith("_reprscore")
            ):
                score += getattr(parent_cls, scorer, lambda *args: 0)(
                    parent_cls, self, child
                )
        return score
866522
private void trueOutliers(HilbertFeatures h) {
    n_star = 0;
    for(ObjectHeap.UnsortedIter<HilFeature> iter = h.out.unsortedIter(); iter.valid(); iter.advance()) {
      HilFeature entry = iter.get();
      if(entry.ubound >= omega_star && (entry.ubound - entry.lbound < 1E-10)) {
        n_star++;
      }
    }
  }
250735
def MP(candidate, references, n):
    
    counts = Counter(ngrams(candidate, n))
    if not counts:
        return 0

    max_counts = {}
    for reference in references:
        reference_counts = Counter(ngrams(reference, n))
        for ngram in counts:
            max_counts[ngram] = max(max_counts.get(ngram, 0), reference_counts[ngram])

    clipped_counts = dict((ngram, min(count, max_counts[ngram])) for ngram, count in counts.items())

    return sum(clipped_counts.values()) / sum(counts.values())
1033126
def _vec_lnqmed_residuals(self, catchments):
        
        result = np.empty(len(catchments))
        for index, donor in enumerate(catchments):
            result[index] = self._lnqmed_residual(donor)
        return result
765651
public Counter<L> scoresOf(Datum<L, F> example) {
    if(example instanceof RVFDatum<?, ?>)return scoresOfRVFDatum((RVFDatum<L,F>)example);
    Collection<F> feats = example.asFeatures();
    int[] features = new int[feats.size()];
    int i = 0;
    for (F f : feats) {
      int index = featureIndex.indexOf(f);
      if (index >= 0) {
        features[i++] = index;
      } else {
        //System.err.println("FEATURE LESS THAN ZERO: " + f);
      }
    }
    int[] activeFeatures = new int[i];
    System.arraycopy(features, 0, activeFeatures, 0, i);
    Counter<L> scores = new ClassicCounter<L>();
    for (L lab : labels()) {
      scores.setCount(lab, scoreOf(activeFeatures, lab));
    }
    return scores;
  }
215504
def get_keep_score(source_counts, prediction_counts, target_counts):
  """"""
  source_and_prediction_counts = source_counts & prediction_counts
  source_and_target_counts = source_counts & target_counts
  true_positives = sum((source_and_prediction_counts &
                        source_and_target_counts).values())
  selected = sum(source_and_prediction_counts.values())
  relevant = sum(source_and_target_counts.values())
  return _get_fbeta_score(true_positives, selected, relevant)
121494
def scores_to_preds(self, threshold, use_probs = True):
        
        self.threshold = threshold

        if use_probs:
            if self.probs is None:
                raise DataError("Probabilities are not available to make "
                                "predictions.")
            else:
                word = "probabilities"
                scores = self.probs
        else:
            if self.scores is None:
                raise DataError("Scores are not available to make predictions.")
            else:
                word = "scores"
                scores = self.scores

        if threshold > np.max(scores) or threshold < np.min(scores):
            warnings.warn("Threshold {} is outside the range of the "
                          "{}.".format(self.threshold, word))

        if self.preds is not None:
            warnings.warn("Overwriting predictions")
        self.preds = (scores >= threshold)*1
1363681
def reffs(self) -> BaseReferenceSet:
        
        if not self._cts:
            self._cts = BaseReferenceSet(
                [reff for reffs in [self.getReffs(level=i) for i in range(1, len(self.citation) + 1)] for reff in reffs]
            )
        return self._cts
1315387
public OutlierResult run(Relation<Model> models, Relation<NumberVector> vecs, Relation<?> labels) {
    WritableDoubleDataStore scores = DataStoreUtil.makeDoubleStorage(models.getDBIDs(), DataStoreFactory.HINT_HOT);

    HashSet<GeneratorSingleCluster> generators = new HashSet<>();
    for(DBIDIter iditer = models.iterDBIDs(); iditer.valid(); iditer.advance()) {
      Model model = models.get(iditer);
      if(model instanceof GeneratorSingleCluster) {
        generators.add((GeneratorSingleCluster) model);
      }
    }
    if(generators.isEmpty()) {
      LOG.warning("No generator models found for dataset - all points will be considered outliers.");
    }
    for(GeneratorSingleCluster gen : generators) {
      for(int i = 0; i < gen.getDim(); i++) {
        Distribution dist = gen.getDistribution(i);
        if(!(dist instanceof NormalDistribution)) {
          throw new AbortException("TrivialGeneratedOutlier currently only supports normal distributions, got: " + dist);
        }
      }
    }

    for(DBIDIter iditer = models.iterDBIDs(); iditer.valid(); iditer.advance()) {
      double score = 1.;
      double[] v = vecs.get(iditer).toArray();
      for(GeneratorSingleCluster gen : generators) {
        double[] tv = v;
        // Transform backwards
        if(gen.getTransformation() != null) {
          tv = gen.getTransformation().applyInverse(v);
        }
        final int dim = tv.length;
        double lensq = 0.0;
        int norm = 0;
        for(int i = 0; i < dim; i++) {
          Distribution dist = gen.getDistribution(i);
          if(dist instanceof NormalDistribution) {
            NormalDistribution d = (NormalDistribution) dist;
            double delta = (tv[i] - d.getMean()) / d.getStddev();
            lensq += delta * delta;
            norm += 1;
          }
          else {
            throw new AbortException("TrivialGeneratedOutlier currently only supports normal distributions, got: " + dist);
          }
        }
        if(norm > 0.) {
          // The squared distances are ChiSquared distributed
          score = Math.min(score, ChiSquaredDistribution.cdf(lensq, norm));
        }
        else {
          score = 0.;
        }
      }
      if(expect < 1) {
        score = expect * score / (1 - score + expect);
      }
      scores.putDouble(iditer, score);
    }
    DoubleRelation scoreres = new MaterializedDoubleRelation("Model outlier scores", "model-outlier", scores, models.getDBIDs());
    OutlierScoreMeta meta = new ProbabilisticOutlierScore(0., 1.);
    return new OutlierResult(meta, scoreres);
  }