Search in sources :

Example 6 with OutlierScalingFunction

use of de.lmu.ifi.dbs.elki.utilities.scaling.outlier.OutlierScalingFunction in project elki by elki-project.

the class JudgeOutlierScores method computeScore.

/**
 * Evaluate a single outlier score result.
 *
 * @param ids Inlier IDs
 * @param outlierIds Outlier IDs
 * @param or Outlier Result to evaluate
 * @return Outlier score result
 * @throws IllegalStateException
 */
protected ScoreResult computeScore(DBIDs ids, DBIDs outlierIds, OutlierResult or) throws IllegalStateException {
    if (scaling instanceof OutlierScalingFunction) {
        OutlierScalingFunction oscaling = (OutlierScalingFunction) scaling;
        oscaling.prepare(or);
    }
    final ScalingFunction innerScaling;
    // If we have useful (finite) min/max, use these for binning.
    double min = scaling.getMin();
    double max = scaling.getMax();
    if (Double.isInfinite(min) || Double.isNaN(min) || Double.isInfinite(max) || Double.isNaN(max)) {
        innerScaling = new IdentityScaling();
        // TODO: does the outlier score give us this guarantee?
        LOG.warning("JudgeOutlierScores expects values between 0.0 and 1.0, but we don't have such a guarantee by the scaling function: min:" + min + " max:" + max);
    } else {
        if (min == 0.0 && max == 1.0) {
            innerScaling = new IdentityScaling();
        } else {
            innerScaling = new LinearScaling(1.0 / (max - min), -min);
        }
    }
    double posscore = 0.0;
    double negscore = 0.0;
    // fill histogram with values of each object
    for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
        double result = or.getScores().doubleValue(iter);
        result = innerScaling.getScaled(scaling.getScaled(result));
        posscore += (1.0 - result);
    }
    for (DBIDIter iter = outlierIds.iter(); iter.valid(); iter.advance()) {
        double result = or.getScores().doubleValue(iter);
        result = innerScaling.getScaled(scaling.getScaled(result));
        negscore += result;
    }
    posscore /= ids.size();
    negscore /= outlierIds.size();
    LOG.verbose("Scores: " + posscore + " " + negscore);
    ArrayList<double[]> s = new ArrayList<>(1);
    s.add(new double[] { (posscore + negscore) * .5, posscore, negscore });
    return new ScoreResult(s);
}
Also used : ScalingFunction(de.lmu.ifi.dbs.elki.utilities.scaling.ScalingFunction) OutlierScalingFunction(de.lmu.ifi.dbs.elki.utilities.scaling.outlier.OutlierScalingFunction) LinearScaling(de.lmu.ifi.dbs.elki.utilities.scaling.LinearScaling) IdentityScaling(de.lmu.ifi.dbs.elki.utilities.scaling.IdentityScaling) OutlierScalingFunction(de.lmu.ifi.dbs.elki.utilities.scaling.outlier.OutlierScalingFunction) ArrayList(java.util.ArrayList) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 7 with OutlierScalingFunction

use of de.lmu.ifi.dbs.elki.utilities.scaling.outlier.OutlierScalingFunction in project elki by elki-project.

the class RescaleMetaOutlierAlgorithm method run.

@Override
public OutlierResult run(Database database) {
    Result innerresult = algorithm.run(database);
    OutlierResult or = getOutlierResult(database.getHierarchy(), innerresult);
    final DoubleRelation scores = or.getScores();
    if (scaling instanceof OutlierScalingFunction) {
        ((OutlierScalingFunction) scaling).prepare(or);
    }
    WritableDoubleDataStore scaledscores = DataStoreUtil.makeDoubleStorage(scores.getDBIDs(), DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_STATIC);
    DoubleMinMax minmax = new DoubleMinMax();
    for (DBIDIter iditer = scores.iterDBIDs(); iditer.valid(); iditer.advance()) {
        double val = scaling.getScaled(scores.doubleValue(iditer));
        scaledscores.putDouble(iditer, val);
        minmax.put(val);
    }
    OutlierScoreMeta meta = new BasicOutlierScoreMeta(minmax.getMin(), minmax.getMax(), scaling.getMin(), scaling.getMax());
    DoubleRelation scoresult = new MaterializedDoubleRelation("Scaled Outlier", "scaled-outlier", scaledscores, scores.getDBIDs());
    OutlierResult result = new OutlierResult(meta, scoresult);
    result.addChildResult(innerresult);
    return result;
}
Also used : DoubleMinMax(de.lmu.ifi.dbs.elki.math.DoubleMinMax) WritableDoubleDataStore(de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore) OutlierScalingFunction(de.lmu.ifi.dbs.elki.utilities.scaling.outlier.OutlierScalingFunction) OutlierResult(de.lmu.ifi.dbs.elki.result.outlier.OutlierResult) DoubleRelation(de.lmu.ifi.dbs.elki.database.relation.DoubleRelation) MaterializedDoubleRelation(de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation) BasicOutlierScoreMeta(de.lmu.ifi.dbs.elki.result.outlier.BasicOutlierScoreMeta) OutlierScoreMeta(de.lmu.ifi.dbs.elki.result.outlier.OutlierScoreMeta) BasicOutlierScoreMeta(de.lmu.ifi.dbs.elki.result.outlier.BasicOutlierScoreMeta) MaterializedDoubleRelation(de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation) Result(de.lmu.ifi.dbs.elki.result.Result) OutlierResult(de.lmu.ifi.dbs.elki.result.outlier.OutlierResult) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Aggregations

OutlierScalingFunction (de.lmu.ifi.dbs.elki.utilities.scaling.outlier.OutlierScalingFunction)7 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)6 DoubleRelation (de.lmu.ifi.dbs.elki.database.relation.DoubleRelation)4 OutlierResult (de.lmu.ifi.dbs.elki.result.outlier.OutlierResult)3 ArrayList (java.util.ArrayList)3 WritableDoubleDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore)2 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)2 MaterializedDoubleRelation (de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation)2 DoubleMinMax (de.lmu.ifi.dbs.elki.math.DoubleMinMax)2 BasicOutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.BasicOutlierScoreMeta)2 OutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.OutlierScoreMeta)2 Clustering (de.lmu.ifi.dbs.elki.data.Clustering)1 Model (de.lmu.ifi.dbs.elki.data.model.Model)1 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)1 HistogramResult (de.lmu.ifi.dbs.elki.result.HistogramResult)1 Result (de.lmu.ifi.dbs.elki.result.Result)1 InvertedOutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.InvertedOutlierScoreMeta)1 ObjHistogram (de.lmu.ifi.dbs.elki.utilities.datastructures.histogram.ObjHistogram)1 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)1 TokenizedReader (de.lmu.ifi.dbs.elki.utilities.io.TokenizedReader)1