Search in sources :

Example 81 with DoubleRelation

use of de.lmu.ifi.dbs.elki.database.relation.DoubleRelation in project elki by elki-project.

the class MinusLogGammaScaling method prepare.

@Override
public void prepare(OutlierResult or) {
    meta = or.getOutlierMeta();
    // Determine Minimum and Maximum.
    DoubleMinMax mm = new DoubleMinMax();
    DoubleRelation scores = or.getScores();
    for (DBIDIter id = scores.iterDBIDs(); id.valid(); id.advance()) {
        double score = scores.doubleValue(id);
        if (!Double.isNaN(score) && !Double.isInfinite(score)) {
            mm.put(score);
        }
    }
    max = mm.getMax();
    mlogmax = -FastMath.log(mm.getMin() / max);
    // with the prescaling, do Gamma Scaling.
    MeanVariance mv = new MeanVariance();
    for (DBIDIter id = scores.iterDBIDs(); id.valid(); id.advance()) {
        double score = scores.doubleValue(id);
        score = preScale(score);
        if (!Double.isNaN(score) && !Double.isInfinite(score)) {
            mv.put(score);
        }
    }
    final double mean = mv.getMean();
    final double var = mv.getSampleVariance();
    k = (mean * mean) / var;
    theta = var / mean;
    atmean = GammaDistribution.regularizedGammaP(k, mean / theta);
// logger.warning("Mean:"+mean+" Var:"+var+" Theta: "+theta+" k: "+k+"
// valatmean"+atmean);
}
Also used : MeanVariance(de.lmu.ifi.dbs.elki.math.MeanVariance) DoubleMinMax(de.lmu.ifi.dbs.elki.math.DoubleMinMax) DoubleRelation(de.lmu.ifi.dbs.elki.database.relation.DoubleRelation) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 82 with DoubleRelation

use of de.lmu.ifi.dbs.elki.database.relation.DoubleRelation in project elki by elki-project.

the class MultiplicativeInverseScaling method prepare.

@Override
public void prepare(OutlierResult or) {
    double max = Double.MIN_VALUE;
    DoubleRelation scores = or.getScores();
    for (DBIDIter id = scores.iterDBIDs(); id.valid(); id.advance()) {
        double val = scores.doubleValue(id);
        double inv = Math.abs(1.0 / val);
        if (!Double.isInfinite(inv) && !Double.isNaN(inv)) {
            max = Math.max(max, inv);
        }
    }
    scaleval = max;
}
Also used : DoubleRelation(de.lmu.ifi.dbs.elki.database.relation.DoubleRelation) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 83 with DoubleRelation

use of de.lmu.ifi.dbs.elki.database.relation.DoubleRelation in project elki by elki-project.

the class OutlierLinearScaling method prepare.

@Override
public void prepare(OutlierResult or) {
    if (usemean) {
        MeanVariance mv = new MeanVariance();
        DoubleMinMax mm = (max == null) ? new DoubleMinMax() : null;
        boolean skippedzeros = false;
        DoubleRelation scores = or.getScores();
        for (DBIDIter id = scores.iterDBIDs(); id.valid(); id.advance()) {
            double val = scores.doubleValue(id);
            if (nozeros && val == 0.0) {
                skippedzeros = true;
                continue;
            }
            if (!Double.isNaN(val) && !Double.isInfinite(val)) {
                mv.put(val);
            }
            if (max == null) {
                mm.put(val);
            }
        }
        if (skippedzeros && mm.getMin() == mm.getMax()) {
            mm.put(0.0);
            mv.put(0.0);
        }
        min = mv.getMean();
        if (max == null) {
            max = mm.getMax();
        }
    } else {
        if (min == null || max == null) {
            boolean skippedzeros = false;
            DoubleMinMax mm = new DoubleMinMax();
            DoubleRelation scores = or.getScores();
            for (DBIDIter id = scores.iterDBIDs(); id.valid(); id.advance()) {
                double val = scores.doubleValue(id);
                if (nozeros && val == 0.0) {
                    skippedzeros = true;
                    continue;
                }
                mm.put(val);
            }
            if (skippedzeros && mm.getMin() == mm.getMax()) {
                mm.put(0.0);
            }
            if (min == null) {
                min = mm.getMin();
            }
            if (max == null) {
                max = mm.getMax();
            }
        }
    }
    factor = (max - min);
}
Also used : MeanVariance(de.lmu.ifi.dbs.elki.math.MeanVariance) DoubleMinMax(de.lmu.ifi.dbs.elki.math.DoubleMinMax) DoubleRelation(de.lmu.ifi.dbs.elki.database.relation.DoubleRelation) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 84 with DoubleRelation

use of de.lmu.ifi.dbs.elki.database.relation.DoubleRelation in project elki by elki-project.

the class RankingPseudoOutlierScaling method prepare.

@Override
public void prepare(OutlierResult or) {
    // collect all outlier scores
    DoubleRelation oscores = or.getScores();
    scores = new double[oscores.size()];
    int pos = 0;
    if (or.getOutlierMeta() instanceof InvertedOutlierScoreMeta) {
        inverted = true;
    }
    for (DBIDIter iditer = oscores.iterDBIDs(); iditer.valid(); iditer.advance()) {
        scores[pos] = oscores.doubleValue(iditer);
        pos++;
    }
    if (pos != oscores.size()) {
        throw new AbortException("Database size is incorrect!");
    }
    // sort them
    Arrays.sort(scores);
}
Also used : InvertedOutlierScoreMeta(de.lmu.ifi.dbs.elki.result.outlier.InvertedOutlierScoreMeta) DoubleRelation(de.lmu.ifi.dbs.elki.database.relation.DoubleRelation) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)

Example 85 with DoubleRelation

use of de.lmu.ifi.dbs.elki.database.relation.DoubleRelation in project elki by elki-project.

the class StandardDeviationScaling method prepare.

@Override
public void prepare(OutlierResult or) {
    if (fixedmean == null) {
        MeanVariance mv = new MeanVariance();
        DoubleRelation scores = or.getScores();
        for (DBIDIter id = scores.iterDBIDs(); id.valid(); id.advance()) {
            double val = scores.doubleValue(id);
            if (!Double.isNaN(val) && !Double.isInfinite(val)) {
                mv.put(val);
            }
        }
        mean = mv.getMean();
        factor = lambda * mv.getSampleStddev() * MathUtil.SQRT2;
        if (factor == 0.0) {
            factor = Double.MIN_NORMAL;
        }
    } else {
        mean = fixedmean;
        Mean sqsum = new Mean();
        DoubleRelation scores = or.getScores();
        for (DBIDIter id = scores.iterDBIDs(); id.valid(); id.advance()) {
            double val = scores.doubleValue(id);
            if (!Double.isNaN(val) && !Double.isInfinite(val)) {
                sqsum.put((val - mean) * (val - mean));
            }
        }
        factor = lambda * FastMath.sqrt(sqsum.getMean()) * MathUtil.SQRT2;
        if (factor == 0.0) {
            factor = Double.MIN_NORMAL;
        }
    }
}
Also used : Mean(de.lmu.ifi.dbs.elki.math.Mean) MeanVariance(de.lmu.ifi.dbs.elki.math.MeanVariance) DoubleRelation(de.lmu.ifi.dbs.elki.database.relation.DoubleRelation) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Aggregations

DoubleRelation (de.lmu.ifi.dbs.elki.database.relation.DoubleRelation)89 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)72 MaterializedDoubleRelation (de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation)70 OutlierResult (de.lmu.ifi.dbs.elki.result.outlier.OutlierResult)70 OutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.OutlierScoreMeta)70 WritableDoubleDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore)69 DoubleMinMax (de.lmu.ifi.dbs.elki.math.DoubleMinMax)65 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)38 BasicOutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.BasicOutlierScoreMeta)34 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)21 KNNList (de.lmu.ifi.dbs.elki.database.ids.KNNList)18 MeanVariance (de.lmu.ifi.dbs.elki.math.MeanVariance)17 InvertedOutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.InvertedOutlierScoreMeta)14 ProbabilisticOutlierScore (de.lmu.ifi.dbs.elki.result.outlier.ProbabilisticOutlierScore)13 QuotientOutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.QuotientOutlierScoreMeta)13 DoubleDBIDListIter (de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter)11 StepProgress (de.lmu.ifi.dbs.elki.logging.progress.StepProgress)11 NeighborSetPredicate (de.lmu.ifi.dbs.elki.algorithm.outlier.spatial.neighborhood.NeighborSetPredicate)9 ArrayDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs)8 Mean (de.lmu.ifi.dbs.elki.math.Mean)8