use of de.lmu.ifi.dbs.elki.result.Result in project elki by elki-project.
the class EvaluationTabPanel method executeStep.
@Override
protected void executeStep() {
if (input.canRun() && !input.isComplete()) {
input.execute();
}
if (algs.canRun() && !algs.isComplete()) {
algs.execute();
}
if (!input.isComplete() || !algs.isComplete()) {
throw new AbortException("Input data not available.");
}
// Get the database and run the algorithms
Database database = input.getInputStep().getDatabase();
Result res = algs.getAlgorithmStep().getResult();
evals.runEvaluators(database.getHierarchy(), database);
basedOnResult = new WeakReference<Object>(res);
}
use of de.lmu.ifi.dbs.elki.result.Result 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.result.Result in project elki by elki-project.
the class RescaleMetaOutlierAlgorithm method run.
@Override
public OutlierResult run(Database database) {
Result innerresult = algorithm.run(database);
OutlierResult or = getOutlierResult(database.getHierarchy(), innerresult);
final DoubleRelation scores = or.getScores();
if (scaling instanceof OutlierScalingFunction) {
((OutlierScalingFunction) scaling).prepare(or);
}
WritableDoubleDataStore scaledscores = DataStoreUtil.makeDoubleStorage(scores.getDBIDs(), DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_STATIC);
DoubleMinMax minmax = new DoubleMinMax();
for (DBIDIter iditer = scores.iterDBIDs(); iditer.valid(); iditer.advance()) {
double val = scaling.getScaled(scores.doubleValue(iditer));
scaledscores.putDouble(iditer, val);
minmax.put(val);
}
OutlierScoreMeta meta = new BasicOutlierScoreMeta(minmax.getMin(), minmax.getMax(), scaling.getMin(), scaling.getMax());
DoubleRelation scoresult = new MaterializedDoubleRelation("Scaled Outlier", "scaled-outlier", scaledscores, scores.getDBIDs());
OutlierResult result = new OutlierResult(meta, scoresult);
result.addChildResult(innerresult);
return result;
}
use of de.lmu.ifi.dbs.elki.result.Result in project elki by elki-project.
the class VisualizationTree method findNewSiblings.
/**
* Process new result combinations of an object type1 (in first hierarchy) and
* any child of type2 (in second hierarchy)
*
* This is a bit painful, because we have two hierarchies with different
* types: results, and visualizations.
*
* @param context Context
* @param start Starting point
* @param type1 First type, in first hierarchy
* @param type2 Second type, in second hierarchy
* @param handler Handler
*/
public static <A extends Result, B extends VisualizationItem> void findNewSiblings(VisualizerContext context, Object start, Class<? super A> type1, Class<? super B> type2, BiConsumer<A, B> handler) {
// Search start in first hierarchy:
final ResultHierarchy hier = context.getHierarchy();
final Hierarchy<Object> vistree = context.getVisHierarchy();
if (start instanceof Result) {
// New result:
for (It<A> it1 = hier.iterDescendantsSelf((Result) start).filter(type1); it1.valid(); it1.advance()) {
final A result = it1.get();
// Existing visualization:
for (It<B> it2 = vistree.iterDescendantsSelf(context.getBaseResult()).filter(type2); it2.valid(); it2.advance()) {
handler.accept(result, it2.get());
}
}
}
// New visualization:
for (It<B> it2 = vistree.iterDescendantsSelf(start).filter(type2); it2.valid(); it2.advance()) {
final B vis = it2.get();
// Existing result:
for (It<A> it1 = hier.iterAll().filter(type1); it1.valid(); it1.advance()) {
handler.accept(it1.get(), vis);
}
}
}
use of de.lmu.ifi.dbs.elki.result.Result in project elki by elki-project.
the class EvaluateClustering method processNewResult.
@Override
public void processNewResult(ResultHierarchy hier, Result newResult) {
// We may just have added this result.
if (newResult instanceof Clustering && isReferenceResult((Clustering<?>) newResult)) {
return;
}
Database db = ResultUtil.findDatabase(hier);
List<Clustering<?>> crs = Clustering.getClusteringResults(newResult);
if (crs == null || crs.isEmpty()) {
return;
}
// Compute the reference clustering
Clustering<?> refc = null;
// Try to find an existing reference clustering (globally)
{
Collection<Clustering<?>> cs = ResultUtil.filterResults(hier, db, Clustering.class);
for (Clustering<?> test : cs) {
if (isReferenceResult(test)) {
refc = test;
break;
}
}
}
// Try to find an existing reference clustering (locally)
if (refc == null) {
Collection<Clustering<?>> cs = ResultUtil.filterResults(hier, newResult, Clustering.class);
for (Clustering<?> test : cs) {
if (isReferenceResult(test)) {
refc = test;
break;
}
}
}
if (refc == null) {
LOG.debug("Generating a new reference clustering.");
Result refres = referencealg.run(db);
List<Clustering<?>> refcrs = Clustering.getClusteringResults(refres);
if (refcrs.isEmpty()) {
LOG.warning("Reference algorithm did not return a clustering result!");
return;
}
if (refcrs.size() > 1) {
LOG.warning("Reference algorithm returned more than one result!");
}
refc = refcrs.get(0);
} else {
LOG.debug("Using existing clustering: " + refc.getLongName() + " " + refc.getShortName());
}
for (Clustering<?> c : crs) {
if (c == refc) {
continue;
}
evaluteResult(db, c, refc);
}
}
Aggregations