Search in sources :

Example 86 with AbortException

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

the class AbstractRStarTree method initializeCapacities.

@Override
protected void initializeCapacities(E exampleLeaf) {
    /* Simulate the creation of a leaf page to get the page capacity */
    try {
        int cap = 0;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        SpatialPointLeafEntry sl = new SpatialPointLeafEntry(DBIDUtil.importInteger(0), new double[exampleLeaf.getDimensionality()]);
        while (baos.size() <= getPageSize()) {
            sl.writeExternal(oos);
            oos.flush();
            cap++;
        }
        // the last one caused the page to overflow.
        leafCapacity = cap - 1;
    } catch (IOException e) {
        throw new AbortException("Error determining page sizes.", e);
    }
    /* Simulate the creation of a directory page to get the capacity */
    try {
        int cap = 0;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        ModifiableHyperBoundingBox hb = new ModifiableHyperBoundingBox(new double[exampleLeaf.getDimensionality()], new double[exampleLeaf.getDimensionality()]);
        SpatialDirectoryEntry sl = new SpatialDirectoryEntry(0, hb);
        while (baos.size() <= getPageSize()) {
            sl.writeExternal(oos);
            oos.flush();
            cap++;
        }
        dirCapacity = cap - 1;
    } catch (IOException e) {
        throw new AbortException("Error determining page sizes.", e);
    }
    if (dirCapacity <= 2) {
        throw new IllegalArgumentException("Node size of " + getPageSize() + " bytes is chosen too small!");
    }
    final Logging log = getLogger();
    if (dirCapacity < 10) {
        log.warning("Page size is choosen very small! Maximum number of entries in a directory node = " + dirCapacity);
    }
    // minimum entries per directory node
    dirMinimum = (int) Math.floor(dirCapacity * settings.relativeMinFill);
    if (dirMinimum < 1) {
        dirMinimum = 1;
    }
    if (leafCapacity <= 2) {
        throw new IllegalArgumentException("Node size of " + getPageSize() + " bytes is chosen too small!");
    }
    if (leafCapacity < 10) {
        log.warning("Page size is choosen very small! Maximum number of entries in a leaf node = " + leafCapacity);
    }
    // minimum entries per leaf node
    leafMinimum = (int) Math.floor(leafCapacity * settings.relativeMinFill);
    if (leafMinimum < 1) {
        leafMinimum = 1;
    }
}
Also used : Logging(de.lmu.ifi.dbs.elki.logging.Logging) SpatialPointLeafEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialPointLeafEntry) SpatialDirectoryEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialDirectoryEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ModifiableHyperBoundingBox(de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox) ObjectOutputStream(java.io.ObjectOutputStream) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)

Example 87 with AbortException

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

the class TrivialDBIDFactory method generateStaticDBIDRange.

@Override
public DBIDRange generateStaticDBIDRange(int size) {
    final int start = next.getAndAdd(size);
    if (start > next.get()) {
        throw new AbortException("DBID range allocation error - too many objects allocated!");
    }
    DBIDRange alloc = new IntegerDBIDRange(start, size);
    return alloc;
}
Also used : DBIDRange(de.lmu.ifi.dbs.elki.database.ids.DBIDRange) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)

Example 88 with AbortException

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

the class GeneratorXMLDatabaseConnection method processElementStatic.

/**
 * Process a 'static' cluster Element in the XML stream.
 *
 * @param gen Generator
 * @param cur Current document nod
 */
private void processElementStatic(GeneratorMain gen, Node cur) {
    String name = ((Element) cur).getAttribute(ATTR_NAME);
    if (name == null) {
        throw new AbortException("No cluster name given in specification file.");
    }
    ArrayList<double[]> points = new ArrayList<>();
    // TODO: check for unknown attributes.
    XMLNodeIterator iter = new XMLNodeIterator(cur.getFirstChild());
    while (iter.hasNext()) {
        Node child = iter.next();
        if (TAG_POINT.equals(child.getNodeName())) {
            processElementPoint(points, child);
        } else if (child.getNodeType() == Node.ELEMENT_NODE) {
            LOG.warning("Unknown element in XML specification file: " + child.getNodeName());
        }
    }
    // *** add new cluster object
    GeneratorStatic cluster = new GeneratorStatic(name, points);
    gen.addCluster(cluster);
    if (LOG.isVerbose()) {
        LOG.verbose("Loaded cluster " + cluster.name + " from specification.");
    }
}
Also used : GeneratorStatic(de.lmu.ifi.dbs.elki.data.synthetic.bymodel.GeneratorStatic) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException) XMLNodeIterator(de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator)

Example 89 with AbortException

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

the class GeneratorXMLDatabaseConnection method processElementClipping.

/**
 * Process a 'clipping' Element in the XML stream.
 *
 * @param cluster
 * @param cur Current document nod
 */
private void processElementClipping(GeneratorSingleCluster cluster, Node cur) {
    double[] cmin = null, cmax = null;
    String minstr = ((Element) cur).getAttribute(ATTR_MIN);
    if (minstr != null && minstr.length() > 0) {
        cmin = parseVector(minstr);
    }
    String maxstr = ((Element) cur).getAttribute(ATTR_MAX);
    if (maxstr != null && maxstr.length() > 0) {
        cmax = parseVector(maxstr);
    }
    if (cmin == null || cmax == null) {
        throw new AbortException("No or incomplete clipping vectors given.");
    }
    // *** set clipping
    cluster.setClipping(cmin, cmax);
    // TODO: check for unknown attributes.
    XMLNodeIterator iter = new XMLNodeIterator(cur.getFirstChild());
    while (iter.hasNext()) {
        Node child = iter.next();
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            LOG.warning("Unknown element in XML specification file: " + child.getNodeName());
        }
    }
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException) XMLNodeIterator(de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator)

Example 90 with AbortException

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

the class GeneratorXMLDatabaseConnection method processElementTranslate.

/**
 * Process a 'translate' Element in the XML stream.
 *
 * @param cluster
 * @param cur Current document nod
 */
private void processElementTranslate(GeneratorSingleCluster cluster, Node cur) {
    double[] offset = null;
    String vstr = ((Element) cur).getAttribute(ATTR_VECTOR);
    if (vstr != null && vstr.length() > 0) {
        offset = parseVector(vstr);
    }
    if (offset == null) {
        throw new AbortException("No translation vector given.");
    }
    // *** add new translation
    cluster.addTranslation(offset);
    // TODO: check for unknown attributes.
    XMLNodeIterator iter = new XMLNodeIterator(cur.getFirstChild());
    while (iter.hasNext()) {
        Node child = iter.next();
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            LOG.warning("Unknown element in XML specification file: " + child.getNodeName());
        }
    }
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException) XMLNodeIterator(de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator)

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