コード例 #1
0
  @Override
  protected double minDistObject(SpatialComparable mbr, NumberVector v) {
    if (mbr.getDimensionality() != v.getDimensionality()) {
      throw new IllegalArgumentException(
          "Different dimensionality of objects\n  "
              + "first argument: "
              + mbr.toString()
              + "\n  "
              + "second argument: "
              + v.toString());
    }

    double agg = 0.;
    for (int d = BitsUtil.nextSetBit(dimensions, 0);
        d >= 0;
        d = BitsUtil.nextSetBit(dimensions, d + 1)) {
      final double value = v.doubleValue(d);
      final double omin = mbr.getMin(d);
      final double diff1 = omin - value;
      if (diff1 > 0.) {
        if (diff1 > agg) {
          agg = diff1;
        }
      } else {
        final double omax = mbr.getMax(d);
        final double diff2 = value - omax;
        if (diff2 > agg) {
          agg = diff2;
        }
      }
    }
    return agg;
  }
コード例 #2
0
ファイル: HyperBoundingBox.java プロジェクト: victordov/elki
 /**
  * Constructor, cloning an existing spatial object.
  *
  * @param other Object to clone
  */
 public HyperBoundingBox(SpatialComparable other) {
   final int dim = other.getDimensionality();
   this.min = new double[dim];
   this.max = new double[dim];
   for (int i = 0; i < dim; i++) {
     this.min[i] = other.getMin(i);
     this.max[i] = other.getMax(i);
   }
 }
コード例 #3
0
 @Override
 public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
   if (mbr1.getDimensionality() != mbr2.getDimensionality()) {
     throw new IllegalArgumentException(
         "Different dimensionality of objects\n  "
             + "first argument: "
             + mbr1.toString()
             + "\n  "
             + "second argument: "
             + mbr2.toString());
   }
   double agg = 0.;
   for (int d = BitsUtil.nextSetBit(dimensions, 0);
       d >= 0;
       d = BitsUtil.nextSetBit(dimensions, d + 1)) {
     final double max1 = mbr1.getMax(d);
     final double min2 = mbr2.getMin(d);
     if (max1 < min2) {
       double v = min2 - max1;
       if (v > agg) {
         agg = v;
       }
     } else {
       final double min1 = mbr1.getMin(d);
       final double max2 = mbr2.getMax(d);
       double v = min1 - max2;
       if (v > agg) {
         agg = v;
       }
     }
   }
   return agg;
 }
コード例 #4
0
ファイル: Misc.java プロジェクト: wwyzxb/RkNN-embedding
  public static List<double[]> getCorners(SpatialComparable box) {
    ArrayList<double[]> corners = new ArrayList<double[]>();
    if (SpatialUtil.perimeter(box) == 0) {
      corners.add(SpatialUtil.getMin(box));
      return corners;
    }
    boolean[] current = new boolean[box.getDimensionality()];
    int dim = box.getDimensionality();

    for (int i = 0; i < Math.pow(2, dim); i++) {
      double[] newCorner = new double[dim];
      for (int j = 0; j < dim; j++) {
        if (current[j]) newCorner[j] = box.getMin(j);
        else newCorner[j] = box.getMax(j);
      }
      addOne(current);
      corners.add(newCorner);
    }
    return corners;
  }
コード例 #5
0
  @Override
  public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
    if (dim >= mbr1.getDimensionality() || dim >= mbr2.getDimensionality() || dim < 0) {
      throw new IllegalArgumentException(
          "Specified dimension to be considered "
              + "is larger that dimensionality of FeatureVectors:"
              + "\n  first argument: "
              + mbr1.toString()
              + "\n  second argument: "
              + mbr2.toString()
              + "\n  dimension: "
              + dim);
    }

    final double max1 = mbr1.getMax(dim), min2 = mbr2.getMin(dim);
    if (max1 < min2) {
      return min2 - max1;
    }
    final double min1 = mbr1.getMin(dim), max2 = mbr2.getMax(dim);
    if (min1 > max2) {
      return min1 - max2;
    }
    return 0;
  }