Search in sources :

Example 1 with SingleObjectBundle

use of de.lmu.ifi.dbs.elki.datasource.bundle.SingleObjectBundle in project elki by elki-project.

the class TextWriter method printObject.

private void printObject(TextWriterStream out, Database db, final DBIDRef objID, List<Relation<?>> ra) throws IOException {
    SingleObjectBundle bundle = db.getBundle(objID);
    // Write database element itself.
    for (int i = 0; i < bundle.metaLength(); i++) {
        Object obj = bundle.data(i);
        if (obj != null) {
            TextWriterWriterInterface<?> owriter = out.getWriterFor(obj);
            if (owriter == null) {
                throw new IOException("No handler for database object itself: " + obj.getClass().getSimpleName());
            }
            String lbl = null;
            // TODO: ugly compatibility hack...
            if (TypeUtil.DBID.isAssignableFromType(bundle.meta(i))) {
                lbl = "ID";
            }
            owriter.writeObject(out, lbl, obj);
        }
    }
    Collection<Relation<?>> dbrels = db.getRelations();
    // print the annotations
    if (ra != null) {
        for (Relation<?> a : ra) {
            // Avoid duplicated output.
            if (dbrels.contains(a)) {
                continue;
            }
            String label = a.getShortName();
            Object value = a.get(objID);
            if (value == null) {
                continue;
            }
            TextWriterWriterInterface<?> writer = out.getWriterFor(value);
            if (writer == null) {
                // Ignore
                continue;
            }
            writer.writeObject(out, label, value);
        }
    }
    out.flush();
}
Also used : Relation(de.lmu.ifi.dbs.elki.database.relation.Relation) SingleObjectBundle(de.lmu.ifi.dbs.elki.datasource.bundle.SingleObjectBundle) IOException(java.io.IOException)

Example 2 with SingleObjectBundle

use of de.lmu.ifi.dbs.elki.datasource.bundle.SingleObjectBundle in project elki by elki-project.

the class HashmapDatabase method delete.

/**
 * Removes the object from the database (by calling {@link #doDelete(DBIDRef)}
 * ) and indexes and fires a deletion event.
 *
 * {@inheritDoc}
 */
@Override
public SingleObjectBundle delete(DBIDRef id) {
    // Prepare bundle to return
    SingleObjectBundle bundle = new SingleObjectBundle();
    for (Relation<?> relation : relations) {
        bundle.append(relation.getDataTypeInformation(), relation.get(id));
    }
    doDelete(id);
    // fire deletion event
    eventManager.fireObjectRemoved(id);
    return bundle;
}
Also used : SingleObjectBundle(de.lmu.ifi.dbs.elki.datasource.bundle.SingleObjectBundle)

Example 3 with SingleObjectBundle

use of de.lmu.ifi.dbs.elki.datasource.bundle.SingleObjectBundle in project elki by elki-project.

the class DiSHPreferenceVectorIndex method determinePreferenceVectorByApriori.

/**
 * Determines the preference vector with the apriori strategy.
 *
 * @param relation the database storing the objects
 * @param neighborIDs the list of ids of the neighbors in each dimension
 * @param msg a string buffer for debug messages
 * @return the preference vector
 */
private long[] determinePreferenceVectorByApriori(Relation<V> relation, ModifiableDBIDs[] neighborIDs, StringBuilder msg) {
    int dimensionality = neighborIDs.length;
    // database for apriori
    UpdatableDatabase apriori_db = new HashmapDatabase();
    SimpleTypeInformation<?> bitmeta = VectorFieldTypeInformation.typeRequest(BitVector.class, dimensionality, dimensionality);
    for (DBIDIter it = relation.iterDBIDs(); it.valid(); it.advance()) {
        long[] bits = BitsUtil.zero(dimensionality);
        boolean allFalse = true;
        for (int d = 0; d < dimensionality; d++) {
            if (neighborIDs[d].contains(it)) {
                BitsUtil.setI(bits, d);
                allFalse = false;
            }
        }
        if (!allFalse) {
            SingleObjectBundle oaa = new SingleObjectBundle();
            oaa.append(bitmeta, new BitVector(bits, dimensionality));
            apriori_db.insert(oaa);
        }
    }
    APRIORI apriori = new APRIORI(minpts);
    FrequentItemsetsResult aprioriResult = apriori.run(apriori_db);
    // result of apriori
    List<Itemset> frequentItemsets = aprioriResult.getItemsets();
    if (msg != null) {
        msg.append("\n Frequent itemsets: ").append(frequentItemsets);
    }
    int maxSupport = 0;
    int maxCardinality = 0;
    long[] preferenceVector = BitsUtil.zero(dimensionality);
    for (Itemset itemset : frequentItemsets) {
        if ((maxCardinality < itemset.length()) || (maxCardinality == itemset.length() && maxSupport == itemset.getSupport())) {
            preferenceVector = Itemset.toBitset(itemset, BitsUtil.zero(dimensionality));
            maxCardinality = itemset.length();
            maxSupport = itemset.getSupport();
        }
    }
    if (msg != null) {
        // 
        msg.append("\n preference ").append(// 
        BitsUtil.toStringLow(preferenceVector, dimensionality)).append('\n');
        LOG.debugFine(msg.toString());
    }
    return preferenceVector;
}
Also used : UpdatableDatabase(de.lmu.ifi.dbs.elki.database.UpdatableDatabase) BitVector(de.lmu.ifi.dbs.elki.data.BitVector) HashmapDatabase(de.lmu.ifi.dbs.elki.database.HashmapDatabase) SingleObjectBundle(de.lmu.ifi.dbs.elki.datasource.bundle.SingleObjectBundle) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter) FrequentItemsetsResult(de.lmu.ifi.dbs.elki.result.FrequentItemsetsResult) Itemset(de.lmu.ifi.dbs.elki.algorithm.itemsetmining.Itemset) APRIORI(de.lmu.ifi.dbs.elki.algorithm.itemsetmining.APRIORI)

Aggregations

SingleObjectBundle (de.lmu.ifi.dbs.elki.datasource.bundle.SingleObjectBundle)3 APRIORI (de.lmu.ifi.dbs.elki.algorithm.itemsetmining.APRIORI)1 Itemset (de.lmu.ifi.dbs.elki.algorithm.itemsetmining.Itemset)1 BitVector (de.lmu.ifi.dbs.elki.data.BitVector)1 HashmapDatabase (de.lmu.ifi.dbs.elki.database.HashmapDatabase)1 UpdatableDatabase (de.lmu.ifi.dbs.elki.database.UpdatableDatabase)1 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)1 Relation (de.lmu.ifi.dbs.elki.database.relation.Relation)1 FrequentItemsetsResult (de.lmu.ifi.dbs.elki.result.FrequentItemsetsResult)1 IOException (java.io.IOException)1