Search in sources :

Example 1 with IntIntPair

use of de.lmu.ifi.dbs.elki.utilities.pairs.IntIntPair in project elki by elki-project.

the class Parallel3DRenderer method sortEdges.

/**
 * Sort the edges for rendering.
 *
 * FIXME: THIS STILL HAS ERRORS SOMETIME!
 *
 * @param dindex depth index of axes.
 * @return Sorted array of (minaxis, edgeid)
 */
private IntIntPair[] sortEdges(int[] dindex) {
    IntIntPair[] edgesort = new IntIntPair[shared.layout.edges.size()];
    int e = 0;
    for (Layout.Edge edge : shared.layout.edges) {
        int i1 = dindex[edge.dim1], i2 = dindex[edge.dim2];
        edgesort[e] = new IntIntPair(Math.min(i1, i2), e);
        e++;
    }
    Arrays.sort(edgesort);
    return edgesort;
}
Also used : Layout(de.lmu.ifi.dbs.elki.visualization.parallel3d.layout.Layout) IntIntPair(de.lmu.ifi.dbs.elki.utilities.pairs.IntIntPair)

Example 2 with IntIntPair

use of de.lmu.ifi.dbs.elki.utilities.pairs.IntIntPair in project elki by elki-project.

the class Parallel3DRenderer method renderLabels.

private void renderLabels(GL2 gl, IntIntPair[] edgesort) {
    shared.textrenderer.begin3DRendering();
    // UNDO the camera rotation. This will mess up text orientation!
    gl.glRotatef((float) MathUtil.rad2deg(shared.camera.getRotationZ()), 0.f, 0.f, 1.f);
    // Rotate to have the text face the camera direction, which looks +Y
    // While the text will be visible from +Z and +Y is baseline.
    gl.glRotatef(90.f, 1.f, 0.f, 0.f);
    // HalfPI: 180 degree extra rotation, for text orientation.
    double cos = FastMath.cos(shared.camera.getRotationZ()), sin = FastMath.sin(shared.camera.getRotationZ());
    shared.textrenderer.setColor(0.0f, 0.0f, 0.0f, 1.0f);
    float defaultscale = .01f / (float) FastMath.sqrt(shared.dim);
    // TODO: div depth?
    final float targetwidth = .2f;
    // Assume all text is at least this width
    final float minratio = 8.f;
    for (int i = 0; i < shared.dim; i++) {
        if (shared.labels[i] != null) {
            Rectangle2D b = shared.textrenderer.getBounds(shared.labels[i]);
            float scale = defaultscale;
            if (Math.max(b.getWidth(), b.getHeight() * minratio) * scale > targetwidth) {
                scale = targetwidth / (float) Math.max(b.getWidth(), b.getHeight() * minratio);
            }
            float w = (float) b.getWidth() * scale;
            // Rotate manually, in x-z plane
            float x = (float) (cos * shared.layout.getNode(i).getX() + sin * shared.layout.getNode(i).getY());
            float y = (float) (-sin * shared.layout.getNode(i).getX() + cos * shared.layout.getNode(i).getY());
            shared.textrenderer.draw3D(shared.labels[i], (x - w * .5f), 1.01f, -y, scale);
        }
    }
    // Show depth indexes on debug:
    if (OpenGL3DParallelCoordinates.Instance.DEBUG) {
        shared.textrenderer.setColor(1f, 0f, 0f, 1f);
        for (IntIntPair pair : edgesort) {
            Layout.Edge edge = shared.layout.edges.get(pair.second);
            final Node node1 = shared.layout.getNode(edge.dim1);
            final Node node2 = shared.layout.getNode(edge.dim2);
            final double mx = 0.5 * (node1.getX() + node2.getX());
            final double my = 0.5 * (node1.getY() + node2.getY());
            // Rotate manually, in x-z plane
            float x = (float) (cos * mx + sin * my);
            float y = (float) (-sin * mx + cos * my);
            shared.textrenderer.draw3D(Integer.toString(pair.first), (x - defaultscale * .5f), 1.01f, -y, .5f * defaultscale);
        }
    }
    shared.textrenderer.end3DRendering();
}
Also used : Layout(de.lmu.ifi.dbs.elki.visualization.parallel3d.layout.Layout) Node(de.lmu.ifi.dbs.elki.visualization.parallel3d.layout.Layout.Node) Rectangle2D(java.awt.geom.Rectangle2D) IntIntPair(de.lmu.ifi.dbs.elki.utilities.pairs.IntIntPair)

Example 3 with IntIntPair

use of de.lmu.ifi.dbs.elki.utilities.pairs.IntIntPair in project elki by elki-project.

the class SweepHullDelaunay2D method debugHull.

/**
 * Debug helper
 */
void debugHull() {
    StringBuilder buf = new StringBuilder();
    for (IntIntPair p : hull) {
        buf.append(p.first).append(" (").append(p.second).append(") ");
    }
    LOG.debugFinest(buf);
}
Also used : IntIntPair(de.lmu.ifi.dbs.elki.utilities.pairs.IntIntPair)

Example 4 with IntIntPair

use of de.lmu.ifi.dbs.elki.utilities.pairs.IntIntPair in project elki by elki-project.

the class LinearEquationSystem method reducedRowEchelonForm.

/**
 * Brings this linear equation system into reduced row echelon form with
 * choice of pivot method.
 *
 * @param method the pivot search method to use
 */
private void reducedRowEchelonForm(int method) {
    final int rows = coeff.length;
    final int cols = coeff[0].length;
    // denotes current position on diagonal
    int k = -1;
    // row index of pivot element
    int pivotRow;
    // column index of pivot element
    int pivotCol;
    // value of pivot element
    double pivot;
    // main loop, transformation to reduced row echelon form
    boolean exitLoop = false;
    while (!exitLoop) {
        k++;
        // pivot search for entry in remaining matrix
        // (depends on chosen method in switch)
        // store position in pivotRow, pivotCol
        // TODO: Note that we're using "row, col", whereas "col, row" would be
        // more common?
        IntIntPair pivotPos = new IntIntPair(0, 0);
        IntIntPair currPos = new IntIntPair(k, k);
        switch(method) {
            case TRIVAL_PIVOT_SEARCH:
                pivotPos = nonZeroPivotSearch(k);
                break;
            case TOTAL_PIVOT_SEARCH:
                pivotPos = totalPivotSearch(k);
                break;
        }
        pivotRow = pivotPos.first;
        pivotCol = pivotPos.second;
        pivot = coeff[this.row[pivotRow]][col[pivotCol]];
        if (LOG.isDebugging()) {
            StringBuilder msg = new StringBuilder();
            msg.append("equations ").append(equationsToString(4));
            msg.append("  *** pivot at (").append(pivotRow).append(',').append(pivotCol).append(") = ").append(pivot).append('\n');
            LOG.debugFine(msg.toString());
        }
        // permute rows and columns to get this entry onto
        // the diagonal
        permutePivot(pivotPos, currPos);
        // reasons are: Math.abs(pivot) == 0
        if ((Math.abs(pivot) <= DELTA)) {
            exitLoop = true;
        }
        // and k <= m - 1
        if ((Math.abs(pivot) > DELTA)) {
            rank++;
            pivotOperation(k);
        }
        // k == cols-1 : no more columns
        if (k == rows - 1 || k == cols - 1) {
            exitLoop = true;
        }
    }
    // end while
    reducedRowEchelonForm = true;
}
Also used : IntIntPair(de.lmu.ifi.dbs.elki.utilities.pairs.IntIntPair)

Example 5 with IntIntPair

use of de.lmu.ifi.dbs.elki.utilities.pairs.IntIntPair in project elki by elki-project.

the class AggarwalYuNaive method run.

/**
 * Run the algorithm on the given relation.
 *
 * @param relation Relation
 * @return Outlier detection result
 */
public OutlierResult run(Relation<V> relation) {
    final int dimensionality = RelationUtil.dimensionality(relation);
    final int size = relation.size();
    ArrayList<ArrayList<DBIDs>> ranges = buildRanges(relation);
    ArrayList<ArrayList<IntIntPair>> Rk;
    // Build a list of all subspaces
    {
        // R1 initial one-dimensional subspaces.
        Rk = new ArrayList<>();
        // Set of all dim*phi ranges
        ArrayList<IntIntPair> q = new ArrayList<>();
        for (int i = 0; i < dimensionality; i++) {
            for (int j = 0; j < phi; j++) {
                IntIntPair s = new IntIntPair(i, j);
                q.add(s);
                // Add to first Rk
                ArrayList<IntIntPair> v = new ArrayList<>();
                v.add(s);
                Rk.add(v);
            }
        }
        // build Ri
        for (int i = 2; i <= k; i++) {
            ArrayList<ArrayList<IntIntPair>> Rnew = new ArrayList<>();
            for (int j = 0; j < Rk.size(); j++) {
                ArrayList<IntIntPair> c = Rk.get(j);
                for (IntIntPair pair : q) {
                    boolean invalid = false;
                    for (int t = 0; t < c.size(); t++) {
                        if (c.get(t).first == pair.first) {
                            invalid = true;
                            break;
                        }
                    }
                    if (!invalid) {
                        ArrayList<IntIntPair> neu = new ArrayList<>(c);
                        neu.add(pair);
                        Rnew.add(neu);
                    }
                }
            }
            Rk = Rnew;
        }
    }
    WritableDoubleDataStore sparsity = DataStoreUtil.makeDoubleStorage(relation.getDBIDs(), DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_STATIC);
    // calculate the sparsity coefficient
    for (ArrayList<IntIntPair> sub : Rk) {
        DBIDs ids = computeSubspace(sub, ranges);
        final double sparsityC = sparsity(ids.size(), size, k, phi);
        if (sparsityC < 0) {
            for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
                double prev = sparsity.doubleValue(iter);
                if (Double.isNaN(prev) || sparsityC < prev) {
                    sparsity.putDouble(iter, sparsityC);
                }
            }
        }
    }
    DoubleMinMax minmax = new DoubleMinMax();
    for (DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
        double val = sparsity.doubleValue(iditer);
        if (Double.isNaN(val)) {
            sparsity.putDouble(iditer, 0.0);
            val = 0.0;
        }
        minmax.put(val);
    }
    DoubleRelation scoreResult = new MaterializedDoubleRelation("AggarwalYuNaive", "aggarwal-yu-outlier", sparsity, relation.getDBIDs());
    OutlierScoreMeta meta = new InvertedOutlierScoreMeta(minmax.getMin(), minmax.getMax(), Double.NEGATIVE_INFINITY, 0.0);
    return new OutlierResult(meta, scoreResult);
}
Also used : WritableDoubleDataStore(de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore) DBIDs(de.lmu.ifi.dbs.elki.database.ids.DBIDs) ArrayList(java.util.ArrayList) OutlierResult(de.lmu.ifi.dbs.elki.result.outlier.OutlierResult) InvertedOutlierScoreMeta(de.lmu.ifi.dbs.elki.result.outlier.InvertedOutlierScoreMeta) DoubleRelation(de.lmu.ifi.dbs.elki.database.relation.DoubleRelation) MaterializedDoubleRelation(de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation) OutlierScoreMeta(de.lmu.ifi.dbs.elki.result.outlier.OutlierScoreMeta) InvertedOutlierScoreMeta(de.lmu.ifi.dbs.elki.result.outlier.InvertedOutlierScoreMeta) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter) DoubleMinMax(de.lmu.ifi.dbs.elki.math.DoubleMinMax) MaterializedDoubleRelation(de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation) IntIntPair(de.lmu.ifi.dbs.elki.utilities.pairs.IntIntPair)

Aggregations

IntIntPair (de.lmu.ifi.dbs.elki.utilities.pairs.IntIntPair)9 Layout (de.lmu.ifi.dbs.elki.visualization.parallel3d.layout.Layout)3 ArrayList (java.util.ArrayList)3 DoubleMinMax (de.lmu.ifi.dbs.elki.math.DoubleMinMax)2 Node (de.lmu.ifi.dbs.elki.visualization.parallel3d.layout.Layout.Node)2 Polygon (de.lmu.ifi.dbs.elki.data.spatial.Polygon)1 WritableDoubleDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore)1 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)1 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)1 DoubleRelation (de.lmu.ifi.dbs.elki.database.relation.DoubleRelation)1 MaterializedDoubleRelation (de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation)1 LinearScale (de.lmu.ifi.dbs.elki.math.scales.LinearScale)1 InvertedOutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.InvertedOutlierScoreMeta)1 OutlierResult (de.lmu.ifi.dbs.elki.result.outlier.OutlierResult)1 OutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.OutlierScoreMeta)1 Rectangle2D (java.awt.geom.Rectangle2D)1 Iterator (java.util.Iterator)1 ListIterator (java.util.ListIterator)1