Package de.lmu.ifi.dbs.elki.database.ids

Examples of de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs


  @Override
  public abstract Matrix processIds(DBIDs ids, Relation<? extends V> database);

  @Override
  public <D extends NumberDistance<?, ?>> Matrix processQueryResults(Collection<DistanceResultPair<D>> results, Relation<? extends V> database, int k) {
    ModifiableDBIDs ids = DBIDUtil.newArray(k);
    int have = 0;
    for(Iterator<DistanceResultPair<D>> it = results.iterator(); it.hasNext() && have < k; have++) {
      ids.add(it.next().getDBID());
    }
    return processIds(ids, database);
  }
View Full Code Here


   * @param relation The data input we use
   */
  public Clustering<Model> run(Relation<?> relation) {
    HashMap<String, ModifiableDBIDs> labelMap = multiple ? multipleAssignment(relation) : singleAssignment(relation);

    ModifiableDBIDs noiseids = DBIDUtil.newArray();
    Clustering<Model> result = new Clustering<Model>("By Label Clustering", "bylabel-clustering");
    for(Entry<String, ModifiableDBIDs> entry : labelMap.entrySet()) {
      ModifiableDBIDs ids = labelMap.get(entry.getKey());
      if(ids.size() <= 1) {
        noiseids.addDBIDs(ids);
        continue;
      }
      // Build a cluster
      Cluster<Model> c = new Cluster<Model>(entry.getKey(), ids, ClusterModel.CLUSTER);
View Full Code Here

  private void assign(HashMap<String, ModifiableDBIDs> labelMap, String label, DBID id) {
    if(labelMap.containsKey(label)) {
      labelMap.get(label).add(id);
    }
    else {
      ModifiableDBIDs n = DBIDUtil.newHashSet();
      n.add(id);
      labelMap.put(label, n);
    }
  }
View Full Code Here

   *
   * @param relation The data input to use
   */
  public Clustering<Model> run(Relation<?> relation) throws IllegalStateException {
    HashMap<String, ModifiableDBIDs> labelmap = new HashMap<String, ModifiableDBIDs>();
    ModifiableDBIDs noiseids = DBIDUtil.newArray();

    for(DBID id : relation.iterDBIDs()) {
      String label = relation.get(id).toString();

      if(labelmap.containsKey(label)) {
        labelmap.get(label).add(id);
      }
      else {
        ModifiableDBIDs n = DBIDUtil.newHashSet();
        n.add(id);
        labelmap.put(label, n);
      }
    }

    ArrayList<Cluster<Model>> clusters = new ArrayList<Cluster<Model>>(labelmap.size());
    for(Entry<String, ModifiableDBIDs> entry : labelmap.entrySet()) {
      ModifiableDBIDs ids = entry.getValue();
      if(ids.size() <= 1) {
        noiseids.addDBIDs(ids);
        continue;
      }
      Cluster<Model> clus = new Cluster<Model>(entry.getKey(), ids, ClusterModel.CLUSTER, new ArrayList<Cluster<Model>>(), new ArrayList<Cluster<Model>>());
      clusters.add(clus);
View Full Code Here

    this.pca = pca;
  }

  @Override
  protected PCAFilteredResult computeProjection(DBID id, List<DistanceResultPair<D>> neighbors, Relation<V> database) {
    ModifiableDBIDs ids = DBIDUtil.newArray(neighbors.size());
    for(DistanceResultPair<D> neighbor : neighbors) {
      ids.add(neighbor.getDBID());
    }
    PCAFilteredResult pcares = pca.processIds(ids, database);

    if(logger.isDebugging()) {
      StringBuffer msg = new StringBuffer();
View Full Code Here

    if(!initialized) {
      initialize(entries.get(0));
    }

    Map<DBID, KNNHeap<D>> knnHeaps = new HashMap<DBID, KNNHeap<D>>(entries.size());
    ModifiableDBIDs ids = DBIDUtil.newArray(entries.size());

    // insert
    for(MkAppEntry<D> entry : entries) {
      DBID id = entry.getRoutingObjectID();
      // create knnList for the object
      knnHeaps.put(id, new KNNHeap<D>(k_max + 1, getDistanceQuery().infiniteDistance()));

      ids.add(id);
      // insert the object
      super.insert(entry, false);
    }

    // do batch nn
View Full Code Here

    if(ors == null || ors.size() <= 0) {
      // logger.warning("No results found for "+JudgeOutlierScores.class.getSimpleName());
      return;
    }

    ModifiableDBIDs ids = DBIDUtil.newHashSet(ors.iterator().next().getScores().getDBIDs());
    DBIDs outlierIds = DatabaseUtil.getObjectsByLabelMatch(db, positiveClassName);
    ids.removeDBIDs(outlierIds);

    for(OutlierResult or : ors) {
      db.getHierarchy().add(or, computeScore(ids, outlierIds, or));
    }
  }
View Full Code Here

        ids = DBIDUtil.randomSample(relation.getDBIDs(), this.sampleSize, 1);
      }
      else {
        DistanceQuery<V, D> distanceQuery = database.getDistanceQuery(relation, getDistanceFunction());
        List<DistanceResultPair<D>> queryResults = database.getKNNQuery(distanceQuery, this.sampleSize).getKNNForObject(centroidDV, this.sampleSize);
        ModifiableDBIDs tids = DBIDUtil.newHashSet(this.sampleSize);
        for(DistanceResultPair<D> qr : queryResults) {
          tids.add(qr.getDBID());
        }
        // Cast to non-modifiable
        ids = tids;
      }
    }
View Full Code Here

  public static <D extends Distance<D>> Clustering<Model> makeOPTICSCut(ClusterOrderResult<D> co, OPTICSDistanceAdapter<D> adapter, double epsilon) {
    List<ClusterOrderEntry<D>> order = co.getClusterOrder();
    // Clustering model we are building
    Clustering<Model> clustering = new Clustering<Model>("OPTICS Cut Clustering", "optics-cut");
    // Collects noise elements
    ModifiableDBIDs noise = DBIDUtil.newHashSet();

    double lastDist = Double.MAX_VALUE;
    double actDist = Double.MAX_VALUE;

    // Current working set
    ModifiableDBIDs current = DBIDUtil.newHashSet();

    // TODO: can we implement this more nicely with a 1-lookahead?
    for(int j = 0; j < order.size(); j++) {
      lastDist = actDist;
      actDist = adapter.getDoubleForEntry(order.get(j));

      if(actDist <= epsilon) {
        // the last element before the plot drops belongs to the cluster
        if(lastDist > epsilon && j > 0) {
          // So un-noise it
          noise.remove(order.get(j - 1).getID());
          // Add it to the cluster
          current.add(order.get(j - 1).getID());
        }
        current.add(order.get(j).getID());
      }
      else {
        // 'Finish' the previous cluster
        if(!current.isEmpty()) {
          // TODO: do we want a minpts restriction?
          // But we get have only core points guaranteed anyway.
          clustering.addCluster(new Cluster<Model>(current, ClusterModel.CLUSTER));
          current = DBIDUtil.newHashSet();
        }
        // Add to noise
        noise.add(order.get(j).getID());
      }
    }
    // Any unfinished cluster will also be added
    if(!current.isEmpty()) {
      clustering.addCluster(new Cluster<Model>(current, ClusterModel.CLUSTER));
    }
    // Add noise
    clustering.addCluster(new Cluster<Model>(noise, true, ClusterModel.CLUSTER));
    return clustering;
View Full Code Here

     * @param ids the list of ids
     * @return a set containing the ids of the query result and the specified
     *         ids
     */
    private ArrayModifiableDBIDs mergeIDs(List<List<DistanceResultPair<D>>> queryResults, DBIDs... ids) {
      ModifiableDBIDs result = DBIDUtil.newTreeSet();
      for(DBIDs dbids : ids) {
        result.addDBIDs(dbids);
      }
      for(List<DistanceResultPair<D>> queryResult : queryResults) {
        for(DistanceResultPair<D> qr : queryResult) {
          result.add(qr.getDBID());
        }
      }
      return DBIDUtil.newArray(result);
    }
View Full Code Here

TOP

Related Classes of de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs

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.