Search in sources :

Example 1 with AbstractVectorIter

use of de.lmu.ifi.dbs.elki.evaluation.scores.adapter.AbstractVectorIter in project elki by elki-project.

the class EvaluatePrecomputedOutlierScores method processRow.

private void processRow(PrintStream fout, NumberVector vec, String label) {
    if (checkForNaNs(vec)) {
        LOG.warning("NaN value encountered in vector " + label);
        return;
    }
    if (positive == null) {
        if (!label.matches("bylabel")) {
            throw new AbortException("No 'by label' reference outlier found, which is needed for evaluation!");
        }
        positive = new VectorNonZero(vec);
        endcg = NDCGEvaluation.STATIC.expected(positive.numPositive(), positive.getDimensionality());
        return;
    }
    AbstractVectorIter iter = reverse.matcher(label).find() ? new IncreasingVectorIter(vec) : new DecreasingVectorIter(vec);
    double rate = positive.numPositive() / (double) positive.getDimensionality();
    double auc = ROCEvaluation.STATIC.evaluate(positive, iter.seek(0));
    double avep = AveragePrecisionEvaluation.STATIC.evaluate(positive, iter.seek(0));
    double rprecision = PrecisionAtKEvaluation.RPRECISION.evaluate(positive, iter.seek(0));
    double maxf1 = MaximumF1Evaluation.STATIC.evaluate(positive, iter.seek(0));
    double dcg = DCGEvaluation.STATIC.evaluate(positive, iter.seek(0));
    double ndcg = NDCGEvaluation.STATIC.evaluate(positive, iter.seek(0));
    double adjauc = 2 * auc - 1;
    double adjrprecision = (rprecision - rate) / (1 - rate);
    double adjavep = (avep - rate) / (1 - rate);
    double adjmaxf1 = (maxf1 - rate) / (1 - rate);
    double adjdcg = (ndcg - endcg) / (1 - endcg);
    final int p = label.lastIndexOf('-');
    String prefix = label.substring(0, p);
    int k = Integer.valueOf(label.substring(p + 1));
    // Write CSV
    if (name != null) {
        fout.append('"').append(name).append("\",");
    }
    fout.append('"').append(prefix).append('"');
    fout.append(',').append(Integer.toString(k));
    fout.append(',').append(Double.toString(auc));
    fout.append(',').append(Double.toString(avep));
    fout.append(',').append(Double.toString(rprecision));
    fout.append(',').append(Double.toString(maxf1));
    fout.append(',').append(Double.toString(dcg));
    fout.append(',').append(Double.toString(ndcg));
    fout.append(',').append(Double.toString(adjauc));
    fout.append(',').append(Double.toString(adjavep));
    fout.append(',').append(Double.toString(adjrprecision));
    fout.append(',').append(Double.toString(adjmaxf1));
    fout.append(',').append(Double.toString(adjdcg));
    fout.append('\n');
}
Also used : IncreasingVectorIter(de.lmu.ifi.dbs.elki.evaluation.scores.adapter.IncreasingVectorIter) DecreasingVectorIter(de.lmu.ifi.dbs.elki.evaluation.scores.adapter.DecreasingVectorIter) AbstractVectorIter(de.lmu.ifi.dbs.elki.evaluation.scores.adapter.AbstractVectorIter) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException) VectorNonZero(de.lmu.ifi.dbs.elki.evaluation.scores.adapter.VectorNonZero)

Aggregations

AbstractVectorIter (de.lmu.ifi.dbs.elki.evaluation.scores.adapter.AbstractVectorIter)1 DecreasingVectorIter (de.lmu.ifi.dbs.elki.evaluation.scores.adapter.DecreasingVectorIter)1 IncreasingVectorIter (de.lmu.ifi.dbs.elki.evaluation.scores.adapter.IncreasingVectorIter)1 VectorNonZero (de.lmu.ifi.dbs.elki.evaluation.scores.adapter.VectorNonZero)1 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)1