當前位置: 首頁>>代碼示例>>Java>>正文


Java Relation.iterDBIDs方法代碼示例

本文整理匯總了Java中de.lmu.ifi.dbs.elki.database.relation.Relation.iterDBIDs方法的典型用法代碼示例。如果您正苦於以下問題:Java Relation.iterDBIDs方法的具體用法?Java Relation.iterDBIDs怎麽用?Java Relation.iterDBIDs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在de.lmu.ifi.dbs.elki.database.relation.Relation的用法示例。


在下文中一共展示了Relation.iterDBIDs方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import de.lmu.ifi.dbs.elki.database.relation.Relation; //導入方法依賴的package包/類
/**
 * Main loop for OUTRES
 * 
 * @param relation Relation to process
 * @return Outlier detection result
 */
public OutlierResult run(Relation<V> relation) {
  WritableDoubleDataStore ranks = DataStoreUtil.makeDoubleStorage(relation.getDBIDs(), DataStoreFactory.HINT_STATIC);
  DoubleMinMax minmax = new DoubleMinMax();

  KernelDensityEstimator kernel = new KernelDensityEstimator(relation);
  long[] subspace = BitsUtil.zero(kernel.dim);

  FiniteProgress progress = LOG.isVerbose() ? new FiniteProgress("OUTRES scores", relation.size(), LOG) : null;

  for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
    BitsUtil.zeroI(subspace);
    double score = outresScore(0, subspace, iditer, kernel);
    ranks.putDouble(iditer, score);
    minmax.put(score);
    LOG.incrementProcessed(progress);
  }
  LOG.ensureCompleted(progress);

  OutlierScoreMeta meta = new InvertedOutlierScoreMeta(minmax.getMin(), minmax.getMax(), 0., 1., 1.);
  OutlierResult outresResult = new OutlierResult(meta, new MaterializedDoubleRelation("OUTRES", "outres-score", ranks, relation.getDBIDs()));
  return outresResult;
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:29,代碼來源:OUTRES.java

示例2: getNearestNeighbors

import de.lmu.ifi.dbs.elki.database.relation.Relation; //導入方法依賴的package包/類
/**
 * Get the k nearest neighbors in terms of the shared nearest neighbor
 * distance.
 *
 * The query object is excluded from the knn list.
 * 
 * FIXME: move this to the database layer.
 * 
 * @param relation the database holding the objects
 * @param simQ similarity function
 * @param queryObject the query object for which the kNNs should be determined
 * @return the k nearest neighbors in terms of the shared nearest neighbor
 *         distance without the query object
 */
private DBIDs getNearestNeighbors(Relation<V> relation, SimilarityQuery<V> simQ, DBIDRef queryObject) {
  Heap<DoubleDBIDPair> nearestNeighbors = new TiedTopBoundedHeap<>(knn);
  for(DBIDIter iter = relation.iterDBIDs(); iter.valid(); iter.advance()) {
    if(DBIDUtil.equal(iter, queryObject)) {
      continue;
    }
    double sim = simQ.similarity(queryObject, iter);
    if(sim > 0.) {
      nearestNeighbors.add(DBIDUtil.newPair(sim, iter));
    }
  }
  // Collect DBIDs
  ArrayModifiableDBIDs dbids = DBIDUtil.newArray(nearestNeighbors.size());
  while(nearestNeighbors.size() > 0) {
    dbids.add(nearestNeighbors.poll());
  }
  return dbids;
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:33,代碼來源:SOD.java

示例3: DAFile

import de.lmu.ifi.dbs.elki.database.relation.Relation; //導入方法依賴的package包/類
/**
 * Constructor.
 * 
 * @param relation Relation to index
 * @param dimension Dimension of this file
 * @param partitions Number of partitions
 */
public DAFile(Relation<? extends NumberVector> relation, int dimension, int partitions) {
  final int size = relation.size();
  this.dimension = dimension;
  this.splitPositions = new double[partitions + 1];

  double[] tempdata = new double[size];
  int j = 0;
  for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
    tempdata[j] = relation.get(iditer).doubleValue(dimension);
    j += 1;
  }
  Arrays.sort(tempdata);

  for(int b = 0; b < partitions; b++) {
    int start = (int) (b * size / (double) partitions);
    splitPositions[b] = tempdata[start];
  }
  // make sure that last object will be included
  splitPositions[partitions] = tempdata[size - 1] + 0.000001;
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:28,代碼來源:DAFile.java

示例4: exactMinMax

import de.lmu.ifi.dbs.elki.database.relation.Relation; //導入方法依賴的package包/類
/**
 * Compute the exact maximum and minimum.
 *
 * @param relation Relation to process
 * @param distFunc Distance function
 * @return Exact maximum and minimum
 */
private DoubleMinMax exactMinMax(Relation<O> relation, DistanceQuery<O> distFunc) {
  final FiniteProgress progress = LOG.isVerbose() ? new FiniteProgress("Exact fitting distance computations", relation.size(), LOG) : null;
  DoubleMinMax minmax = new DoubleMinMax();
  // find exact minimum and maximum first.
  for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
    for(DBIDIter iditer2 = relation.iterDBIDs(); iditer2.valid(); iditer2.advance()) {
      // skip the point itself.
      if(DBIDUtil.equal(iditer, iditer2)) {
        continue;
      }
      double d = distFunc.distance(iditer, iditer2);
      minmax.put(d);
    }
    LOG.incrementProcessed(progress);
  }
  LOG.ensureCompleted(progress);
  return minmax;
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:26,代碼來源:DistanceStatisticsWithClasses.java

示例5: instantiate

import de.lmu.ifi.dbs.elki.database.relation.Relation; //導入方法依賴的package包/類
/**
 * Full instantiation method.
 * 
 * @param database Database
 * @param relation Vector relation
 * @return Instance
 */
public COPACNeighborPredicate.Instance instantiate(Database database, Relation<V> relation) {
  DistanceQuery<V> dq = database.getDistanceQuery(relation, EuclideanDistanceFunction.STATIC);
  KNNQuery<V> knnq = database.getKNNQuery(dq, settings.k);

  WritableDataStore<COPACModel> storage = DataStoreUtil.makeStorage(relation.getDBIDs(), DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_TEMP, COPACModel.class);
  
  Duration time = LOG.newDuration(this.getClass().getName() + ".preprocessing-time").begin();
  FiniteProgress progress = LOG.isVerbose() ? new FiniteProgress(this.getClass().getName(), relation.size(), LOG) : null;
  for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
    DoubleDBIDList ref = knnq.getKNNForDBID(iditer, settings.k);
    storage.put(iditer, computeLocalModel(iditer, ref, relation));
    LOG.incrementProcessed(progress);
  }
  LOG.ensureCompleted(progress);
  LOG.statistics(time.end());
  return new Instance(relation.getDBIDs(), storage);
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:25,代碼來源:COPACNeighborPredicate.java

示例6: computeNeighborhoods

import de.lmu.ifi.dbs.elki.database.relation.Relation; //導入方法依賴的package包/類
/**
 * Compute neighborhoods
 *
 * @param relation
 * @param knnQuery
 * @param pruned
 * @param knns
 * @param rnns
 * @param density
 */
protected void computeNeighborhoods(Relation<O> relation, KNNQuery<O> knnQuery, ModifiableDBIDs pruned, WritableDataStore<ModifiableDBIDs> knns, WritableDataStore<ModifiableDBIDs> rnns, WritableDoubleDataStore density) {
  for(DBIDIter iter = relation.iterDBIDs(); iter.valid(); iter.advance()) {
    // if not visited count=0
    int count = rnns.get(iter).size();
    DBIDs knn = getKNN(iter, knnQuery, knns, density);
    for(DBIDIter niter = knn.iter(); niter.valid(); niter.advance()) {
      // Ignore the query point itself.
      if(DBIDUtil.equal(iter, niter)) {
        continue;
      }
      if(getKNN(niter, knnQuery, knns, density).contains(iter)) {
        rnns.get(niter).add(iter);
        rnns.get(iter).add(niter);
        count++;
      }
    }
    if(count >= knn.size() * m) {
      pruned.add(iter);
    }
  }
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:32,代碼來源:INFLO.java

示例7: chooseInitialMeans

import de.lmu.ifi.dbs.elki.database.relation.Relation; //導入方法依賴的package包/類
@Override
public <T extends NumberVector> double[][] chooseInitialMeans(Database database, Relation<T> relation, int k, NumberVectorDistanceFunction<? super T> distanceFunction) {
  DBIDIter iter = relation.iterDBIDs();
  double[][] means = new double[k][];
  for(int i = 0; i < k && iter.valid(); i++, iter.advance()) {
    means[i] = relation.get(iter).toArray();
  }
  return means;
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:10,代碼來源:FirstKInitialMeans.java

示例8: run

import de.lmu.ifi.dbs.elki.database.relation.Relation; //導入方法依賴的package包/類
/**
 * Run the algorithm.
 * 
 * @param database Database
 * @param relation Relation
 * @return Null result
 */
public Result run(Database database, Relation<O> relation) {
  // Get a distance and knn query for the Euclidean distance
  // Hardcoded, only use this if you only allow the eucliden distance
  DistanceQuery<O> distQuery = database.getDistanceQuery(relation, EuclideanDistanceFunction.STATIC);
  KNNQuery<O> knnQuery = database.getKNNQuery(distQuery, 10);

  for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
    // Get the actual object from the database (but discard the result)
    relation.get(iditer);
    // run a 10NN query for each point (but discard the result)
    knnQuery.getKNNForDBID(iditer, 10);
  }
  return null;
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:22,代碼來源:DummyAlgorithm.java

示例9: run

import de.lmu.ifi.dbs.elki.database.relation.Relation; //導入方法依賴的package包/類
/**
 * Run the outlier detection algorithm
 *
 * @param database Database to use
 * @param relation Relation to analyze
 * @return Outlier score result
 */
public OutlierResult run(Database database, Relation<O> relation) {
  // Get a nearest neighbor query on the relation.
  KNNQuery<O> knnq = QueryUtil.getKNNQuery(relation, getDistanceFunction(), k);
  // Output data storage
  WritableDoubleDataStore scores = DataStoreUtil.makeDoubleStorage(relation.getDBIDs(), DataStoreFactory.HINT_DB);
  // Track minimum and maximum scores
  DoubleMinMax minmax = new DoubleMinMax();

  // Iterate over all objects
  for(DBIDIter iter = relation.iterDBIDs(); iter.valid(); iter.advance()) {
    KNNList neighbors = knnq.getKNNForDBID(iter, k);
    // Aggregate distances
    MeanVariance mv = new MeanVariance();
    for(DoubleDBIDListIter neighbor = neighbors.iter(); neighbor.valid(); neighbor.advance()) {
      // Skip the object itself. The 0 is not very informative.
      if(DBIDUtil.equal(iter, neighbor)) {
        continue;
      }
      mv.put(neighbor.doubleValue());
    }
    // Store score
    scores.putDouble(iter, mv.getSampleStddev());
  }

  // Wrap the result in the standard containers
  // Actual min-max, theoretical min-max!
  OutlierScoreMeta meta = new BasicOutlierScoreMeta(minmax.getMin(), minmax.getMax(), 0, Double.POSITIVE_INFINITY);
  DoubleRelation rel = new MaterializedDoubleRelation(relation.getDBIDs(), "stddev-outlier", scores);
  return new OutlierResult(meta, rel);
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:38,代碼來源:DistanceStddevOutlier.java

示例10: getClassLabels

import de.lmu.ifi.dbs.elki.database.relation.Relation; //導入方法依賴的package包/類
/**
 * Retrieves all class labels within the database.
 * 
 * @param database the database to be scanned for class labels
 * @return a set comprising all class labels that are currently set in the
 *         database
 */
public static SortedSet<ClassLabel> getClassLabels(Relation<? extends ClassLabel> database) {
  SortedSet<ClassLabel> labels = new TreeSet<>();
  for(DBIDIter it = database.iterDBIDs(); it.valid(); it.advance()) {
    labels.add(database.get(it));
  }
  return labels;
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:15,代碼來源:DatabaseUtil.java

示例11: run

import de.lmu.ifi.dbs.elki.database.relation.Relation; //導入方法依賴的package包/類
/**
 * Run the algorithm
 *
 * @param database Database to process
 * @param relation Relation to process
 * @return Outlier result
 */
public OutlierResult run(Database database, Relation<O> relation) {
  DistanceQuery<O> distFunc = database.getDistanceQuery(relation, getDistanceFunction());
  KNNQuery<O> knnQuery = database.getKNNQuery(distFunc, k + 1, DatabaseQuery.HINT_HEAVY_USE);

  ModifiableDBIDs pruned = DBIDUtil.newHashSet();
  // KNNS
  WritableDataStore<ModifiableDBIDs> knns = DataStoreUtil.makeStorage(relation.getDBIDs(), DataStoreFactory.HINT_TEMP | DataStoreFactory.HINT_HOT, ModifiableDBIDs.class);
  // RNNS
  WritableDataStore<ModifiableDBIDs> rnns = DataStoreUtil.makeStorage(relation.getDBIDs(), DataStoreFactory.HINT_TEMP | DataStoreFactory.HINT_HOT, ModifiableDBIDs.class);
  // density
  WritableDoubleDataStore density = DataStoreUtil.makeDoubleStorage(relation.getDBIDs(), DataStoreFactory.HINT_TEMP | DataStoreFactory.HINT_HOT);
  // init knns and rnns
  for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
    knns.put(iditer, DBIDUtil.newArray());
    rnns.put(iditer, DBIDUtil.newArray());
  }

  computeNeighborhoods(relation, knnQuery, pruned, knns, rnns, density);

  // Calculate INFLO for any Object
  DoubleMinMax inflominmax = new DoubleMinMax();
  WritableDoubleDataStore inflos = DataStoreUtil.makeDoubleStorage(relation.getDBIDs(), DataStoreFactory.HINT_STATIC);
  // Note: this modifies knns, by adding rknns!
  computeINFLO(relation, pruned, knns, rnns, density, inflos, inflominmax);

  // Build result representation.
  DoubleRelation scoreResult = new MaterializedDoubleRelation("Influence Outlier Score", "inflo-outlier", inflos, relation.getDBIDs());
  OutlierScoreMeta scoreMeta = new QuotientOutlierScoreMeta(inflominmax.getMin(), inflominmax.getMax(), 0., Double.POSITIVE_INFINITY, 1.);
  return new OutlierResult(scoreMeta, scoreResult);
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:38,代碼來源:INFLO.java

示例12: initialAssignToNearestCluster

import de.lmu.ifi.dbs.elki.database.relation.Relation; //導入方法依賴的package包/類
/**
 * Reassign objects, but only if their bounds indicate it is necessary to do
 * so.
 *
 * @param relation Data
 * @param means Current means
 * @param sums Running sums of the new means
 * @param clusters Current clusters
 * @param assignment Cluster assignment
 * @param upper Upper bounds
 * @param lower Lower bounds
 * @return true when the object was reassigned
 */
private int initialAssignToNearestCluster(Relation<V> relation, double[][] means, double[][] sums, List<ModifiableDBIDs> clusters, WritableIntegerDataStore assignment, WritableDoubleDataStore upper, WritableDoubleDataStore lower) {
  assert (k == means.length);
  boolean issquared = distanceFunction.isSquared();
  for(DBIDIter it = relation.iterDBIDs(); it.valid(); it.advance()) {
    V fv = relation.get(it);
    // Find closest center, and distance to two closest centers
    double min1 = Double.POSITIVE_INFINITY, min2 = Double.POSITIVE_INFINITY;
    int minIndex = -1;
    for(int i = 0; i < k; i++) {
      double dist = distanceFunction.distance(fv, DoubleVector.wrap(means[i]));
      if(dist < min1) {
        minIndex = i;
        min2 = min1;
        min1 = dist;
      }
      else if(dist < min2) {
        min2 = dist;
      }
    }
    // make squared Euclidean a metric:
    if(issquared) {
      min1 = FastMath.sqrt(min1);
      min2 = FastMath.sqrt(min2);
    }
    ModifiableDBIDs newc = clusters.get(minIndex);
    newc.add(it);
    assignment.putInt(it, minIndex);
    double[] newmean = sums[minIndex];
    for(int d = 0; d < fv.getDimensionality(); d++) {
      newmean[d] += fv.doubleValue(d);
    }
    upper.putDouble(it, min1);
    lower.putDouble(it, min2);
  }
  return relation.size();
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:50,代碼來源:KMeansHamerly.java

示例13: run

import de.lmu.ifi.dbs.elki.database.relation.Relation; //導入方法依賴的package包/類
/**
 * Run the algorithm.
 * 
 * @param relation data relation.
 * @return
 */
public OutlierResult run(Relation<O> relation) {
  final int k1 = k + 1; // Query size
  final double perplexity = k / 3.;
  KNNQuery<O> knnq = relation.getKNNQuery(getDistanceFunction(), k1);
  final double logPerp = FastMath.log(perplexity);

  double[] p = new double[k + 10];
  FiniteProgress prog = LOG.isVerbose() ? new FiniteProgress("KNNSOS scores", relation.size(), LOG) : null;
  WritableDoubleDataStore scores = DataStoreUtil.makeDoubleStorage(relation.getDBIDs(), DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_DB, 1.);
  for(DBIDIter it = relation.iterDBIDs(); it.valid(); it.advance()) {
    KNNList knns = knnq.getKNNForDBID(it, k1);
    if(p.length < knns.size() + 1) {
      p = new double[knns.size() + 10];
    }
    final DoubleDBIDListIter ki = knns.iter();
    // Compute affinities
    SOS.computePi(it, ki, p, perplexity, logPerp);
    // Normalization factor:
    double s = SOS.sumOfProbabilities(it, ki, p);
    if(s > 0) {
      ISOS.nominateNeighbors(it, ki, p, 1. / s, scores);
    }
    LOG.incrementProcessed(prog);
  }
  LOG.ensureCompleted(prog);
  // Find minimum and maximum.
  DoubleMinMax minmax = ISOS.transformScores(scores, relation.getDBIDs(), logPerp, phi);
  DoubleRelation scoreres = new MaterializedDoubleRelation("kNN Stoachastic Outlier Selection", "knnsos-outlier", scores, relation.getDBIDs());
  OutlierScoreMeta meta = new ProbabilisticOutlierScore(minmax.getMin(), minmax.getMax(), 0.);
  return new OutlierResult(meta, scoreres);
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:38,代碼來源:KNNSOS.java

示例14: multipleAssignment

import de.lmu.ifi.dbs.elki.database.relation.Relation; //導入方法依賴的package包/類
/**
 * Assigns the objects of the database to multiple clusters according to their
 * labels.
 * 
 * @param data the database storing the objects
 * @return a mapping of labels to ids
 */
private HashMap<String, DBIDs> multipleAssignment(Relation<?> data) {
  HashMap<String, DBIDs> labelMap = new HashMap<>();

  for(DBIDIter iditer = data.iterDBIDs(); iditer.valid(); iditer.advance()) {
    String[] labels = data.get(iditer).toString().split(" ");
    for(String label : labels) {
      assign(labelMap, label, iditer);
    }
  }
  return labelMap;
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:19,代碼來源:ByLabelClustering.java

示例15: run

import de.lmu.ifi.dbs.elki.database.relation.Relation; //導入方法依賴的package包/類
@Override
public void run() {
  database.initialize();
  Relation<O> relation = database.getRelation(distance.getInputTypeRestriction());
  DistanceQuery<O> distanceQuery = database.getDistanceQuery(relation, distance);
  RangeQuery<O> rangeQ = database.getRangeQuery(distanceQuery, radius, DatabaseQuery.HINT_HEAVY_USE);

  LOG.verbose("Performing range queries with radius " + radius);

  // open file.
  try (RandomAccessFile file = new RandomAccessFile(out, "rw");
      FileChannel channel = file.getChannel();
      // and acquire a file write lock
      FileLock lock = channel.lock()) {
    // write magic header
    file.writeInt(RANGE_CACHE_MAGIC);
    // write the query radius.
    file.writeDouble(radius);

    int bufsize = 100 * 12 * 2 + 10; // Initial size, enough for 100.
    ByteBuffer buffer = ByteBuffer.allocateDirect(bufsize);

    FiniteProgress prog = LOG.isVerbose() ? new FiniteProgress("Computing range queries", relation.size(), LOG) : null;

    ModifiableDoubleDBIDList nn = DBIDUtil.newDistanceDBIDList();
    DoubleDBIDListIter ni = nn.iter();
    for(DBIDIter it = relation.iterDBIDs(); it.valid(); it.advance()) {
      nn.clear();
      rangeQ.getRangeForDBID(it, radius, nn);
      nn.sort();
      final int nnsize = nn.size();

      // Grow the buffer when needed:
      if(nnsize * 12 + 10 > bufsize) {
        while(nnsize * 12 + 10 > bufsize) {
          bufsize <<= 1;
        }
        LOG.verbose("Resizing buffer to " + bufsize + " to store " + nnsize + " results:");
        buffer = ByteBuffer.allocateDirect(bufsize);
      }

      buffer.clear();
      ByteArrayUtil.writeUnsignedVarint(buffer, it.internalGetIndex());
      ByteArrayUtil.writeUnsignedVarint(buffer, nnsize);
      int c = 0;
      for(ni.seek(0); ni.valid(); ni.advance(), c++) {
        ByteArrayUtil.writeUnsignedVarint(buffer, ni.internalGetIndex());
        buffer.putDouble(ni.doubleValue());
      }
      if(c != nn.size()) {
        throw new AbortException("Sizes did not agree. Cache is invalid.");
      }

      buffer.flip();
      channel.write(buffer);
      LOG.incrementProcessed(prog);
    }
    LOG.ensureCompleted(prog);
    lock.release();
  }
  catch(IOException e) {
    LOG.exception(e);
  }
  // FIXME: close!
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:66,代碼來源:CacheDoubleDistanceRangeQueries.java


注:本文中的de.lmu.ifi.dbs.elki.database.relation.Relation.iterDBIDs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。