use of de.lmu.ifi.dbs.elki.algorithm.itemsetmining.Itemset in project elki by elki-project.
the class FrequentItemsetsResult method writeToText.
@Override
public void writeToText(TextWriterStream out, String label) {
StringBuilder buf = new StringBuilder();
for (Itemset itemset : itemsets) {
// Reuse
buf.setLength(0);
out.inlinePrintNoQuotes(itemset.appendTo(buf, meta));
out.flush();
}
}
use of de.lmu.ifi.dbs.elki.algorithm.itemsetmining.Itemset 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