当前位置: 首页>>代码示例>>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;未经允许,请勿转载。