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);
}
}
}
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);
}
}
}
Aggregations