Search in sources :

Example 1 with LPNormDistanceFunction

use of de.lmu.ifi.dbs.elki.distance.distancefunction.minkowski.LPNormDistanceFunction in project elki by elki-project.

the class SpatialPrimitiveDistanceFunctionTest method testSpatialDistanceConsistency.

@Test
public void testSpatialDistanceConsistency() {
    final Random rnd = new Random(0);
    final int dim = 7;
    final int iters = 10000;
    List<SpatialPrimitiveDistanceFunction<? super NumberVector>> dists = new ArrayList<>();
    dists.add(EuclideanDistanceFunction.STATIC);
    dists.add(ManhattanDistanceFunction.STATIC);
    dists.add(MaximumDistanceFunction.STATIC);
    dists.add(MinimumDistanceFunction.STATIC);
    dists.add(new LPNormDistanceFunction(3));
    dists.add(new LPNormDistanceFunction(.5));
    dists.add(CanberraDistanceFunction.STATIC);
    // Histogram intersection distance isn't proper for negative values
    // dists.add(HistogramIntersectionDistanceFunction.STATIC);
    dists.add(SquaredEuclideanDistanceFunction.STATIC);
    dists.add(ArcCosineDistanceFunction.STATIC);
    dists.add(CosineDistanceFunction.STATIC);
    double[] d1 = new double[dim];
    double[] d2 = new double[dim];
    double[] d3 = new double[dim];
    double[] d4 = new double[dim];
    DoubleVector v1 = DoubleVector.wrap(d1);
    ModifiableHyperBoundingBox mbr = new ModifiableHyperBoundingBox(d2, d3);
    DoubleVector v2 = DoubleVector.wrap(d4);
    for (int i = 0; i < iters; i++) {
        for (int d = 0; d < dim; d++) {
            d1[d] = (rnd.nextDouble() - .5) * 2E4;
            d2[d] = (rnd.nextDouble() - .5) * 2E4;
            d3[d] = (rnd.nextDouble() - .5) * 2E4;
            if (d2[d] > d3[d]) {
                double t = d2[d];
                d2[d] = d3[d];
                d3[d] = t;
            }
            double m = rnd.nextDouble();
            d4[d] = m * d2[d] + (1 - m) * d3[d];
        }
        for (SpatialPrimitiveDistanceFunction<? super NumberVector> dis : dists) {
            compareDistances(v1, mbr, v2, dis);
        }
    }
}
Also used : LPNormDistanceFunction(de.lmu.ifi.dbs.elki.distance.distancefunction.minkowski.LPNormDistanceFunction) Random(java.util.Random) NumberVector(de.lmu.ifi.dbs.elki.data.NumberVector) ArrayList(java.util.ArrayList) DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) ModifiableHyperBoundingBox(de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox) Test(org.junit.Test)

Example 2 with LPNormDistanceFunction

use of de.lmu.ifi.dbs.elki.distance.distancefunction.minkowski.LPNormDistanceFunction in project elki by elki-project.

the class SpatialPrimitiveDistanceFunctionTest method testSpatialDistanceConsistencyPositive.

@Test
public void testSpatialDistanceConsistencyPositive() {
    final Random rnd = new Random(1);
    final int dim = 7;
    final int iters = 10000;
    List<SpatialPrimitiveDistanceFunction<? super NumberVector>> dists = new ArrayList<>();
    dists.add(EuclideanDistanceFunction.STATIC);
    dists.add(ManhattanDistanceFunction.STATIC);
    dists.add(MaximumDistanceFunction.STATIC);
    dists.add(MinimumDistanceFunction.STATIC);
    dists.add(new LPNormDistanceFunction(3));
    dists.add(new LPNormDistanceFunction(.5));
    dists.add(CanberraDistanceFunction.STATIC);
    dists.add(HistogramIntersectionDistanceFunction.STATIC);
    dists.add(SquaredEuclideanDistanceFunction.STATIC);
    dists.add(ArcCosineDistanceFunction.STATIC);
    dists.add(CosineDistanceFunction.STATIC);
    double[] d1 = new double[dim];
    double[] d2 = new double[dim];
    double[] d3 = new double[dim];
    double[] d4 = new double[dim];
    DoubleVector v1 = DoubleVector.wrap(d1);
    ModifiableHyperBoundingBox mbr = new ModifiableHyperBoundingBox(d2, d3);
    DoubleVector v2 = DoubleVector.wrap(d4);
    for (int i = 0; i < iters; i++) {
        for (int d = 0; d < dim; d++) {
            d1[d] = rnd.nextDouble() * 2E4;
            d2[d] = rnd.nextDouble() * 2E4;
            d3[d] = rnd.nextDouble() * 2E4;
            if (d2[d] > d3[d]) {
                double t = d2[d];
                d2[d] = d3[d];
                d3[d] = t;
            }
            double m = rnd.nextDouble();
            d4[d] = m * d2[d] + (1 - m) * d3[d];
        }
        for (SpatialPrimitiveDistanceFunction<? super NumberVector> dis : dists) {
            compareDistances(v1, mbr, v2, dis);
        }
    }
}
Also used : LPNormDistanceFunction(de.lmu.ifi.dbs.elki.distance.distancefunction.minkowski.LPNormDistanceFunction) Random(java.util.Random) NumberVector(de.lmu.ifi.dbs.elki.data.NumberVector) ArrayList(java.util.ArrayList) DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) ModifiableHyperBoundingBox(de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox) Test(org.junit.Test)

Aggregations

DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)2 ModifiableHyperBoundingBox (de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox)2 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)2 LPNormDistanceFunction (de.lmu.ifi.dbs.elki.distance.distancefunction.minkowski.LPNormDistanceFunction)2 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 Test (org.junit.Test)2