Package de.lmu.ifi.dbs.elki.utilities.pairs

Examples of de.lmu.ifi.dbs.elki.utilities.pairs.DoubleIntPair


    protected void initMinMaxArrays() {
      maxSorting = new DoubleIntPair[size];
      minSorting = new DoubleIntPair[size];
      // Prefill
      for(int j = 0; j < size; j++) {
        minSorting[j] = new DoubleIntPair(0, -1);
        maxSorting[j] = new DoubleIntPair(0, -1);
      }
    }
View Full Code Here


      }
    }
    // Sort by minimum value
    DoubleIntPair[] data = new DoubleIntPair[num];
    for(int i = 0; i < num; i++) {
      data[i] = new DoubleIntPair(getter.get(entries, i).getMin(axis), i);
    }
    Arrays.sort(data);
    // Object assignment
    final BitSet assignment = new BitSet(num);
    final int half = (num + 1) / 2;
View Full Code Here

        for(int i = 0; i < neighbors.size(); i++) {
          DistanceResultPair<D> r = neighbors.get(i);
          if(i + 1 < neighbors.size() && r.getDistance().compareTo(neighbors.get(i + 1).getDistance()) == 0) {
            continue;
          }
          cdist.add(new DoubleIntPair(r.getDistance().doubleValue(), i));
          final double ri = r.getDistance().doubleValue() / alpha;
          if(ri <= rmax.doubleValue()) {
            cdist.add(new DoubleIntPair(ri, Integer.MIN_VALUE));
          }
        }
      }
      Collections.sort(cdist);
      // fill the gaps to have fast lookups of number of neighbors at a given
View Full Code Here

  public <A> int[] computeReinserts(A entries, ArrayAdapter<? extends SpatialComparable, ? super A> getter, SpatialComparable page) {
    DoubleIntPair[] order = new DoubleIntPair[getter.size(entries)];
    DoubleVector centroid = new DoubleVector(SpatialUtil.centroid(page));
    for(int i = 0; i < order.length; i++) {
      double distance = distanceFunction.doubleMinDist(new DoubleVector(SpatialUtil.centroid(getter.get(entries, i))), centroid);
      order[i] = new DoubleIntPair(distance, i);
    }
    Arrays.sort(order, Collections.reverseOrder());

    int num = (int) (reinsertAmount * order.length);
    int[] re = new int[num];
View Full Code Here

  public <A> int[] computeReinserts(A entries, ArrayAdapter<? extends SpatialComparable, ? super A> getter, SpatialComparable page) {
    DoubleIntPair[] order = new DoubleIntPair[getter.size(entries)];
    DoubleVector centroid = new DoubleVector(SpatialUtil.centroid(page));
    for(int i = 0; i < order.length; i++) {
      double distance = distanceFunction.doubleMinDist(new DoubleVector(SpatialUtil.centroid(getter.get(entries, i))), centroid);
      order[i] = new DoubleIntPair(distance, i);
    }
    Arrays.sort(order, Collections.reverseOrder());

    int num = (int) (reinsertAmount * order.length);
    int[] re = new int[num];
View Full Code Here

      int[][] posvecs = new int[len][dim];
      // Sort for each dimension
      // TODO: an int[] array would be enough, if we could use a comparator...
      DoubleIntPair[] sorter = new DoubleIntPair[len];
      for(int i = 0; i < sorter.length; i++) {
        sorter[i] = new DoubleIntPair(Double.NaN, -1);
      }
      for(int d = 1; d <= dim; d++) {
        // fill array
        for(int i = 0; i < sorter.length; i++) {
          sorter[i].first = castColumn.get(i).doubleValue(d);
View Full Code Here

      // Existing object and extended rectangle:
      SpatialComparable entry = getter.get(options, i);
      HyperBoundingBox mbr = SpatialUtil.union(entry, obj);
      // Area increase
      final double inc_area = SpatialUtil.volume(mbr) - SpatialUtil.volume(entry);
      candidates.add(new DoubleIntPair(inc_area, i));
    }

    // R*-Tree: overlap increase for leaves.
    int best = -1;
    double least_overlap = Double.POSITIVE_INFINITY;
    double least_areainc = Double.POSITIVE_INFINITY;
    double least_area = Double.POSITIVE_INFINITY;
    // least overlap increase, on reduced candidate set:
    while(!candidates.isEmpty()) {
      DoubleIntPair pair = candidates.poll();
      final double inc_area = pair.first;

      // Existing object and extended rectangle:
      SpatialComparable entry = getter.get(options, pair.second);
      HyperBoundingBox mbr = SpatialUtil.union(entry, obj);
View Full Code Here

          continue;
        }
        final NumberVector<?, ?> vec = relation.get(id);
        TiedTopBoundedHeap<DoubleIntPair> heap = new TiedTopBoundedHeap<DoubleIntPair>(estimated_outliers, Collections.reverseOrder());
        for(int i = 0; i < dim; i++) {
          heap.add(new DoubleIntPair(vec.doubleValue(i + 1), i));
        }
        if(heap.size() >= 2 * estimated_outliers) {
          logger.warning("Too many ties. Expected: " + estimated_outliers + " got: " + heap.size());
        }
        for(DoubleIntPair pair : heap) {
          if(outliers_seen[pair.second] == 0) {
            outliers_seen[pair.second] = 1;
            union_outliers += 1;
          }
          else {
            outliers_seen[pair.second] += 1;
          }
        }
      }
    }
    logger.verbose("Merged top " + estimated_outliers + " outliers to: " + union_outliers + " outliers");
    // Build the final weight vector.
    final double[] estimated_weights = new double[dim];
    final double[] estimated_truth = new double[dim];
    updateEstimations(outliers_seen, union_outliers, estimated_weights, estimated_truth);
    NumberVector<?, ?> estimated_truth_vec = refvec.newNumberVector(estimated_truth);

    PrimitiveDoubleDistanceFunction<NumberVector<?, ?>> wdist = getDistanceFunction(estimated_weights);
    PrimitiveDoubleDistanceFunction<NumberVector<?, ?>> tdist = wdist;

    // Build the naive ensemble:
    final double[] naiveensemble = new double[dim];
    {
      for(DBID id : relation.iterDBIDs()) {
        if(firstid.equals(id)) {
          continue;
        }
        final NumberVector<?, ?> vec = relation.get(id);
        for(int d = 0; d < dim; d++) {
          naiveensemble[d] += vec.doubleValue(d + 1);
        }
      }
      for(int d = 0; d < dim; d++) {
        naiveensemble[d] /= (relation.size() - 1);
      }
    }
    NumberVector<?, ?> naivevec = refvec.newNumberVector(naiveensemble);

    // Compute single AUC scores and estimations.
    // Remember the method most similar to the estimation
    double bestauc = 0.0;
    String bestaucstr = "";
    double bestcost = Double.POSITIVE_INFINITY;
    String bestcoststr = "";
    DBID bestid = null;
    double bestest = Double.POSITIVE_INFINITY;
    {
      // Compute individual scores
      for(DBID id : relation.iterDBIDs()) {
        if(firstid.equals(id)) {
          continue;
        }
        // fout.append(labels.get(id));
        final NumberVector<?, ?> vec = relation.get(id);
        double auc = computeROCAUC(vec, positive, dim);
        double estimated = wdist.doubleDistance(vec, estimated_truth_vec);
        double cost = tdist.doubleDistance(vec, refvec);
        logger.verbose("ROC AUC: " + auc + " estimated " + estimated + " cost " + cost + " " + labels.get(id));
        if(auc > bestauc) {
          bestauc = auc;
          bestaucstr = labels.get(id);
        }
        if(cost < bestcost) {
          bestcost = cost;
          bestcoststr = labels.get(id);
        }
        if(estimated < bestest) {
          bestest = estimated;
          bestid = id;
        }
      }
    }

    // Initialize ensemble with "best" method
    logger.verbose("Distance function: " + wdist);
    logger.verbose("Initial estimation of outliers: " + union_outliers);
    logger.verbose("Initializing ensemble with: " + labels.get(bestid));
    ModifiableDBIDs ensemble = DBIDUtil.newArray(bestid);
    ModifiableDBIDs enscands = DBIDUtil.newHashSet(relation.getDBIDs());
    enscands.remove(bestid);
    enscands.remove(firstid);
    final double[] greedyensemble = new double[dim];
    {
      final NumberVector<?, ?> vec = relation.get(bestid);
      for(int i = 0; i < dim; i++) {
        greedyensemble[i] = vec.doubleValue(i + 1);
      }
    }
    // Greedily grow the ensemble
    final double[] testensemble = new double[dim];
    while(enscands.size() > 0) {
      NumberVector<?, ?> greedyvec = refvec.newNumberVector(greedyensemble);

      // Weighting factors for combining:
      double s1 = ensemble.size() / (ensemble.size() + 1.);
      double s2 = 1. / (ensemble.size() + 1.);

      final int heapsize = enscands.size();
      TopBoundedHeap<DoubleObjPair<DBID>> heap = new TopBoundedHeap<DoubleObjPair<DBID>>(heapsize, Collections.reverseOrder());
      for(DBID id : enscands) {
        final NumberVector<?, ?> vec = relation.get(id);
        double diversity = wdist.doubleDistance(vec, greedyvec);
        heap.add(new DoubleObjPair<DBID>(diversity, id));
      }
      while(heap.size() > 0) {
        DBID bestadd = heap.poll().second;
        enscands.remove(bestadd);
        // Update ensemble:
        final NumberVector<?, ?> vec = relation.get(bestadd);
        for(int i = 0; i < dim; i++) {
          testensemble[i] = greedyensemble[i] * s1 + vec.doubleValue(i + 1) * s2;
        }
        NumberVector<?, ?> testvec = refvec.newNumberVector(testensemble);
        double oldd = wdist.doubleDistance(estimated_truth_vec, greedyvec);
        double newd = wdist.doubleDistance(estimated_truth_vec, testvec);
        // logger.verbose("Distances: " + oldd + " vs. " + newd);
        if(newd < oldd) {
          System.arraycopy(testensemble, 0, greedyensemble, 0, dim);
          ensemble.add(bestadd);
          // logger.verbose("Growing ensemble with: " + labels.get(bestadd));
          break; // Recompute heap
        }
        else {
          // logger.verbose("Discarding: " + labels.get(bestadd));
          if(refine_truth) {
            boolean refresh = false;
            // Update target vectors and weights
            TiedTopBoundedHeap<DoubleIntPair> oheap = new TiedTopBoundedHeap<DoubleIntPair>(estimated_outliers, Collections.reverseOrder());
            for(int i = 0; i < dim; i++) {
              oheap.add(new DoubleIntPair(vec.doubleValue(i + 1), i));
            }
            for(DoubleIntPair pair : oheap) {
              assert (outliers_seen[pair.second] > 0);
              outliers_seen[pair.second] -= 1;
              if(outliers_seen[pair.second] == 0) {
View Full Code Here

  }

  private double computeROCAUC(NumberVector<?, ?> vec, Set<Integer> positive, int dim) {
    final DoubleIntPair[] scores = new DoubleIntPair[dim];
    for(int d = 0; d < dim; d++) {
      scores[d] = new DoubleIntPair(vec.doubleValue(d + 1), d);
    }
    Arrays.sort(scores, Collections.reverseOrder(DoubleIntPair.BYFIRST_COMPARATOR));
    return ROC.computeAUC(ROC.materializeROC(dim, positive, Arrays.asList(scores).iterator()));
  }
View Full Code Here

    // Build the truth vector
    Set<Integer> pos = new TreeSet<Integer>();
    final DoubleIntPair[] combined = new DoubleIntPair[dim];
    {
      for(int d = 0; d < dim; d++) {
        combined[d] = new DoubleIntPair(0, d);
        if(refvec.doubleValue(d + 1) > 0) {
          pos.add(d);
        }
      }
    }
View Full Code Here

TOP

Related Classes of de.lmu.ifi.dbs.elki.utilities.pairs.DoubleIntPair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.