Search in sources :

Example 1 with DoubleMinMax

use of de.lmu.ifi.dbs.elki.math.DoubleMinMax in project elki by elki-project.

the class AttributeWiseMinMaxNormalizationTest method testNaNParameters.

/**
 * Test with default parameters and for correcting handling of NaN and Inf.
 */
@Test
public void testNaNParameters() {
    String filename = UNITTEST + "nan-test-1.csv";
    AttributeWiseMinMaxNormalization<DoubleVector> filter = new ELKIBuilder<AttributeWiseMinMaxNormalization<DoubleVector>>(AttributeWiseMinMaxNormalization.class).build();
    MultipleObjectsBundle bundle = readBundle(filename, filter);
    // Ensure the first column are the vectors.
    assertTrue("Test file not as expected", TypeUtil.NUMBER_VECTOR_FIELD.isAssignableFromType(bundle.meta(0)));
    // This cast is now safe (vector field):
    int dim = ((FieldTypeInformation) bundle.meta(0)).getDimensionality();
    // We verify that minimum and maximum values in each column are 0 and 1:
    DoubleMinMax[] mms = DoubleMinMax.newArray(dim);
    for (int row = 0; row < bundle.dataLength(); row++) {
        DoubleVector d = get(bundle, row, 0, DoubleVector.class);
        for (int col = 0; col < dim; col++) {
            final double val = d.doubleValue(col);
            if (val > Double.NEGATIVE_INFINITY && val < Double.POSITIVE_INFINITY) {
                mms[col].put(val);
            }
        }
    }
    for (int col = 0; col < dim; col++) {
        assertEquals("Minimum not as expected", 0., mms[col].getMin(), 0.);
        assertEquals("Maximum not as expected", 1., mms[col].getMax(), 0.);
    }
}
Also used : DoubleMinMax(de.lmu.ifi.dbs.elki.math.DoubleMinMax) MultipleObjectsBundle(de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle) FieldTypeInformation(de.lmu.ifi.dbs.elki.data.type.FieldTypeInformation) DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) AbstractDataSourceTest(de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest) Test(org.junit.Test)

Example 2 with DoubleMinMax

use of de.lmu.ifi.dbs.elki.math.DoubleMinMax in project elki by elki-project.

the class AffineProjection method estimateViewport.

@Override
public CanvasSize estimateViewport() {
    if (viewport == null) {
        final int dim = proj.getDimensionality();
        DoubleMinMax minmaxx = new DoubleMinMax();
        DoubleMinMax minmaxy = new DoubleMinMax();
        // Origin
        final double[] vec = new double[dim];
        double[] orig = projectScaledToRender(vec);
        minmaxx.put(orig[0]);
        minmaxy.put(orig[1]);
        // Diagonal point
        Arrays.fill(vec, 1.);
        double[] diag = projectScaledToRender(vec);
        minmaxx.put(diag[0]);
        minmaxy.put(diag[1]);
        // Axis end points
        for (int d = 0; d < dim; d++) {
            Arrays.fill(vec, 0.);
            vec[d] = 1.;
            double[] ax = projectScaledToRender(vec);
            minmaxx.put(ax[0]);
            minmaxy.put(ax[1]);
        }
        viewport = new CanvasSize(minmaxx.getMin(), minmaxx.getMax(), minmaxy.getMin(), minmaxy.getMax());
    }
    return viewport;
}
Also used : DoubleMinMax(de.lmu.ifi.dbs.elki.math.DoubleMinMax)

Example 3 with DoubleMinMax

use of de.lmu.ifi.dbs.elki.math.DoubleMinMax in project elki by elki-project.

the class HistogramVisualization method makeVisualization.

@Override
public Visualization makeVisualization(VisualizerContext context, VisualizationTask task, VisualizationPlot plot, double width, double height, Projection proj) {
    HistogramResult curve = task.getResult();
    final StyleLibrary style = context.getStyleLibrary();
    final double sizex = StyleLibrary.SCALE;
    final double sizey = StyleLibrary.SCALE * height / width;
    final double margin = style.getSize(StyleLibrary.MARGIN);
    Element layer = SVGUtil.svgElement(plot.getDocument(), SVGConstants.SVG_G_TAG);
    final String transform = SVGUtil.makeMarginTransform(width, height, sizex, sizey, margin);
    SVGUtil.setAtt(layer, SVGConstants.SVG_TRANSFORM_ATTRIBUTE, transform);
    // find maximum, determine step size
    int dim = -1;
    DoubleMinMax xminmax = new DoubleMinMax();
    DoubleMinMax yminmax = new DoubleMinMax();
    for (double[] point : curve) {
        xminmax.put(point[0]);
        dim = dim < point.length ? point.length : dim;
        for (int i = 1; i < point.length; i++) {
            yminmax.put(point[i]);
        }
    }
    // Minimum should always start at 0 for histograms
    yminmax.put(0.0);
    // remove one dimension which are the x values.
    dim = dim - 1;
    int size = curve.size();
    double range = xminmax.getMax() - xminmax.getMin();
    double binwidth = range / (size - 1);
    LinearScale xscale = new LinearScale(xminmax.getMin() - binwidth * .49999, xminmax.getMax() + binwidth * .49999);
    LinearScale yscale = new LinearScale(yminmax.getMin(), yminmax.getMax());
    SVGPath[] path = new SVGPath[dim];
    for (int i = 0; i < dim; i++) {
        path[i] = new SVGPath(sizex * xscale.getScaled(xminmax.getMin() - binwidth * .5), sizey);
    }
    // draw curves.
    for (double[] point : curve) {
        for (int d = 0; d < dim; d++) {
            path[d].lineTo(sizex * (xscale.getScaled(point[0] - binwidth * .5)), sizey * (1 - yscale.getScaled(point[d + 1])));
            path[d].lineTo(sizex * (xscale.getScaled(point[0] + binwidth * .5)), sizey * (1 - yscale.getScaled(point[d + 1])));
        }
    }
    // close all histograms
    for (int i = 0; i < dim; i++) {
        path[i].lineTo(sizex * xscale.getScaled(xminmax.getMax() + binwidth * .5), sizey);
    }
    // add axes
    try {
        SVGSimpleLinearAxis.drawAxis(plot, layer, yscale, 0, sizey, 0, 0, SVGSimpleLinearAxis.LabelStyle.LEFTHAND, style);
        SVGSimpleLinearAxis.drawAxis(plot, layer, xscale, 0, sizey, sizex, sizey, SVGSimpleLinearAxis.LabelStyle.RIGHTHAND, style);
    } catch (CSSNamingConflict e) {
        LoggingUtil.exception(e);
    }
    // Setup line styles and insert lines.
    ColorLibrary cl = style.getColorSet(StyleLibrary.PLOT);
    for (int d = 0; d < dim; d++) {
        CSSClass csscls = new CSSClass(this, SERIESID + "_" + d);
        csscls.setStatement(SVGConstants.SVG_FILL_ATTRIBUTE, SVGConstants.SVG_NONE_VALUE);
        csscls.setStatement(SVGConstants.SVG_STROKE_ATTRIBUTE, cl.getColor(d));
        csscls.setStatement(SVGConstants.SVG_STROKE_WIDTH_ATTRIBUTE, style.getLineWidth(StyleLibrary.PLOT));
        plot.addCSSClassOrLogError(csscls);
        Element line = path[d].makeElement(plot);
        line.setAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE, csscls.getName());
        layer.appendChild(line);
    }
    return new StaticVisualizationInstance(context, task, plot, width, height, layer);
}
Also used : HistogramResult(de.lmu.ifi.dbs.elki.result.HistogramResult) LinearScale(de.lmu.ifi.dbs.elki.math.scales.LinearScale) Element(org.w3c.dom.Element) StyleLibrary(de.lmu.ifi.dbs.elki.visualization.style.StyleLibrary) CSSClass(de.lmu.ifi.dbs.elki.visualization.css.CSSClass) StaticVisualizationInstance(de.lmu.ifi.dbs.elki.visualization.visualizers.StaticVisualizationInstance) ColorLibrary(de.lmu.ifi.dbs.elki.visualization.colors.ColorLibrary) DoubleMinMax(de.lmu.ifi.dbs.elki.math.DoubleMinMax) CSSNamingConflict(de.lmu.ifi.dbs.elki.visualization.css.CSSClassManager.CSSNamingConflict) SVGPath(de.lmu.ifi.dbs.elki.visualization.svg.SVGPath)

Example 4 with DoubleMinMax

use of de.lmu.ifi.dbs.elki.math.DoubleMinMax in project elki by elki-project.

the class UniformMinMaxEstimator method estimate.

@Override
public <A> UniformDistribution estimate(A data, NumberArrayAdapter<?, A> adapter) {
    final int len = adapter.size(data);
    DoubleMinMax mm = new DoubleMinMax();
    for (int i = 0; i < len; i++) {
        final double val = adapter.getDouble(data, i);
        if (val > Double.NEGATIVE_INFINITY && val < Double.POSITIVE_INFINITY) {
            mm.put(val);
        }
    }
    return estimate(mm);
}
Also used : DoubleMinMax(de.lmu.ifi.dbs.elki.math.DoubleMinMax)

Example 5 with DoubleMinMax

use of de.lmu.ifi.dbs.elki.math.DoubleMinMax in project elki by elki-project.

the class Scales method calcScales.

/**
 * Compute a linear scale for each dimension.
 *
 * @param rel Relation
 * @return Scales, indexed starting with 0 (like Vector, not database
 *         objects!)
 */
public static LinearScale[] calcScales(Relation<? extends SpatialComparable> rel) {
    int dim = RelationUtil.dimensionality(rel);
    DoubleMinMax[] minmax = DoubleMinMax.newArray(dim);
    LinearScale[] scales = new LinearScale[dim];
    // analyze data
    for (DBIDIter iditer = rel.iterDBIDs(); iditer.valid(); iditer.advance()) {
        SpatialComparable v = rel.get(iditer);
        if (v instanceof NumberVector) {
            for (int d = 0; d < dim; d++) {
                final double mi = v.getMin(d);
                if (mi != mi) {
                    // NaN
                    continue;
                }
                minmax[d].put(mi);
            }
        } else {
            for (int d = 0; d < dim; d++) {
                final double mi = v.getMin(d);
                if (mi == mi) {
                    // No NaN
                    minmax[d].put(mi);
                }
                final double ma = v.getMax(d);
                if (ma == ma) {
                    // No NaN
                    minmax[d].put(ma);
                }
            }
        }
    }
    // generate scales
    for (int d = 0; d < dim; d++) {
        scales[d] = new LinearScale(minmax[d].getMin(), minmax[d].getMax());
    }
    return scales;
}
Also used : DoubleMinMax(de.lmu.ifi.dbs.elki.math.DoubleMinMax) NumberVector(de.lmu.ifi.dbs.elki.data.NumberVector) SpatialComparable(de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Aggregations

DoubleMinMax (de.lmu.ifi.dbs.elki.math.DoubleMinMax)89 DoubleRelation (de.lmu.ifi.dbs.elki.database.relation.DoubleRelation)65 WritableDoubleDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore)62 MaterializedDoubleRelation (de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation)62 OutlierResult (de.lmu.ifi.dbs.elki.result.outlier.OutlierResult)62 OutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.OutlierScoreMeta)62 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)54 BasicOutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.BasicOutlierScoreMeta)35 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)34 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)25 KNNList (de.lmu.ifi.dbs.elki.database.ids.KNNList)15 MeanVariance (de.lmu.ifi.dbs.elki.math.MeanVariance)15 QuotientOutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.QuotientOutlierScoreMeta)13 StepProgress (de.lmu.ifi.dbs.elki.logging.progress.StepProgress)12 DoubleDBIDListIter (de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter)11 InvertedOutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.InvertedOutlierScoreMeta)11 NeighborSetPredicate (de.lmu.ifi.dbs.elki.algorithm.outlier.spatial.neighborhood.NeighborSetPredicate)9 ArrayDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs)7 Mean (de.lmu.ifi.dbs.elki.math.Mean)6 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)6