/** * Joins in the given spatial database to each object its k-nearest neighbors. * * @param relation Relation to process * @return result */ public Relation<KNNList> run(Relation<V> relation) { DBIDs ids = relation.getDBIDs(); WritableDataStore<KNNList> knnLists = run(relation, ids); // Wrap as relation: return new MaterializedRelation<>("k nearest neighbors", "kNNs", TypeUtil.KNNLIST, knnLists, ids); }
/** * Builds a database for the derivator consisting of the ids in the specified * interval. * * @param relation the database storing the parameterization functions * @param ids the ids to build the database from * @return a database for the derivator consisting of the ids in the specified * interval */ private Database buildDerivatorDB(Relation<ParameterizationFunction> relation, DBIDs ids) { ProxyDatabase proxy = new ProxyDatabase(ids); int dim = dimensionality(relation); SimpleTypeInformation<DoubleVector> type = new VectorFieldTypeInformation<>(DoubleVector.FACTORY, dim); MaterializedRelation<DoubleVector> prep = new MaterializedRelation<>(type, ids); proxy.addRelation(prep); // Project for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) { prep.insert(iter, DoubleVector.wrap(relation.get(iter).getColumnVector())); } return proxy; }
@Override public void insert(DBIDRef id, O val) { assert (ids.contains(id)) : "Object not yet in DBIDs."; if(!(content instanceof WritableDataStore)) { throw new AbortException("Data is stored in a non-writable data store. Modifications are not possible."); } ((WritableDataStore<O>) content).put(id, val); for(It<Index> it = this.getHierarchy().iterDescendants(this).filter(Index.class); it.valid(); it.advance()) { if(!(it.get() instanceof DynamicIndex)) { throw new AbortException("A non-dynamic index was added to this database. Modifications are not allowed, unless this index is removed."); } ((DynamicIndex) it.get()).insert(id); } }
@Override public void insert(DBIDRef id, O val) { assert (ids.contains(id)) : "Object not yet in DBIDs."; if(!(content instanceof WritableDataStore)) { throw new AbortException("Data is stored in a non-writable data store. Modifications are not possible."); } ((WritableDataStore<O>) content).put(id, val); for(It<Index> it = this.getHierarchy().iterDescendants(this).filter(Index.class); it.valid(); it.advance()) { if(!(it.get() instanceof DynamicIndex)) { throw new AbortException("A non-dynamic index was added to this database. Modifications are not allowed, unless this index is removed."); } ((DynamicIndex) it.get()).insert(id); } }
private Relation<NumberVector> mockRelation(final int dimension) { return new MaterializedRelation<>(VectorFieldTypeInformation.typeRequest(NumberVector.class, dimension, dimension), DBIDUtil.EMPTYDBIDS); } }
/** * Builds a database for the derivator consisting of the ids in the specified * interval. * * @param relation the database storing the parameterization functions * @param ids the ids to build the database from * @return a database for the derivator consisting of the ids in the specified * interval */ private Database buildDerivatorDB(Relation<ParameterizationFunction> relation, DBIDs ids) { ProxyDatabase proxy = new ProxyDatabase(ids); int dim = dimensionality(relation); SimpleTypeInformation<DoubleVector> type = new VectorFieldTypeInformation<>(DoubleVector.FACTORY, dim); MaterializedRelation<DoubleVector> prep = new MaterializedRelation<>(type, ids); proxy.addRelation(prep); // Project for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) { DoubleVector v = new DoubleVector(relation.get(iter).getColumnVector().getArrayRef()); prep.insert(iter, v); } return proxy; }
@Override public void insert(DBIDRef id, O val) { assert(ids.contains(id)) : "Object not yet in DBIDs."; if(!(content instanceof WritableDataStore)) { throw new AbortException("Data is stored in a non-writable data store. Modifications are not possible."); } ((WritableDataStore<O>) content).put(id, val); for(Iter<Result> it = this.getHierarchy().iterDescendants(this); it.valid(); it.advance()) { if(!(it.get() instanceof DynamicIndex)) { if(it.get() instanceof Index) { throw new AbortException("A non-dynamic index was added to this database. Modifications are not allowed, unless this index is removed."); } continue; } ((DynamicIndex) it.get()).insert(id); } }
/** * Constructor * * @param ids Object IDs included * @param name The long name (for pretty printing) * @param shortname the short name (for filenames etc.) */ public ClusterOrder(String name, String shortname, ArrayModifiableDBIDs ids, WritableDoubleDataStore reachability, WritableDBIDDataStore predecessor) { super(name, shortname); this.ids = ids; this.reachability = reachability; this.predecessor = predecessor; addChildResult(new MaterializedDoubleRelation("Reachability distance", "reachdist", reachability, ids)); if(predecessor != null) { addChildResult(new MaterializedRelation<DBID>("OPTICS predecessor", "predecessor", TypeUtil.DBID, predecessor, ids)); } }
/** * Delete an objects values. * * @param id ID to delete */ @Override public void delete(DBIDRef id) { assert (!ids.contains(id)) : "Object still in DBIDs."; if(!(content instanceof WritableDataStore)) { throw new AbortException("Data is stored in a non-writable data store. Modifications are not possible."); } for(It<Index> it = this.getHierarchy().iterDescendants(this).filter(Index.class); it.valid(); it.advance()) { if(!(it.get() instanceof DynamicIndex)) { throw new AbortException("A non-dynamic index was added to this database. Modifications are not allowed, unless this index is removed."); } ((DynamicIndex) it.get()).delete(id); } ((WritableDataStore<O>) content).delete(id); }
/** * Constructor * * @param ids Object IDs included * @param name The long name (for pretty printing) * @param shortname the short name (for filenames etc.) */ public ClusterOrder(String name, String shortname, ArrayModifiableDBIDs ids, WritableDoubleDataStore reachability, WritableDBIDDataStore predecessor) { super(name, shortname); this.ids = ids; this.reachability = reachability; this.predecessor = predecessor; addChildResult(new MaterializedDoubleRelation("Reachability distance", "reachdist", reachability, ids)); if(predecessor != null) { addChildResult(new MaterializedRelation<DBID>("OPTICS predecessor", "predecessor", TypeUtil.DBID, predecessor, ids)); } }
/** * Delete an objects values. * * @param id ID to delete */ @Override public void delete(DBIDRef id) { assert (!ids.contains(id)) : "Object still in DBIDs."; if(!(content instanceof WritableDataStore)) { throw new AbortException("Data is stored in a non-writable data store. Modifications are not possible."); } for(It<Index> it = this.getHierarchy().iterDescendants(this).filter(Index.class); it.valid(); it.advance()) { if(!(it.get() instanceof DynamicIndex)) { throw new AbortException("A non-dynamic index was added to this database. Modifications are not allowed, unless this index is removed."); } ((DynamicIndex) it.get()).delete(id); } ((WritableDataStore<O>) content).delete(id); }
/** * Constructor * * @param ids Object IDs included * @param name The long name (for pretty printing) * @param shortname the short name (for filenames etc.) */ public ClusterOrder(String name, String shortname, ArrayModifiableDBIDs ids, WritableDoubleDataStore reachability, WritableDBIDDataStore predecessor) { super(name, shortname); this.ids = ids; this.reachability = reachability; this.predecessor = predecessor; addChildResult(new MaterializedDoubleRelation("Reachability distance", "reachdist", reachability, ids)); if(predecessor != null) { addChildResult(new MaterializedRelation<DBID>("OPTICS predecessor", "predecessor", TypeUtil.DBID, predecessor, ids)); } }
/** * Delete an objects values. * * @param id ID to delete */ @Override public void delete(DBIDRef id) { assert(!ids.contains(id)) : "Object still in DBIDs."; if(!(content instanceof WritableDataStore)) { throw new AbortException("Data is stored in a non-writable data store. Modifications are not possible."); } for(Iter<Result> it = this.getHierarchy().iterDescendants(this); it.valid(); it.advance()) { if(!(it.get() instanceof DynamicIndex)) { if(it.get() instanceof Index) { throw new AbortException("A non-dynamic index was added to this database. Modifications are not allowed, unless this index is removed."); } continue; } ((DynamicIndex) it.get()).delete(id); } ((WritableDataStore<O>) content).delete(id); }
/** * Add a new representation for the given meta. * * @param meta meta data * @return new representation */ private Relation<?> addNewRelation(SimpleTypeInformation<?> meta) { @SuppressWarnings("unchecked") SimpleTypeInformation<Object> ometa = (SimpleTypeInformation<Object>) meta; Relation<?> relation = new MaterializedRelation<>(ometa, ids); relations.add(relation); getHierarchy().add(this, relation); // Try to add indexes where appropriate for(IndexFactory<?> factory : indexFactories) { if(factory.getInputTypeRestriction().isAssignableFromType(meta)) { @SuppressWarnings("unchecked") final IndexFactory<Object> ofact = (IndexFactory<Object>) factory; @SuppressWarnings("unchecked") final Relation<Object> orep = (Relation<Object>) relation; Index index = ofact.instantiate(orep); index.initialize(); getHierarchy().add(relation, index); } } return relation; }
/** * Constructor * * @param ids Object IDs included * @param name The long name (for pretty printing) * @param shortname the short name (for filenames etc.) */ public ClusterOrder(DBIDs ids, String name, String shortname) { super(name, shortname); this.ids = DBIDUtil.newArray(ids.size()); reachability = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_DB | DataStoreFactory.HINT_HOT, Double.POSITIVE_INFINITY); predecessor = DataStoreUtil.makeDBIDStorage(ids, DataStoreFactory.HINT_HOT); addChildResult(new MaterializedDoubleRelation("Reachability distance", "reachdist", reachability, ids)); addChildResult(new MaterializedRelation<DBID>("OPTICS predecessor", "predecessor", TypeUtil.DBID, predecessor, ids)); }
/** * Add a new representation for the given meta. * * @param meta meta data * @return new representation */ private Relation<?> addNewRelation(SimpleTypeInformation<?> meta) { @SuppressWarnings("unchecked") SimpleTypeInformation<Object> ometa = (SimpleTypeInformation<Object>) meta; Relation<?> relation = new MaterializedRelation<>(ometa, ids); relations.add(relation); getHierarchy().add(this, relation); // Try to add indexes where appropriate for(IndexFactory<?, ?> factory : indexFactories) { if(factory.getInputTypeRestriction().isAssignableFromType(meta)) { @SuppressWarnings("unchecked") final IndexFactory<Object, ?> ofact = (IndexFactory<Object, ?>) factory; @SuppressWarnings("unchecked") final Relation<Object> orep = (Relation<Object>) relation; Index index = ofact.instantiate(orep); index.initialize(); getHierarchy().add(relation, index); } } return relation; }
/** * Constructor * * @param ids Object IDs included * @param name The long name (for pretty printing) * @param shortname the short name (for filenames etc.) */ public ClusterOrder(DBIDs ids, String name, String shortname) { super(name, shortname); this.ids = DBIDUtil.newArray(ids.size()); reachability = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_DB | DataStoreFactory.HINT_HOT, Double.POSITIVE_INFINITY); predecessor = DataStoreUtil.makeDBIDStorage(ids, DataStoreFactory.HINT_HOT); addChildResult(new MaterializedDoubleRelation("Reachability distance", "reachdist", reachability, ids)); addChildResult(new MaterializedRelation<DBID>("OPTICS predecessor", "predecessor", TypeUtil.DBID, predecessor, ids)); }
/** * Add a new representation for the given meta. * * @param meta meta data * @return new representation */ private Relation<?> addNewRelation(SimpleTypeInformation<?> meta) { @SuppressWarnings("unchecked") SimpleTypeInformation<Object> ometa = (SimpleTypeInformation<Object>) meta; Relation<?> relation = new MaterializedRelation<>(ometa, ids); relations.add(relation); getHierarchy().add(this, relation); // Try to add indexes where appropriate for(IndexFactory<?> factory : indexFactories) { if(factory.getInputTypeRestriction().isAssignableFromType(meta)) { @SuppressWarnings("unchecked") final IndexFactory<Object> ofact = (IndexFactory<Object>) factory; @SuppressWarnings("unchecked") final Relation<Object> orep = (Relation<Object>) relation; Index index = ofact.instantiate(orep); index.initialize(); getHierarchy().add(relation, index); } } return relation; }
/** * Constructor * * @param ids Object IDs included * @param name The long name (for pretty printing) * @param shortname the short name (for filenames etc.) */ public ClusterOrder(DBIDs ids, String name, String shortname) { super(name, shortname); this.ids = DBIDUtil.newArray(ids.size()); reachability = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_DB | DataStoreFactory.HINT_HOT, Double.POSITIVE_INFINITY); predecessor = DataStoreUtil.makeDBIDStorage(ids, DataStoreFactory.HINT_HOT); addChildResult(new MaterializedDoubleRelation("Reachability distance", "reachdist", reachability, ids)); addChildResult(new MaterializedRelation<DBID>("OPTICS predecessor", "predecessor", TypeUtil.DBID, predecessor, ids)); }
/** * Preprocess the dataset, precomputing the parameterization functions. * * @param db Database * @param vrel Vector relation * @return Preprocessed relation */ private Relation<ParameterizationFunction> preprocess(Database db, Relation<V> vrel) { DBIDs ids = vrel.getDBIDs(); SimpleTypeInformation<ParameterizationFunction> type = new SimpleTypeInformation<>(ParameterizationFunction.class); WritableDataStore<ParameterizationFunction> prep = DataStoreUtil.makeStorage(ids, DataStoreFactory.HINT_HOT, ParameterizationFunction.class); // Project for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) { prep.put(iter, new ParameterizationFunction(vrel.get(iter))); } return new MaterializedRelation<>(type, ids, null, prep); }