use of de.lmu.ifi.dbs.elki.algorithm.Algorithm in project elki by elki-project.
the class SimpleOutlierEnsemble method run.
@Override
public OutlierResult run(Database database) throws IllegalStateException {
int num = algorithms.size();
// Run inner outlier algorithms
ModifiableDBIDs ids = DBIDUtil.newHashSet();
ArrayList<OutlierResult> results = new ArrayList<>(num);
{
FiniteProgress prog = LOG.isVerbose() ? new FiniteProgress("Inner outlier algorithms", num, LOG) : null;
for (Algorithm alg : algorithms) {
Result res = alg.run(database);
List<OutlierResult> ors = OutlierResult.getOutlierResults(res);
for (OutlierResult or : ors) {
results.add(or);
ids.addDBIDs(or.getScores().getDBIDs());
}
LOG.incrementProcessed(prog);
}
LOG.ensureCompleted(prog);
}
// Combine
WritableDoubleDataStore sumscore = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_STATIC);
DoubleMinMax minmax = new DoubleMinMax();
{
FiniteProgress cprog = LOG.isVerbose() ? new FiniteProgress("Combining results", ids.size(), LOG) : null;
for (DBIDIter id = ids.iter(); id.valid(); id.advance()) {
double[] scores = new double[num];
int i = 0;
for (OutlierResult r : results) {
double score = r.getScores().doubleValue(id);
if (!Double.isNaN(score)) {
scores[i] = score;
i++;
} else {
LOG.warning("DBID " + id + " was not given a score by result " + r);
}
}
if (i > 0) {
// Shrink array if necessary.
if (i < scores.length) {
scores = Arrays.copyOf(scores, i);
}
double combined = voting.combine(scores);
sumscore.putDouble(id, combined);
minmax.put(combined);
} else {
LOG.warning("DBID " + id + " was not given any score at all.");
}
LOG.incrementProcessed(cprog);
}
LOG.ensureCompleted(cprog);
}
OutlierScoreMeta meta = new BasicOutlierScoreMeta(minmax.getMin(), minmax.getMax());
DoubleRelation scores = new MaterializedDoubleRelation("Simple Outlier Ensemble", "ensemble-outlier", sumscore, ids);
return new OutlierResult(meta, scores);
}
use of de.lmu.ifi.dbs.elki.algorithm.Algorithm in project elki by elki-project.
the class AlgorithmStep method runAlgorithms.
/**
* Run algorithms.
*
* @param database Database
* @return Algorithm result
*/
public Result runAlgorithms(Database database) {
ResultHierarchy hier = database.getHierarchy();
if (LOG.isStatistics()) {
boolean first = true;
for (It<Index> it = hier.iterDescendants(database).filter(Index.class); it.valid(); it.advance()) {
if (first) {
LOG.statistics("Index statistics before running algorithms:");
first = false;
}
it.get().logStatistics();
}
}
stepresult = new BasicResult("Algorithm Step", "algorithm-step");
for (Algorithm algorithm : algorithms) {
Thread.currentThread().setName(algorithm.toString());
Duration duration = LOG.isStatistics() ? LOG.newDuration(algorithm.getClass().getName() + ".runtime").begin() : null;
Result res = algorithm.run(database);
if (duration != null) {
LOG.statistics(duration.end());
}
if (LOG.isStatistics()) {
boolean first = true;
for (It<Index> it = hier.iterDescendants(database).filter(Index.class); it.valid(); it.advance()) {
if (first) {
LOG.statistics("Index statistics after running algorithm " + algorithm.toString() + ":");
first = false;
}
it.get().logStatistics();
}
}
if (res != null) {
// Make sure the result is attached, but usually this is a noop:
hier.add(database, res);
}
}
return stepresult;
}
Aggregations