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


Java RelationUtil.getNumberVectorFactory方法代碼示例

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


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

示例1: applyPrescaling

import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //導入方法依賴的package包/類
/**
 * Prescale each vector (except when in {@code skip}) with the given scaling
 * function.
 *
 * @param scaling Scaling function
 * @param relation Relation to read
 * @param skip DBIDs to pass unmodified
 * @return New relation
 */
public static Relation<NumberVector> applyPrescaling(ScalingFunction scaling, Relation<NumberVector> relation, DBIDs skip) {
  if(scaling == null) {
    return relation;
  }
  NumberVector.Factory<NumberVector> factory = RelationUtil.getNumberVectorFactory(relation);
  DBIDs ids = relation.getDBIDs();
  WritableDataStore<NumberVector> contents = DataStoreUtil.makeStorage(ids, DataStoreFactory.HINT_HOT, NumberVector.class);
  for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
    NumberVector v = relation.get(iter);
    double[] raw = v.toArray();
    if(!skip.contains(iter)) {
      applyScaling(raw, scaling);
    }
    contents.put(iter, factory.newNumberVector(raw, ArrayLikeUtil.DOUBLEARRAYADAPTER));
  }
  return new MaterializedRelation<>(relation.getDataTypeInformation(), ids, "rescaled", contents);
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:27,代碼來源:GreedyEnsembleExperiment.java

示例2: run

import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //導入方法依賴的package包/類
/**
 * Computes quantitatively linear dependencies among the attributes of the
 * given database based on a linear correlation PCA.
 *
 * @param database the database to run this DependencyDerivator on
 * @param relation the relation to use
 * @return the CorrelationAnalysisSolution computed by this
 *         DependencyDerivator
 */
public CorrelationAnalysisSolution<V> run(Database database, Relation<V> relation) {
  if(LOG.isVerbose()) {
    LOG.verbose("retrieving database objects...");
  }
  Centroid centroid = Centroid.make(relation, relation.getDBIDs());
  NumberVector.Factory<V> factory = RelationUtil.getNumberVectorFactory(relation);
  V centroidDV = factory.newNumberVector(centroid.getArrayRef());
  DBIDs ids;
  if(this.sampleSize > 0) {
    if(randomsample) {
      ids = DBIDUtil.randomSample(relation.getDBIDs(), this.sampleSize, RandomFactory.DEFAULT);
    }
    else {
      DistanceQuery<V> distanceQuery = database.getDistanceQuery(relation, getDistanceFunction());
      KNNList queryResults = database.getKNNQuery(distanceQuery, this.sampleSize)//
          .getKNNForObject(centroidDV, this.sampleSize);
      ids = DBIDUtil.newHashSet(queryResults);
    }
  }
  else {
    ids = relation.getDBIDs();
  }

  return generateModel(relation, ids, centroid.getArrayRef());
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:35,代碼來源:DependencyDerivator.java

示例3: runOnlineLOF

import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //導入方法依賴的package包/類
/**
 * Run OnlineLOF (with insertions and removals) on database.
 */
@SuppressWarnings("unchecked")
private static OutlierResult runOnlineLOF(UpdatableDatabase db) {
  Relation<DoubleVector> rep = db.getRelation(TypeUtil.DOUBLE_VECTOR_FIELD);

  // setup algorithm
  OnlineLOF<DoubleVector> lof = new OnlineLOF<>(k, k, neighborhoodDistanceFunction, reachabilityDistanceFunction);

  // run OnlineLOF on database
  OutlierResult result = lof.run(db);

  // insert new objects
  ArrayList<DoubleVector> insertions = new ArrayList<>();
  NumberVector.Factory<DoubleVector> o = RelationUtil.getNumberVectorFactory(rep);
  int dim = RelationUtil.dimensionality(rep);
  Random random = new Random(seed);
  for(int i = 0; i < size; i++) {
    DoubleVector obj = VectorUtil.randomVector(o, dim, random);
    insertions.add(obj);
  }
  DBIDs deletions = db.insert(MultipleObjectsBundle.makeSimple(rep.getDataTypeInformation(), insertions));

  // delete objects
  db.delete(deletions);
  return result;
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:29,代碼來源:OnlineLOFTest.java

示例4: testPreprocessor

import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //導入方法依賴的package包/類
@Test
public void testPreprocessor() {
  UpdatableDatabase db;
  // get database
  try (InputStream is = AbstractSimpleAlgorithmTest.open(dataset)) {
    ListParameterization params = new ListParameterization();
    // Setup parser and data loading
    NumberVectorLabelParser<DoubleVector> parser = new NumberVectorLabelParser<>(DoubleVector.FACTORY);
    InputStreamDatabaseConnection dbc = new InputStreamDatabaseConnection(is, new ArrayList<>(), parser);

    // We want to allow the use of indexes via "params"
    params.addParameter(AbstractDatabase.Parameterizer.DATABASE_CONNECTION_ID, dbc);
    db = ClassGenericsUtil.parameterizeOrAbort(HashmapDatabase.class, params);
    db.initialize();
  }
  catch(IOException e) {
    fail("Test data " + dataset + " not found.");
    return;
  }

  Relation<DoubleVector> rep = db.getRelation(TypeUtil.DOUBLE_VECTOR_FIELD);
  DistanceQuery<DoubleVector> distanceQuery = db.getDistanceQuery(rep, EuclideanDistanceFunction.STATIC);

  // verify data set size.
  assertEquals("Data set size doesn't match parameters.", shoulds, rep.size());

  // get linear queries
  LinearScanDistanceKNNQuery<DoubleVector> lin_knn_query = new LinearScanDistanceKNNQuery<>(distanceQuery);
  LinearScanRKNNQuery<DoubleVector> lin_rknn_query = new LinearScanRKNNQuery<>(distanceQuery, lin_knn_query, k);

  // get preprocessed queries
  ListParameterization config = new ListParameterization();
  config.addParameter(MaterializeKNNPreprocessor.Factory.DISTANCE_FUNCTION_ID, distanceQuery.getDistanceFunction());
  config.addParameter(MaterializeKNNPreprocessor.Factory.K_ID, k);
  MaterializeKNNAndRKNNPreprocessor<DoubleVector> preproc = new MaterializeKNNAndRKNNPreprocessor<>(rep, distanceQuery.getDistanceFunction(), k);
  KNNQuery<DoubleVector> preproc_knn_query = preproc.getKNNQuery(distanceQuery, k);
  RKNNQuery<DoubleVector> preproc_rknn_query = preproc.getRKNNQuery(distanceQuery);
  // add as index
  db.getHierarchy().add(rep, preproc);
  assertFalse("Preprocessor knn query class incorrect.", preproc_knn_query instanceof LinearScanDistanceKNNQuery);
  assertFalse("Preprocessor rknn query class incorrect.", preproc_rknn_query instanceof LinearScanDistanceKNNQuery);

  // test queries
  testKNNQueries(rep, lin_knn_query, preproc_knn_query, k);
  testRKNNQueries(rep, lin_rknn_query, preproc_rknn_query, k);
  // also test partial queries, forward only
  testKNNQueries(rep, lin_knn_query, preproc_knn_query, k / 2);

  // insert new objects
  List<DoubleVector> insertions = new ArrayList<>();
  NumberVector.Factory<DoubleVector> o = RelationUtil.getNumberVectorFactory(rep);
  int dim = RelationUtil.dimensionality(rep);
  Random random = new Random(seed);
  for(int i = 0; i < updatesize; i++) {
    DoubleVector obj = VectorUtil.randomVector(o, dim, random);
    insertions.add(obj);
  }
  // System.out.println("Insert " + insertions);
  DBIDs deletions = db.insert(MultipleObjectsBundle.makeSimple(rep.getDataTypeInformation(), insertions));

  // test queries
  testKNNQueries(rep, lin_knn_query, preproc_knn_query, k);
  testRKNNQueries(rep, lin_rknn_query, preproc_rknn_query, k);

  // delete objects
  // System.out.println("Delete " + deletions);
  db.delete(deletions);

  // test queries
  testKNNQueries(rep, lin_knn_query, preproc_knn_query, k);
  testRKNNQueries(rep, lin_rknn_query, preproc_rknn_query, k);
}
 
開發者ID:elki-project,項目名稱:elki,代碼行數:73,代碼來源:MaterializedKNNAndRKNNPreprocessorTest.java


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