use of de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox 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.data.ModifiableHyperBoundingBox in project elki by elki-project.
the class VisualizeGeodesicDistances method run.
@Override
public void run() {
// Format: Latitude, Longitude
// München:
DoubleVector stap = DoubleVector.wrap(new double[] { 48.133333, 11.566667 });
// New York:
DoubleVector endp = DoubleVector.wrap(new double[] { 40.712778, -74.005833 });
// Bavaria:
ModifiableHyperBoundingBox bb = new ModifiableHyperBoundingBox(new double[] { 47.27011150, 8.97634970 }, new double[] { 50.56471420, 13.83963710 });
// Bavaria slice on lat
// bb = new ModifiableHyperBoundingBox(new double[] { 47.27011150, -80 }, //
// new double[] { 50.56471420, 80 });
// Bavaria slice on lon
// bb = new ModifiableHyperBoundingBox(new double[] { -10, 8.97634970 }, //
// new double[] { 50, 13.83963710 });
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
final double max = model.getEquatorialRadius() * Math.PI;
// Red: left off-course, green: right off-course
int red = 0xffff0000;
int green = 0xff00ff00;
FiniteProgress prog = LOG.isVerbose() ? new FiniteProgress("columns", width, LOG) : null;
for (int x = 0; x < width; x++) {
final double lon = x * 360. / width - 180.;
for (int y = 0; y < height; y++) {
final double lat = y * -180. / height + 90.;
switch(mode) {
case ATD:
{
final double atd = model.getEquatorialRadius() * SphereUtil.alongTrackDistanceDeg(stap.doubleValue(0), stap.doubleValue(1), endp.doubleValue(0), endp.doubleValue(1), lat, lon);
if (atd < 0) {
img.setRGB(x, y, colorMultiply(red, -atd / max, false));
} else {
img.setRGB(x, y, colorMultiply(green, atd / max, false));
}
break;
}
case XTD:
{
final double ctd = model.getEquatorialRadius() * SphereUtil.crossTrackDistanceDeg(stap.doubleValue(0), stap.doubleValue(1), endp.doubleValue(0), endp.doubleValue(1), lat, lon);
if (ctd < 0) {
img.setRGB(x, y, colorMultiply(red, -ctd / max, false));
} else {
img.setRGB(x, y, colorMultiply(green, ctd / max, false));
}
break;
}
case MINDIST:
{
final double dist = model.minDistDeg(lat, lon, bb.getMin(0), bb.getMin(1), bb.getMax(0), bb.getMax(1));
if (dist < 0) {
img.setRGB(x, y, colorMultiply(red, -dist / max, true));
} else {
img.setRGB(x, y, colorMultiply(green, dist / max, true));
}
break;
}
}
}
LOG.incrementProcessed(prog);
}
LOG.ensureCompleted(prog);
try {
ImageIO.write(img, "png", out);
} catch (IOException e) {
LOG.exception(e);
}
}
use of de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox 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);
}
}
}
use of de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox in project elki by elki-project.
the class XSplitter method mbr.
/**
* Computes and returns the mbr of the specified nodes, only the nodes between
* from and to index are considered.
*
* @param entries the array of node indices in {@link #entries}
* @param from the start index
* @param to the end index
* @return the mbr of the specified nodes
*/
private HyperBoundingBox mbr(final int[] entries, final int from, final int to) {
SpatialEntry first = this.node.getEntry(entries[from]);
ModifiableHyperBoundingBox mbr = new ModifiableHyperBoundingBox(first);
for (int i = from + 1; i < to; i++) {
mbr.extend(this.node.getEntry(entries[i]));
}
return mbr;
}
use of de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox in project elki by elki-project.
the class XSplitter method getRatioOfDataInIntersectionVolume.
/**
* Get the ratio of data objects in the intersection volume (weighted
* overlap).
*
* @param split two entry lists representing the given split
* @param mbrs the MBRs for the given split
* @return the ration of data objects in the intersection volume as value
* between 0 and 1
*/
public double getRatioOfDataInIntersectionVolume(List<SpatialEntry>[] split, HyperBoundingBox[] mbrs) {
final ModifiableHyperBoundingBox xMBR = SpatialUtil.intersection(mbrs[0], mbrs[1]);
if (xMBR == null) {
return 0.;
}
// Total number of entries, intersecting entries
int[] numOf = { 0, 0 };
countXingDataEntries(split[0], xMBR, numOf);
countXingDataEntries(split[1], xMBR, numOf);
return numOf[1] / (double) numOf[0];
}
Aggregations