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);
}
}
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);
}
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?!?");
}
}
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);
}
}
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);
}
}
}
Aggregations