Search in sources :

Example 51 with MeanVariance

use of de.lmu.ifi.dbs.elki.math.MeanVariance 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 52 with MeanVariance

use of de.lmu.ifi.dbs.elki.math.MeanVariance in project elki by elki-project.

the class OutlierLinearScaling method prepare.

@Override
public <A> void prepare(A array, NumberArrayAdapter<?, A> adapter) {
    if (usemean) {
        MeanVariance mv = new MeanVariance();
        DoubleMinMax mm = (max == null) ? new DoubleMinMax() : null;
        boolean skippedzeros = false;
        final int size = adapter.size(array);
        for (int i = 0; i < size; i++) {
            double val = adapter.getDouble(array, i);
            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();
            final int size = adapter.size(array);
            for (int i = 0; i < size; i++) {
                double val = adapter.getDouble(array, i);
                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)

Example 53 with MeanVariance

use of de.lmu.ifi.dbs.elki.math.MeanVariance 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)

Example 54 with MeanVariance

use of de.lmu.ifi.dbs.elki.math.MeanVariance in project elki by elki-project.

the class StandardDeviationScaling method prepare.

@Override
public <A> void prepare(A array, NumberArrayAdapter<?, A> adapter) {
    if (fixedmean == null) {
        MeanVariance mv = new MeanVariance();
        final int size = adapter.size(array);
        for (int i = 0; i < size; i++) {
            double val = adapter.getDouble(array, i);
            if (!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();
        final int size = adapter.size(array);
        for (int i = 0; i < size; i++) {
            double val = adapter.getDouble(array, i);
            if (!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)

Example 55 with MeanVariance

use of de.lmu.ifi.dbs.elki.math.MeanVariance in project elki by elki-project.

the class MinusLogStandardDeviationScaling 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 = -FastMath.log(scores.doubleValue(id));
            if (!Double.isNaN(val) && !Double.isInfinite(val)) {
                mv.put(val);
            }
        }
        mean = mv.getMean();
        factor = lambda * mv.getSampleStddev() * MathUtil.SQRT2;
    } else {
        mean = fixedmean;
        Mean sqsum = new Mean();
        DoubleRelation scores = or.getScores();
        for (DBIDIter id = scores.iterDBIDs(); id.valid(); id.advance()) {
            double val = -FastMath.log(scores.doubleValue(id));
            if (!Double.isNaN(val) && !Double.isInfinite(val)) {
                sqsum.put((val - mean) * (val - mean));
            }
        }
        factor = lambda * FastMath.sqrt(sqsum.getMean()) * MathUtil.SQRT2;
    }
}
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

MeanVariance (de.lmu.ifi.dbs.elki.math.MeanVariance)61 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)32 DoubleRelation (de.lmu.ifi.dbs.elki.database.relation.DoubleRelation)17 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)17 DoubleMinMax (de.lmu.ifi.dbs.elki.math.DoubleMinMax)15 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)13 WritableDoubleDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore)9 KNNList (de.lmu.ifi.dbs.elki.database.ids.KNNList)9 MaterializedDoubleRelation (de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation)9 OutlierResult (de.lmu.ifi.dbs.elki.result.outlier.OutlierResult)9 OutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.OutlierScoreMeta)9 MultipleObjectsBundle (de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle)8 DoubleStatistic (de.lmu.ifi.dbs.elki.logging.statistics.DoubleStatistic)8 DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)7 Mean (de.lmu.ifi.dbs.elki.math.Mean)7 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)6 DoubleDBIDListIter (de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter)6 ArrayDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs)5 DBIDArrayIter (de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter)5 AbstractDataSourceTest (de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest)5