Search in sources :

Example 6 with Result

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);
}
Also used : Database(de.lmu.ifi.dbs.elki.database.Database) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException) Result(de.lmu.ifi.dbs.elki.result.Result)

Example 7 with Result

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);
}
Also used : WritableDoubleDataStore(de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore) FiniteProgress(de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress) OutlierResult(de.lmu.ifi.dbs.elki.result.outlier.OutlierResult) ArrayList(java.util.ArrayList) Algorithm(de.lmu.ifi.dbs.elki.algorithm.Algorithm) OutlierAlgorithm(de.lmu.ifi.dbs.elki.algorithm.outlier.OutlierAlgorithm) AbstractAlgorithm(de.lmu.ifi.dbs.elki.algorithm.AbstractAlgorithm) DoubleRelation(de.lmu.ifi.dbs.elki.database.relation.DoubleRelation) MaterializedDoubleRelation(de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation) BasicOutlierScoreMeta(de.lmu.ifi.dbs.elki.result.outlier.BasicOutlierScoreMeta) OutlierScoreMeta(de.lmu.ifi.dbs.elki.result.outlier.OutlierScoreMeta) BasicOutlierScoreMeta(de.lmu.ifi.dbs.elki.result.outlier.BasicOutlierScoreMeta) Result(de.lmu.ifi.dbs.elki.result.Result) OutlierResult(de.lmu.ifi.dbs.elki.result.outlier.OutlierResult) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter) DoubleMinMax(de.lmu.ifi.dbs.elki.math.DoubleMinMax) ModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs) ArrayList(java.util.ArrayList) List(java.util.List) MaterializedDoubleRelation(de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation)

Example 8 with Result

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;
}
Also used : DoubleMinMax(de.lmu.ifi.dbs.elki.math.DoubleMinMax) WritableDoubleDataStore(de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore) OutlierScalingFunction(de.lmu.ifi.dbs.elki.utilities.scaling.outlier.OutlierScalingFunction) OutlierResult(de.lmu.ifi.dbs.elki.result.outlier.OutlierResult) DoubleRelation(de.lmu.ifi.dbs.elki.database.relation.DoubleRelation) MaterializedDoubleRelation(de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation) BasicOutlierScoreMeta(de.lmu.ifi.dbs.elki.result.outlier.BasicOutlierScoreMeta) OutlierScoreMeta(de.lmu.ifi.dbs.elki.result.outlier.OutlierScoreMeta) BasicOutlierScoreMeta(de.lmu.ifi.dbs.elki.result.outlier.BasicOutlierScoreMeta) MaterializedDoubleRelation(de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation) Result(de.lmu.ifi.dbs.elki.result.Result) OutlierResult(de.lmu.ifi.dbs.elki.result.outlier.OutlierResult) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 9 with 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);
        }
    }
}
Also used : ResultHierarchy(de.lmu.ifi.dbs.elki.result.ResultHierarchy) Result(de.lmu.ifi.dbs.elki.result.Result)

Example 10 with Result

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);
    }
}
Also used : Database(de.lmu.ifi.dbs.elki.database.Database) Collection(java.util.Collection) ByLabelOrAllInOneClustering(de.lmu.ifi.dbs.elki.algorithm.clustering.trivial.ByLabelOrAllInOneClustering) Clustering(de.lmu.ifi.dbs.elki.data.Clustering) Result(de.lmu.ifi.dbs.elki.result.Result) EvaluationResult(de.lmu.ifi.dbs.elki.result.EvaluationResult)

Aggregations

Result (de.lmu.ifi.dbs.elki.result.Result)11 Database (de.lmu.ifi.dbs.elki.database.Database)6 AbstractClusterAlgorithmTest (de.lmu.ifi.dbs.elki.algorithm.clustering.AbstractClusterAlgorithmTest)3 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)3 ResultHierarchy (de.lmu.ifi.dbs.elki.result.ResultHierarchy)3 Test (org.junit.Test)3 AbstractAlgorithm (de.lmu.ifi.dbs.elki.algorithm.AbstractAlgorithm)2 Algorithm (de.lmu.ifi.dbs.elki.algorithm.Algorithm)2 HDBSCANLinearMemory (de.lmu.ifi.dbs.elki.algorithm.clustering.hierarchical.HDBSCANLinearMemory)2 Clustering (de.lmu.ifi.dbs.elki.data.Clustering)2 WritableDoubleDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore)2 DoubleRelation (de.lmu.ifi.dbs.elki.database.relation.DoubleRelation)2 MaterializedDoubleRelation (de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation)2 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)2 DoubleMinMax (de.lmu.ifi.dbs.elki.math.DoubleMinMax)2 BasicResult (de.lmu.ifi.dbs.elki.result.BasicResult)2 EvaluationResult (de.lmu.ifi.dbs.elki.result.EvaluationResult)2 BasicOutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.BasicOutlierScoreMeta)2 OutlierResult (de.lmu.ifi.dbs.elki.result.outlier.OutlierResult)2 OutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.OutlierScoreMeta)2