Search in sources :

Example 11 with Mean

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

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

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

Example 14 with Mean

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

the class DWOF method initializeRadii.

/**
 * This method prepares a container for the radii of the objects and
 * initializes radii according to the equation:
 *
 * initialRadii of a certain object = (absoluteMinDist of all objects) *
 * (avgDist of the object) / (minAvgDist of all objects)
 *
 * @param ids Database IDs to process
 * @param distFunc Distance function
 * @param knnq kNN search function
 * @param radii WritableDoubleDataStore to store radii
 */
private void initializeRadii(DBIDs ids, KNNQuery<O> knnq, DistanceQuery<O> distFunc, WritableDoubleDataStore radii) {
    FiniteProgress avgDistProgress = LOG.isVerbose() ? new FiniteProgress("Calculating average kNN distances-", ids.size(), LOG) : null;
    double absoluteMinDist = Double.POSITIVE_INFINITY;
    double minAvgDist = Double.POSITIVE_INFINITY;
    // to get the mean for each object
    Mean mean = new Mean();
    // Iterate over all objects
    for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
        KNNList iterNeighbors = knnq.getKNNForDBID(iter, k);
        // skip the point itself
        mean.reset();
        for (DBIDIter neighbor1 = iterNeighbors.iter(); neighbor1.valid(); neighbor1.advance()) {
            if (DBIDUtil.equal(neighbor1, iter)) {
                continue;
            }
            for (DBIDIter neighbor2 = iterNeighbors.iter(); neighbor2.valid(); neighbor2.advance()) {
                if (DBIDUtil.equal(neighbor1, neighbor2) || DBIDUtil.equal(neighbor2, iter)) {
                    continue;
                }
                double distance = distFunc.distance(neighbor1, neighbor2);
                mean.put(distance);
                if (distance > 0. && distance < absoluteMinDist) {
                    absoluteMinDist = distance;
                }
            }
        }
        double currentMean = mean.getMean();
        radii.putDouble(iter, currentMean);
        if (currentMean < minAvgDist) {
            minAvgDist = currentMean;
        }
        LOG.incrementProcessed(avgDistProgress);
    }
    LOG.ensureCompleted(avgDistProgress);
    // Initializing the radii of all objects.
    for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
        radii.putDouble(iter, (minAvgDist > 0) ? (absoluteMinDist * radii.doubleValue(iter) / minAvgDist) : Double.POSITIVE_INFINITY);
    }
}
Also used : Mean(de.lmu.ifi.dbs.elki.math.Mean) KNNList(de.lmu.ifi.dbs.elki.database.ids.KNNList) FiniteProgress(de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 15 with Mean

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

the class AttributeWiseMeanNormalizationTest method defaultParameters.

/**
 * Test with default parameters.
 */
@Test
public void defaultParameters() {
    String filename = UNITTEST + "normalization-test-1.csv";
    AttributeWiseMeanNormalization<DoubleVector> filter = new ELKIBuilder<AttributeWiseMeanNormalization<DoubleVector>>(AttributeWiseMeanNormalization.class).build();
    MultipleObjectsBundle bundle = readBundle(filename, filter);
    int dim = getFieldDimensionality(bundle, 0, TypeUtil.NUMBER_VECTOR_FIELD);
    // We verify that all columns have a mean of 0:
    Mean[] ms = Mean.newArray(dim);
    for (int row = 0; row < bundle.dataLength(); row++) {
        DoubleVector d = get(bundle, row, 0, DoubleVector.class);
        for (int col = 0; col < dim; col++) {
            final double val = d.doubleValue(col);
            if (val > Double.NEGATIVE_INFINITY && val < Double.POSITIVE_INFINITY) {
                ms[col].put(val);
            }
        }
    }
    for (int col = 0; col < dim; col++) {
        assertEquals("Mean is not 1", 1., ms[col].getMean(), 1e-14);
    }
}
Also used : Mean(de.lmu.ifi.dbs.elki.math.Mean) MultipleObjectsBundle(de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle) DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) AbstractDataSourceTest(de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest) Test(org.junit.Test)

Aggregations

Mean (de.lmu.ifi.dbs.elki.math.Mean)15 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)11 DoubleRelation (de.lmu.ifi.dbs.elki.database.relation.DoubleRelation)8 MeanVariance (de.lmu.ifi.dbs.elki.math.MeanVariance)7 WritableDoubleDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore)6 MaterializedDoubleRelation (de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation)6 DoubleMinMax (de.lmu.ifi.dbs.elki.math.DoubleMinMax)6 OutlierResult (de.lmu.ifi.dbs.elki.result.outlier.OutlierResult)6 OutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.OutlierScoreMeta)6 BasicOutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.BasicOutlierScoreMeta)5 NeighborSetPredicate (de.lmu.ifi.dbs.elki.algorithm.outlier.spatial.neighborhood.NeighborSetPredicate)4 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)4 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)3 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)2 KNNList (de.lmu.ifi.dbs.elki.database.ids.KNNList)2 DoubleStatistic (de.lmu.ifi.dbs.elki.logging.statistics.DoubleStatistic)2 DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)1 DoubleDBIDListIter (de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter)1 AbstractDataSourceTest (de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest)1 MultipleObjectsBundle (de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle)1