Compute the core distances for all objects.

@param ids Objects
@param knnQ kNN query
@param minPts Minimum neighborhood size
@return Data store with core distances
172832
protected WritableDoubleDataStore computeCoreDists(DBIDs ids, KNNQuery<O> knnQ, int minPts) {
    final Logging LOG = getLogger();
    final WritableDoubleDataStore coredists = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_DB);
    FiniteProgress cprog = LOG.isVerbose() ? new FiniteProgress("Computing core sizes", ids.size(), LOG) : null;
    for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
      coredists.put(iter, knnQ.getKNNForDBID(iter, minPts).getKNNDistance());
      LOG.incrementProcessed(cprog);
    }
    LOG.ensureCompleted(cprog);
    return coredists;
  }
131103
public static ArrayDBIDs ensureArray(DBIDs ids) {
    return ids instanceof ArrayDBIDs ? (ArrayDBIDs) ids : newArray(ids);
  }
676208
protected DBIDs findNeighbors(DBIDRef q, long[] nD, ArrayModifiableDBIDs S, Relation<V> relation) {
    // Weights for distance (= rectangle query)
    DistanceQuery<V> dq = relation.getDistanceQuery(new SubspaceMaximumDistanceFunction(nD));

    // TODO: add filtering capabilities into query API!
    // Until then, using the range query API will be unnecessarily slow.
    // RangeQuery<V> rq = relation.getRangeQuery(df, DatabaseQuery.HINT_SINGLE);
    ArrayModifiableDBIDs nC = DBIDUtil.newArray();
    for(DBIDIter it = S.iter(); it.valid(); it.advance()) {
      if(dq.distance(q, it) <= w) {
        nC.add(it);
      }
    }
    return nC;
  }
1184462
public void setIds(java.util.Collection<String> ids) {
        if (ids == null) {
            this.ids = null;
            return;
        }

        this.ids = new java.util.ArrayList<String>(ids);
    }
1021138
protected void precomputeInterestingRadii(DBIDs ids, RangeQuery<O> rangeQuery, WritableDataStore<DoubleIntArrayList> interestingDistances) {
    FiniteProgress progressPreproc = LOG.isVerbose() ? new FiniteProgress("LOCI preprocessing", ids.size(), LOG) : null;
    for(DBIDIter iditer = ids.iter(); iditer.valid(); iditer.advance()) {
      DoubleDBIDList neighbors = rangeQuery.getRangeForDBID(iditer, rmax);
      // build list of critical distances
      DoubleIntArrayList cdist = new DoubleIntArrayList(neighbors.size() << 1);
      {
        int i = 0;
        DoubleDBIDListIter ni = neighbors.iter();
        while(ni.valid()) {
          final double curdist = ni.doubleValue();
          ++i;
          ni.advance();
          // Skip, if tied to the next object:
          if(ni.valid() && curdist == ni.doubleValue()) {
            continue;
          }
          cdist.append(curdist, i);
          // Scale radius, and reinsert
          if(alpha != 1.) {
            final double ri = curdist / alpha;
            if(ri <= rmax) {
              cdist.append(ri, Integer.MIN_VALUE);
            }
          }
        }
      }
      cdist.sort();

      // fill the gaps to have fast lookups of number of neighbors at a given
      // distance.
      int lastk = 0;
      for(int i = 0, size = cdist.size(); i < size; i++) {
        final int k = cdist.getInt(i);
        if(k == Integer.MIN_VALUE) {
          cdist.setValue(i, lastk);
        }
        else {
          lastk = k;
        }
      }
      // TODO: shrink the list, removing duplicate radii?

      interestingDistances.put(iditer, cdist);
      LOG.incrementProcessed(progressPreproc);
    }
    LOG.ensureCompleted(progressPreproc);
  }
1305888
protected void linearScanBatchKNN(List<O> objs, List<KNNHeap> heaps) {
    final PrimitiveDistanceFunction<? super O> rawdist = this.rawdist;
    final Relation<? extends O> relation = getRelation();
    final int size = objs.size();
    // Linear scan style KNN.
    for(DBIDIter iter = relation.getDBIDs().iter(); iter.valid(); iter.advance()) {
      O candidate = relation.get(iter);
      for(int index = 0; index < size; index++) {
        final KNNHeap heap = heaps.get(index);
        final double dist = rawdist.distance(objs.get(index), candidate);
        if(dist <= heap.getKNNDistance()) {
          heap.insert(dist, iter);
        }
      }
    }
  }
765264
public static WritableDBIDDataStore makeDBIDStorage(DBIDs ids, int hints) {
    return DataStoreFactory.FACTORY.makeDBIDStorage(ids, hints);
  }
406722
private ArrayList<PROCLUSCluster> assignPoints(ArrayDBIDs m_current, long[][] dimensions, Relation<V> database) {
    ModifiableDBIDs[] clusterIDs = new ModifiableDBIDs[dimensions.length];
    for(int i = 0; i < m_current.size(); i++) {
      clusterIDs[i] = DBIDUtil.newHashSet();
    }

    DBIDArrayIter m_i = m_current.iter();
    for(DBIDIter it = database.iterDBIDs(); it.valid(); it.advance()) {
      V p = database.get(it);
      double minDist = Double.NaN;
      int best = -1, i = 0;
      for(m_i.seek(0); m_i.valid(); m_i.advance(), i++) {
        V m = database.get(m_i);
        double currentDist = manhattanSegmentalDistance(p, m, dimensions[i]);
        if(!(minDist <= currentDist)) {
          minDist = currentDist;
          best = i;
        }
      }
      // add p to cluster with mindist
      assert best >= 0;
      clusterIDs[best].add(it);
    }

    ArrayList<PROCLUSCluster> clusters = new ArrayList<>(m_current.size());
    for(int i = 0; i < dimensions.length; i++) {
      ModifiableDBIDs objectIDs = clusterIDs[i];
      if(!objectIDs.isEmpty()) {
        long[] clusterDimensions = dimensions[i];
        double[] centroid = Centroid.make(database, objectIDs).getArrayRef();
        clusters.add(new PROCLUSCluster(objectIDs, clusterDimensions, centroid));
      }
      else {
        clusters.add(null);
      }
    }

    if(LOG.isDebugging()) {
      LOG.debugFine(new StringBuilder().append("clusters ").append(clusters).toString());
    }
    return clusters;
  }
257016
private void setColumnsSize(final double min, final double max, final String... columnPropertyIds) {
        for (final String columnPropertyId : columnPropertyIds) {
            getColumn(columnPropertyId).setMinimumWidth(min);
            getColumn(columnPropertyId).setMaximumWidth(max);
        }
    }
402250
protected void computeLRDs(KNNQuery<O> knnq, DBIDs ids, WritableDoubleDataStore lrds) {
    FiniteProgress lrdsProgress = LOG.isVerbose() ? new FiniteProgress("LRD", ids.size(), LOG) : null;
    for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
      final KNNList neighbors = knnq.getKNNForDBID(iter, kreach);
      double sum = 0.0;
      int count = 0;
      for(DoubleDBIDListIter neighbor = neighbors.iter(); neighbor.valid(); neighbor.advance()) {
        if(DBIDUtil.equal(neighbor, iter)) {
          continue;
        }
        KNNList neighborsNeighbors = knnq.getKNNForDBID(neighbor, kreach);
        sum += MathUtil.max(neighbor.doubleValue(), neighborsNeighbors.getKNNDistance());
        count++;
      }
      // Avoid division by 0
      final double lrd = (sum > 0) ? (count / sum) : Double.POSITIVE_INFINITY;
      lrds.putDouble(iter, lrd);
      LOG.incrementProcessed(lrdsProgress);
    }
    LOG.ensureCompleted(lrdsProgress);
  }
862136
public List<Entry> storeSkipExisting(List<Entry> entries) throws MissingParentException {
        List<Entry> skippedEntries = new LinkedList<Entry>();
        for (Entry e : entries) {
            try {
                store(e);
            } catch (EntryAlreadyExistsException ex) {
                skippedEntries.add(e);
            }
        }
        return skippedEntries;
    }
587854
private void computeVolumes(KNNQuery<O> knnq, int dim, DBIDs ids, WritableDoubleDataStore vols) {
    FiniteProgress prog = LOG.isVerbose() ? new FiniteProgress("Volume", ids.size(), LOG) : null;
    double scaleconst = MathUtil.SQRTPI * FastMath.pow(GammaDistribution.gamma(1 + dim * .5), -1. / dim);
    boolean warned = false;
    double sum = 0.;
    for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
      double dk = knnq.getKNNForDBID(iter, k).getKNNDistance();
      double vol = dk > 0 ? MathUtil.powi(dk * scaleconst, dim) : 0.;
      if(vol == Double.POSITIVE_INFINITY && !warned) {
        LOG.warning("Variance of Volumes has hit double precision limits, results are not reliable.");
        warned = true;
      }
      vols.putDouble(iter, vol);
      sum += vol;
      LOG.incrementProcessed(prog);
    }
    double scaling = ids.size() / sum;
    for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
      vols.putDouble(iter, vols.doubleValue(iter) * scaling);
    }
    LOG.ensureCompleted(prog);
  }
1072388
protected Query buildMtoNImplementorQuery(Collection ids)
    {
        String[] indFkCols = getFksToThisClass();
        String[] indItemFkCols = getFksToItemClass();
        FieldDescriptor[] pkFields = getOwnerClassDescriptor().getPkFields();
        FieldDescriptor[] itemPkFields = getItemClassDescriptor().getPkFields();
        String[] cols = new String[indFkCols.length + indItemFkCols.length];
        int[] jdbcTypes = new int[indFkCols.length + indItemFkCols.length];

        // concatenate the columns[]
        System.arraycopy(indFkCols, 0, cols, 0, indFkCols.length);
        System.arraycopy(indItemFkCols, 0, cols, indFkCols.length, indItemFkCols.length);

        Criteria crit = buildPrefetchCriteria(ids, indFkCols, indItemFkCols, itemPkFields);

        // determine the jdbcTypes of the pks
        for (int i = 0; i < pkFields.length; i++)
        {
            jdbcTypes[i] = pkFields[i].getJdbcType().getType();
        }
        for (int i = 0; i < itemPkFields.length; i++)
        {
            jdbcTypes[pkFields.length + i] = itemPkFields[i].getJdbcType().getType();
        }

        ReportQueryByMtoNCriteria q = new ReportQueryByMtoNCriteria(getItemClassDescriptor().getClassOfObject(), cols,
                crit, false);
        q.setIndirectionTable(getCollectionDescriptor().getIndirectionTable());
        q.setJdbcTypes(jdbcTypes);

        CollectionDescriptor cds = getCollectionDescriptor();
        //check if collection must be ordered
        if (!cds.getOrderBy().isEmpty())
        {
            Iterator iter = cds.getOrderBy().iterator();
            while (iter.hasNext())
            {
                q.addOrderBy((FieldHelper) iter.next());
            }
        }
        
        return q;
    }
395264
protected Pair<KNNQuery<O>, KNNQuery<O>> getKNNQueries(Database database, Relation<O> relation, StepProgress stepprog) {
    KNNQuery<O> knnComp, knnReach;
    if(comparisonDistanceFunction == reachabilityDistanceFunction || comparisonDistanceFunction.equals(reachabilityDistanceFunction)) {
      LOG.beginStep(stepprog, 1, "Materializing neighborhoods with respect to reference neighborhood distance function.");
      knnComp = DatabaseUtil.precomputedKNNQuery(database, relation, comparisonDistanceFunction, MathUtil.max(kcomp, kreach) + 1);
      knnReach = knnComp;
    }
    else {
      LOG.beginStep(stepprog, 1, "Not materializing distance functions, since we request each DBID once only.");
      knnComp = QueryUtil.getKNNQuery(relation, comparisonDistanceFunction, kreach + 1);
      knnReach = QueryUtil.getKNNQuery(relation, reachabilityDistanceFunction, kcomp + 1);
    }
    return new Pair<>(knnComp, knnReach);
  }
898431
public void setDBIDs(DBIDs ids) {
    this.idrep.setDBIDs(ids);
    // Update relations.
    for (Relation<?> orel : this.relations) {
      if (orel instanceof ProxyView) {
        ((ProxyView<?>) orel).setDBIDs(this.idrep.getDBIDs());
      }
    }
  }
682550
public void setDimensions(int maxCols, int minCols, int maxRows, int minRows) {
    this.maxCols = maxCols;
    this.minCols = minCols;
    this.maxRows = maxRows;
    this.minRows = minRows;
  }
261613
def nearest_keys(self, key):
        """"""
        if not isinstance(key, tuple):
            _key = (key,)
        if self.__stale:
            self.generate_tree()
        d, idx = self.__tree.query(
            _key, self.k_neighbors, distance_upper_bound=self.distance_upper_bound)

        try:
            return [self.__keys[id][0] for id in idx if id < len(self.__keys)]
        except TypeError:
            # if k_neighbors = 1 query is not returnng arrays
            return self.__keys[idx]