Macro-average AUC for all outcomes
@return the (macro-)average AUC for all outcomes.
979734
public double calculateAverageAuc() {
        double ret = 0.0;
        for (int i = 0; i < numLabels(); i++) {
            ret += calculateAUC(i);
        }

        return ret / (double) numLabels();
    }
420891
def _score_micro_average(self, y, y_pred, classes, n_classes):
        
        # Convert y to binarized array for micro and macro scores
        y = label_binarize(y, classes=classes)
        if n_classes == 2:
            y = np.hstack((1-y, y))

        # Compute micro-average
        self.fpr[MICRO], self.tpr[MICRO], _ = roc_curve(y.ravel(), y_pred.ravel())
        self.roc_auc[MICRO] = auc(self.fpr[MICRO], self.tpr[MICRO])
801358
@Override
    public double calculateAnomalyScore(double value) {
        double zScore = (value - mean) / Math.sqrt(variance);
        //Taking absolute value for a more human-readable anomaly score
        return Math.abs(zScore);
    }
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();
    }
  }
482926
def result_report_overall(self):
        

        results = self.results_overall_metrics()

        output = self.ui.section_header('Overall metrics (micro-average)', indent=2) + '\n'

        if results['f_measure']:
            output += self.ui.line('F-measure', indent=2) + '\n'
            output += self.ui.data(field='F-measure (F1)', value=float(results['f_measure']['f_measure']) * 100,
                                   unit='%', indent=4) + '\n'
            output += self.ui.data(field='Precision', value=float(results['f_measure']['precision']) * 100,
                                   unit='%', indent=4) + '\n'
            output += self.ui.data(field='Recall', value=float(results['f_measure']['recall']) * 100,
                                   unit='%', indent=4) + '\n'

        if results['error_rate']:
            output += self.ui.line('Error rate', indent=2) + '\n'
            output += self.ui.data(field='Error rate (ER)', value=float(results['error_rate']['error_rate']),
                                   indent=4) + '\n'
            output += self.ui.data(field='Substitution rate', value=float(results['error_rate']['substitution_rate']),
                                   indent=4) + '\n'
            output += self.ui.data(field='Deletion rate', value=float(results['error_rate']['deletion_rate']),
                                   indent=4) + '\n'
            output += self.ui.data(field='Insertion rate', value=float(results['error_rate']['insertion_rate']),
                                   indent=4) + '\n'

        if results['accuracy']:
            output += self.ui.line('Accuracy', indent=2) + '\n'
            output += self.ui.data(field='Sensitivity', value=float(results['accuracy']['sensitivity']*100),
                                   unit='%', indent=4) + '\n'
            output += self.ui.data(field='Specificity', value=float(results['accuracy']['specificity'] * 100),
                                   unit='%', indent=4) + '\n'
            output += self.ui.data(field='Balanced accuracy', value=float(results['accuracy']['balanced_accuracy'] * 100),
                                   unit='%', indent=4) + '\n'
            output += self.ui.data(field='Accuracy', value=float(results['accuracy']['accuracy'] * 100),
                                   unit='%', indent=4) + '\n'

        return output
346493
public double getCumulativeElapsedTimeAllGlobal() {
	  final long[] accumulatedTimesHolder = new long[NUM_EVENTS];
	  globalAcc.consultAccumulatedTimes(accumulatedTimesHolder);

      double sum = 0;
      for (int i = 1; i <= ProfilingEvent.EXECUTED.ordinal(); ++i) {
         sum += accumulatedTimesHolder[i];
      }
      return sum;
   }
452634
@JmxAttribute(optional = true)
	public double getSmoothedStandardDeviation() {
		if (totalCount == 0) {
			return 0.0;
		}

		double avg = smoothedSum / smoothedCount;
		double variance = smoothedSqr / smoothedCount - avg * avg;
		if (variance < 0.0)
			variance = 0.0;
		return sqrt(variance);
	}
829931
public double computeAccuracy() {
		double totalCorrect = 0;
		double totalIncorrect = 0;

		for (int i = 0; i < actualCounts.length; i++) {
			for (int j = 0; j < actualCounts.length; j++) {
				if( i == j ) {
					totalCorrect += matrix.get(i,j);
				} else {
					totalIncorrect += matrix.get(i,j);
				}
			}
		}

		return totalCorrect/(totalCorrect+totalIncorrect);
	}
1180214
public UNode toDoc() {
        // Root "results" node.
        UNode resultsNode = UNode.createMapNode("results");
        
        // "aggregate" node.
        UNode aggNode = resultsNode.addMapNode("aggregate");
        aggNode.addValueNode("metric", m_metricParam, true);
        if (m_queryParam != null){
            aggNode.addValueNode("query", m_queryParam, true);
        }
        if (m_groupingParam != null) {
            aggNode.addValueNode("group", m_groupingParam, true);
        }
        
        // Add "totalobjects" if used.
        if (m_totalObjects >= 0) {
            resultsNode.addValueNode("totalobjects", Long.toString(m_totalObjects));
        }
        
        // Add global or summary value if present.
        if (m_globalValue != null) {
            if (m_groupSetList == null) {
                resultsNode.addChildNode(UNode.createValueNode("value", m_globalValue));
            } else {
                resultsNode.addChildNode(UNode.createValueNode("summary", m_globalValue));
            }
        }

        // If needed, the "groupsets" node becomes the new parent. 
        UNode parentNode = resultsNode;
        boolean bGroupSetsNode = false;
        if (m_groupSetList != null && m_groupSetList.size() > 1) {
            bGroupSetsNode = true;
            UNode groupSetsNode = parentNode.addArrayNode("groupsets");
            parentNode = groupSetsNode;
        }

        // Add groupsets, if any, to the parent node.
        if (m_groupSetList != null) {
            for (AggGroupSet groupSet : m_groupSetList) {
                groupSet.addDoc(parentNode, bGroupSetsNode);
            }
        }
        return resultsNode;
    }
166299
def auc(truth, recommend):
    
    tp = correct = 0.
    for r in recommend:
        if r in truth:
            # keep track number of true positives placed before
            tp += 1.
        else:
            correct += tp
    # number of all possible tp-fp pairs
    pairs = tp * (recommend.size - tp)

    # if there is no TP (or no FP), it's meaningless for this metric (i.e., AUC=0.5)
    if pairs == 0:
        return 0.5

    return correct / pairs
684141
public double calculateAverageAUCPR() {
        double sum = 0.0;
        for (int i = 0; i < underlying.length; i++) {
            sum += calculateAUCPR(i);
        }

        return sum / underlying.length;
    }
815689
public double getMean() {
        if (getTotalCount() == 0) {
            return 0.0;
        }
        recordedValuesIterator.reset();
        double totalValue = 0;
        while (recordedValuesIterator.hasNext()) {
            HistogramIterationValue iterationValue = recordedValuesIterator.next();
            totalValue += medianEquivalentValue(iterationValue.getValueIteratedTo())
                    * iterationValue.getCountAtValueIteratedTo();
        }
        return (totalValue * 1.0) / getTotalCount();
    }
45937
@Override
	public double calculateExpectedAgreement() {
		Map<Object, int[]> annotationsPerCategory
				= CodingAnnotationStudy.countAnnotationsPerCategory(study);

		BigDecimal result = BigDecimal.ZERO;
		for (Object category : study.getCategories()) {
			int[] annotations = annotationsPerCategory.get(category);
			if (annotations != null) {
				BigDecimal prod = BigDecimal.ONE;
				for (int rater = 0; rater < study.getRaterCount(); rater++)
					prod = prod.multiply(new BigDecimal(annotations[rater]));
				result = result.add(prod);
			}
		}
		result = result.divide(new BigDecimal(study.getItemCount()).pow(2), MathContext.DECIMAL128);
		return result.doubleValue();
	}
836299
public Double averagePrecision() 
    {
        double n = 0;
        double sumPrecision = 0;
        for (int i=0; i<pairs.length; i++) {
            if (correctPair(i)) {
                n++;
                double precisionAtRankI = n/(i+1.0);
                sumPrecision += precisionAtRankI;
            }
        }
        return new Double(sumPrecision / numCorrectPairs);
    }
863206
public double optimalCwa() {
    double acc = 0;
    for (int recall = 1; recall <= numSamples(); recall++) {
      acc += precision(recall) / (double) recall;
    }
    return acc / numSamples();
  }
693425
def result(self):
        
        # TODO: how about xcurrent?
        return self.best.get() + (
            self.countevals, self.countiter, self.gp.pheno(self.mean),
            self.gp.scales * self.sigma * self.sigma_vec * self.dC**0.5)
573270
public double errorSum() {
        if (isLeaf()) {
            return 0.0;
        } else if (isPreTerminal()) {
            return error();
        } else {
            double error = 0.0;
            for (Tree child : children()) {
                error += child.errorSum();
            }
            return error() + error;
        }
    }