Search in sources :

Example 81 with AbortException

use of de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException in project elki by elki-project.

the class CachedDoubleDistanceKNNPreprocessor method preprocess.

@Override
protected void preprocess() {
    createStorage();
    // open file.
    try (RandomAccessFile file = new RandomAccessFile(filename, "rw");
        FileChannel channel = file.getChannel()) {
        // check magic header
        int header = file.readInt();
        if (header != CacheDoubleDistanceKNNLists.KNN_CACHE_MAGIC) {
            throw new AbortException("Cache magic number does not match.");
        }
        MappedByteBuffer buffer = channel.map(MapMode.READ_ONLY, 4, file.length() - 4);
        for (DBIDIter iter = relation.iterDBIDs(); iter.valid(); iter.advance()) {
            int dbid = ByteArrayUtil.readUnsignedVarint(buffer);
            int nnsize = ByteArrayUtil.readUnsignedVarint(buffer);
            if (nnsize < k) {
                throw new AbortException("kNN cache contains fewer than k objects!");
            }
            // FIXME: avoid the KNNHeap to KNNList roundtrip.
            // FIXME: use a DBIDVar instead of importInteger.
            KNNHeap knn = DBIDUtil.newHeap(k);
            for (int i = 0; i < nnsize; i++) {
                int nid = ByteArrayUtil.readUnsignedVarint(buffer);
                double dist = buffer.getDouble();
                knn.insert(dist, DBIDUtil.importInteger(nid));
            }
            storage.put(DBIDUtil.importInteger(dbid), knn.toKNNList());
        }
        if (buffer.hasRemaining()) {
            LOG.warning("kNN cache has " + buffer.remaining() + " bytes remaining!");
        }
    } catch (IOException e) {
        throw new AbortException("I/O error in loading kNN cache: " + e.getMessage(), e);
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) MappedByteBuffer(java.nio.MappedByteBuffer) FileChannel(java.nio.channels.FileChannel) IOException(java.io.IOException) KNNHeap(de.lmu.ifi.dbs.elki.database.ids.KNNHeap) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 82 with AbortException

use of de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException in project elki by elki-project.

the class LogRankingPseudoOutlierScaling method prepare.

@Override
public void prepare(OutlierResult or) {
    // collect all outlier scores
    DoubleRelation oscores = or.getScores();
    scores = new double[oscores.size()];
    int pos = 0;
    if (or.getOutlierMeta() instanceof InvertedOutlierScoreMeta) {
        inverted = true;
    }
    for (DBIDIter iditer = oscores.iterDBIDs(); iditer.valid(); iditer.advance()) {
        scores[pos] = oscores.doubleValue(iditer);
        pos++;
    }
    if (pos != oscores.size()) {
        throw new AbortException("Database size is incorrect!");
    }
    // sort them
    Arrays.sort(scores);
}
Also used : InvertedOutlierScoreMeta(de.lmu.ifi.dbs.elki.result.outlier.InvertedOutlierScoreMeta) DoubleRelation(de.lmu.ifi.dbs.elki.database.relation.DoubleRelation) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)

Example 83 with AbortException

use of de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException in project elki by elki-project.

the class OpenGL3DParallelCoordinates method getStylePolicy.

/**
 * Hack: Get/Create the style result.
 *
 * @return Style result
 */
public StylingPolicy getStylePolicy(ResultHierarchy hier, StyleLibrary stylelib) {
    Database db = ResultUtil.findDatabase(hier);
    AutomaticEvaluation.ensureClusteringResult(db, db);
    List<Clustering<? extends Model>> clusterings = Clustering.getClusteringResults(db);
    if (clusterings.size() > 0) {
        return new ClusterStylingPolicy(clusterings.get(0), stylelib);
    } else {
        throw new AbortException("No clustering result generated?!?");
    }
}
Also used : Database(de.lmu.ifi.dbs.elki.database.Database) Model(de.lmu.ifi.dbs.elki.data.model.Model) Clustering(de.lmu.ifi.dbs.elki.data.Clustering) ClusterStylingPolicy(de.lmu.ifi.dbs.elki.visualization.style.ClusterStylingPolicy) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)

Example 84 with AbortException

use of de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException in project elki by elki-project.

the class ExportVisualizations method processNewResult.

@Override
public void processNewResult(ResultHierarchy hier, Result newResult) {
    if (output.isFile()) {
        throw new AbortException("Output folder cannot be an existing file.");
    }
    if (!output.exists() && !output.mkdirs()) {
        throw new AbortException("Could not create output directory.");
    }
    if (this.baseResult == null) {
        this.baseResult = newResult;
        context = null;
        counter = new HashMap<>();
        LOG.warning("Note: Reusing visualization exporter for more than one result is untested.");
    }
    if (context == null) {
        context = manager.newContext(hier, baseResult);
    }
    // Projected visualizations
    Hierarchy<Object> vistree = context.getVisHierarchy();
    for (It<Projector> iter2 = vistree.iterAll().filter(Projector.class); iter2.valid(); iter2.advance()) {
        // TODO: allow selecting individual projections only.
        Collection<PlotItem> items = iter2.get().arrange(context);
        for (PlotItem item : items) {
            processItem(item);
        }
    }
    for (It<VisualizationTask> iter2 = vistree.iterAll().filter(VisualizationTask.class); iter2.valid(); iter2.advance()) {
        VisualizationTask task = iter2.get();
        if (vistree.iterParents(task).filter(Projector.class).valid()) {
            continue;
        }
        PlotItem pi = new PlotItem(ratio, 1.0, null);
        pi.add(task);
        processItem(pi);
    }
}
Also used : Projector(de.lmu.ifi.dbs.elki.visualization.projector.Projector) VisualizationTask(de.lmu.ifi.dbs.elki.visualization.VisualizationTask) PlotItem(de.lmu.ifi.dbs.elki.visualization.gui.overview.PlotItem) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)

Example 85 with AbortException

use of de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException in project elki by elki-project.

the class BundleReader method readMeta.

/**
 * Read the metadata.
 */
void readMeta() {
    final int check = buffer.getInt();
    if (check != MAGIC) {
        throw new AbortException("File does not start with expected magic.");
    }
    final int nummeta = buffer.getInt();
    assert (nummeta > 0) : "Empty bundle?";
    meta = new BundleMeta(nummeta);
    sers = new ByteBufferSerializer<?>[nummeta];
    data = new Object[nummeta];
    for (int i = 0; i < nummeta; i++) {
        try {
            @SuppressWarnings("unchecked") SimpleTypeInformation<? extends Object> type = (SimpleTypeInformation<? extends Object>) TypeInformationSerializer.STATIC.fromByteBuffer(buffer);
            sers[i] = type.getSerializer();
            if (i == 0 && DBID.class.isAssignableFrom(type.getRestrictionClass())) {
                hasids = true;
            } else {
                meta.add(type);
            }
        } catch (UnsupportedOperationException e) {
            throw new AbortException("Deserialization failed: " + e.getMessage(), e);
        } catch (IOException e) {
            throw new AbortException("IO error", e);
        }
    }
}
Also used : DBID(de.lmu.ifi.dbs.elki.database.ids.DBID) SimpleTypeInformation(de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation) IOException(java.io.IOException) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)

Aggregations

AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)99 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)25 IOException (java.io.IOException)24 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)22 ArrayList (java.util.ArrayList)16 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)13 MultipleObjectsBundle (de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle)13 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)10 DBIDArrayIter (de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter)9 DoubleRelation (de.lmu.ifi.dbs.elki.database.relation.DoubleRelation)9 Clustering (de.lmu.ifi.dbs.elki.data.Clustering)8 Model (de.lmu.ifi.dbs.elki.data.model.Model)8 VectorFieldTypeInformation (de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation)8 Database (de.lmu.ifi.dbs.elki.database.Database)8 WritableDoubleDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore)8 DBIDRange (de.lmu.ifi.dbs.elki.database.ids.DBIDRange)8 OutlierResult (de.lmu.ifi.dbs.elki.result.outlier.OutlierResult)8 MaterializedDoubleRelation (de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation)6 ClassLabel (de.lmu.ifi.dbs.elki.data.ClassLabel)5 DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)5