use of de.lmu.ifi.dbs.elki.data.NumberVector in project elki by elki-project.
the class EuclideanDistanceFunction method minDist.
@Override
public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
final int dim1 = mbr1.getDimensionality(), dim2 = mbr2.getDimensionality();
final int mindim = (dim1 < dim2) ? dim1 : dim2;
final NumberVector v1 = (mbr1 instanceof NumberVector) ? (NumberVector) mbr1 : null;
final NumberVector v2 = (mbr2 instanceof NumberVector) ? (NumberVector) mbr2 : null;
double agg = //
(v1 != null) ? //
(v2 != null) ? preDistance(v1, v2, 0, mindim) : preDistanceVM(v1, mbr2, 0, mindim) : (v2 != null) ? preDistanceVM(v2, mbr1, 0, mindim) : preDistanceMBR(mbr1, mbr2, 0, mindim);
// first object has more dimensions.
if (dim1 > mindim) {
agg += (v1 != null) ? preNorm(v1, mindim, dim1) : preNormMBR(mbr1, mindim, dim1);
}
// second object has more dimensions.
if (dim2 > mindim) {
agg += (v2 != null) ? preNorm(v2, mindim, dim2) : preNormMBR(mbr2, mindim, dim2);
}
return FastMath.sqrt(agg);
}
use of de.lmu.ifi.dbs.elki.data.NumberVector in project elki by elki-project.
the class LPNormDistanceFunction method minDist.
@Override
public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
final int dim1 = mbr1.getDimensionality(), dim2 = mbr2.getDimensionality();
final int mindim = (dim1 < dim2) ? dim1 : dim2;
final NumberVector v1 = (mbr1 instanceof NumberVector) ? (NumberVector) mbr1 : null;
final NumberVector v2 = (mbr2 instanceof NumberVector) ? (NumberVector) mbr2 : null;
double agg = //
(v1 != null) ? //
(v2 != null) ? preDistance(v1, v2, 0, mindim) : preDistanceVM(v1, mbr2, 0, mindim) : (v2 != null) ? preDistanceVM(v2, mbr1, 0, mindim) : preDistanceMBR(mbr1, mbr2, 0, mindim);
// first object has more dimensions.
if (dim1 > mindim) {
agg += (v1 != null) ? preNorm(v1, mindim, dim1) : preNormMBR(mbr1, mindim, dim1);
}
// second object has more dimensions.
if (dim2 > mindim) {
agg += (v2 != null) ? preNorm(v2, mindim, dim2) : preNormMBR(mbr2, mindim, dim2);
}
return FastMath.pow(agg, invp);
}
use of de.lmu.ifi.dbs.elki.data.NumberVector in project elki by elki-project.
the class WeightedLPNormDistanceFunction method minDist.
@Override
public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
final int dim1 = mbr1.getDimensionality(), dim2 = mbr2.getDimensionality();
final int mindim = (dim1 < dim2) ? dim1 : dim2;
final NumberVector v1 = (mbr1 instanceof NumberVector) ? (NumberVector) mbr1 : null;
final NumberVector v2 = (mbr2 instanceof NumberVector) ? (NumberVector) mbr2 : null;
double agg = //
(v1 != null) ? //
(v2 != null) ? preDistance(v1, v2, 0, mindim) : preDistanceVM(v1, mbr2, 0, mindim) : (v2 != null) ? preDistanceVM(v2, mbr1, 0, mindim) : preDistanceMBR(mbr1, mbr2, 0, mindim);
// first object has more dimensions.
if (dim1 > mindim) {
agg += (v1 != null) ? preNorm(v1, mindim, dim1) : preNormMBR(mbr1, mindim, dim1);
}
// second object has more dimensions.
if (dim2 > mindim) {
agg += (v2 != null) ? preNorm(v2, mindim, dim2) : preNormMBR(mbr2, mindim, dim2);
}
return FastMath.pow(agg, invp);
}
use of de.lmu.ifi.dbs.elki.data.NumberVector in project elki by elki-project.
the class WeightedMaximumDistanceFunction method minDist.
@Override
public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
final int dim1 = mbr1.getDimensionality(), dim2 = mbr2.getDimensionality();
final int mindim = (dim1 < dim2) ? dim1 : dim2;
final NumberVector v1 = (mbr1 instanceof NumberVector) ? (NumberVector) mbr1 : null;
final NumberVector v2 = (mbr2 instanceof NumberVector) ? (NumberVector) mbr2 : null;
double agg = //
(v1 != null) ? //
(v2 != null) ? preDistance(v1, v2, 0, mindim) : preDistanceVM(v1, mbr2, 0, mindim) : (v2 != null) ? preDistanceVM(v2, mbr1, 0, mindim) : preDistanceMBR(mbr1, mbr2, 0, mindim);
// first object has more dimensions.
if (dim1 > mindim) {
double b = (v1 != null) ? preNorm(v1, mindim, dim1) : preNormMBR(mbr1, mindim, dim1);
agg = agg >= b ? agg : b;
}
// second object has more dimensions.
if (dim2 > mindim) {
double b = (v2 != null) ? preNorm(v2, mindim, dim2) : preNormMBR(mbr2, mindim, dim2);
agg = agg >= b ? agg : b;
}
return agg;
}
use of de.lmu.ifi.dbs.elki.data.NumberVector in project elki by elki-project.
the class TriangularDiscriminationDistanceFunctionTest method testTriganular.
@Test
public void testTriganular() {
DoubleVector v0 = DoubleVector.wrap(new double[] { 0.8, 0.1, 0.1 });
DoubleVector v1 = DoubleVector.wrap(new double[] { 0.1, 0.8, 0.1 });
DoubleVector v2 = DoubleVector.wrap(new double[] { 0.1, 0.1, 0.8 });
DoubleVector v3 = DoubleVector.wrap(new double[] { 1. / 3, 1. / 3, 1. / 3 });
DoubleVector v4 = DoubleVector.wrap(new double[] { 0.6, 0.2, 0.2 });
DoubleVector[] vecs = { v0, v1, v2, v3, v4 };
// Manual computation of correct distances:
double d10 = .49 / .9 + .49 / .9 + 0.;
double d30 = //
(.8 - 1. / 3) * (.8 - 1. / 3) / (.8 + 1. / 3) + 2 * (.1 - 1. / 3) * (.1 - 1. / 3) / (.1 + 1. / 3);
double d40 = .04 / 1.4 + .01 / .3 + .01 / .3;
double d41 = .25 / 0.7 + .36 / 1. + .01 / .3;
double d43 = //
(.6 - 1. / 3) * (.6 - 1. / 3) / (.6 + 1. / 3) + 2 * (.2 - 1. / 3) * (.2 - 1. / 3) / (.2 + 1. / 3);
double[][] distances = { //
{ 0., d10, d10, d30, d40 }, //
{ d10, 0., d10, d30, d41 }, //
{ d10, d10, 0., d30, d41 }, //
{ d30, d30, d30, 0., d43 }, //
{ d40, d41, d41, d43, 0. } };
PrimitiveDistanceFunction<NumberVector> df = TriangularDiscriminationDistanceFunction.STATIC;
for (int i = 0; i < vecs.length; i++) {
for (int j = 0; j < vecs.length; j++) {
assertEquals("Distance " + i + "," + j + " incorrect.", distances[i][j], df.distance(vecs[i], vecs[j]), 1e-15);
}
}
}
Aggregations