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();
}
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;
}
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;
}
Aggregations