Example usage for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getMin

List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getMin

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getMin.

Prototype

public double getMin() 

Source Link

Document

Returns the minimum of the available values

Usage

From source file:com.github.jessemull.microflex.stat.statbiginteger.MinBigIntegerTest.java

/**
 * Tests the aggregated plate statistics method.
 *//*from  w  w  w  .j a v a2 s. c o m*/
@Test
public void testAggregatedSet() {

    for (PlateBigInteger plate : array) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        BigDecimal aggregatedReturned = min.setsAggregated(plate.dataSet());

        for (WellBigInteger well : plate) {
            resultList.addAll(well.toBigDecimal());
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getMin();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        BigDecimal[] corrected = correctRoundingErrors(aggregatedResult, aggregatedReturned);
        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflex.stat.statbiginteger.MinBigIntegerTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices.
 *//*from  w w  w . ja va  2s .c  o m*/
@Test
public void testAggregatedPlateIndices() {

    for (PlateBigInteger plate : arrayIndices) {

        int size = arrayIndices[0].first().size();
        int begin = random.nextInt(size - 5);
        int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        BigDecimal aggregatedReturned = min.platesAggregated(plate, begin, end - begin);

        for (WellBigInteger well : plate) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getMin();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        BigDecimal[] corrected = correctRoundingErrors(aggregatedResult, aggregatedReturned);
        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflex.stat.statbiginteger.MinBigIntegerTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices.
 *///  www.ja  v  a 2s. c  o m
@Test
public void testAggregatedSetIndices() {

    for (PlateBigInteger plate : arrayIndices) {

        int size = arrayIndices[0].first().size();
        int begin = random.nextInt(size - 5);
        int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        BigDecimal aggregatedReturned = min.setsAggregated(plate.dataSet(), begin, end - begin);

        for (WellBigInteger well : plate) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getMin();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        BigDecimal[] corrected = correctRoundingErrors(aggregatedResult, aggregatedReturned);
        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.MinTest.java

/**
 * Tests well calculation using indices.
 *///w  w w.  j a  v  a 2s . c o m
@Test
public void testWellIndices() {

    for (Plate plate : arrayIndices) {

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigInteger bi : well) {
                input[index++] = bi.doubleValue();
            }

            int size = arrayIndices[0].first().size();
            int begin = random.nextInt(size - 5);
            int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double resultDouble = stat.getMin();

            BigDecimal returned = min.well(well, begin, end - begin);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);
            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.MinTest.java

/**
 * Tests the aggregated plate statistics method using a collection.
 *//*  w w  w  .j  a  v  a2  s  .c  o  m*/
@Test
public void testAggregatedPlateCollection() {

    List<Plate> collection = Arrays.asList(array);
    Map<Plate, BigDecimal> aggregatedReturnedMap = min.platesAggregated(collection);
    Map<Plate, BigDecimal> aggregatedResultMap = new TreeMap<Plate, BigDecimal>();

    for (Plate plate : collection) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (Well well : plate) {
            resultList.addAll(well.toBigDecimal());
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getMin();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (Plate plate : collection) {

        BigDecimal result = aggregatedResultMap.get(plate);
        BigDecimal returned = aggregatedReturnedMap.get(plate);

        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.MinTest.java

/**
 * Tests the aggregated plate statistics method using an array.
 *//*from ww w.j  a v  a  2  s. c  o  m*/
@Test
public void testAggregatedPlateArray() {

    Map<Plate, BigDecimal> aggregatedReturnedMap = min.platesAggregated(array);
    Map<Plate, BigDecimal> aggregatedResultMap = new TreeMap<Plate, BigDecimal>();

    for (Plate plate : array) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (Well well : plate) {
            resultList.addAll(well.toBigDecimal());
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getMin();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (Plate plate : array) {

        BigDecimal result = aggregatedResultMap.get(plate);
        BigDecimal returned = aggregatedReturnedMap.get(plate);

        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }

}

From source file:gdsc.smlm.ij.plugins.SpotInspector.java

public void run(String arg) {
    if (MemoryPeakResults.countMemorySize() == 0) {
        IJ.error(TITLE, "No localisations in memory");
        return;//ww w.j a v a  2 s. c om
    }

    if (!showDialog())
        return;

    // Load the results
    results = ResultsManager.loadInputResults(inputOption, false);
    if (results == null || results.size() == 0) {
        IJ.error(TITLE, "No results could be loaded");
        IJ.showStatus("");
        return;
    }

    // Check if the original image is open
    ImageSource source = results.getSource();
    if (source == null) {
        IJ.error(TITLE, "Unknown original source image");
        return;
    }
    source = source.getOriginal();
    if (!source.open()) {
        IJ.error(TITLE, "Cannot open original source image: " + source.toString());
        return;
    }
    final float stdDevMax = getStandardDeviation(results);
    if (stdDevMax < 0) {
        // TODO - Add dialog to get the initial peak width
        IJ.error(TITLE, "Fitting configuration (for initial peak width) is not available");
        return;
    }

    // Rank spots
    rankedResults = new ArrayList<PeakResultRank>(results.size());
    final double a = results.getNmPerPixel();
    final double gain = results.getGain();
    final boolean emCCD = results.isEMCCD();

    for (PeakResult r : results.getResults()) {
        float[] score = getScore(r, a, gain, emCCD, stdDevMax);
        rankedResults.add(new PeakResultRank(r, score[0], score[1]));
    }
    Collections.sort(rankedResults);

    // Prepare results table. Get bias if necessary
    if (showCalibratedValues) {
        // Get a bias if required
        Calibration calibration = results.getCalibration();
        if (calibration.bias == 0) {
            GenericDialog gd = new GenericDialog(TITLE);
            gd.addMessage("Calibrated results requires a camera bias");
            gd.addNumericField("Camera_bias (ADUs)", calibration.bias, 2);
            gd.showDialog();
            if (!gd.wasCanceled()) {
                calibration.bias = Math.abs(gd.getNextNumber());
            }
        }
    }

    IJTablePeakResults table = new IJTablePeakResults(false, results.getName(), true);
    table.copySettings(results);
    table.setTableTitle(TITLE);
    table.setAddCounter(true);
    table.setShowCalibratedValues(showCalibratedValues);
    table.begin();

    // Add a mouse listener to jump to the frame for the clicked line
    textPanel = table.getResultsWindow().getTextPanel();

    // We must ignore old instances of this class from the mouse listeners
    id = ++currentId;
    textPanel.addMouseListener(this);

    // Add results to the table
    int n = 0;
    for (PeakResultRank rank : rankedResults) {
        rank.rank = n++;
        PeakResult r = rank.peakResult;
        table.add(r.peak, r.origX, r.origY, r.origValue, r.error, r.noise, r.params, r.paramsStdDev);
    }
    table.end();

    if (plotScore || plotHistogram) {
        // Get values for the plots
        float[] xValues = null, yValues = null;
        double yMin, yMax;

        int spotNumber = 0;
        xValues = new float[rankedResults.size()];
        yValues = new float[xValues.length];
        for (PeakResultRank rank : rankedResults) {
            xValues[spotNumber] = spotNumber + 1;
            yValues[spotNumber++] = recoverScore(rank.score);
        }

        // Set the min and max y-values using 1.5 x IQR 
        DescriptiveStatistics stats = new DescriptiveStatistics();
        for (float v : yValues)
            stats.addValue(v);
        if (removeOutliers) {
            double lower = stats.getPercentile(25);
            double upper = stats.getPercentile(75);
            double iqr = upper - lower;

            yMin = FastMath.max(lower - iqr, stats.getMin());
            yMax = FastMath.min(upper + iqr, stats.getMax());

            IJ.log(String.format("Data range: %f - %f. Plotting 1.5x IQR: %f - %f", stats.getMin(),
                    stats.getMax(), yMin, yMax));
        } else {
            yMin = stats.getMin();
            yMax = stats.getMax();

            IJ.log(String.format("Data range: %f - %f", yMin, yMax));
        }

        plotScore(xValues, yValues, yMin, yMax);
        plotHistogram(yValues, yMin, yMax);
    }

    // Extract spots into a stack
    final int w = source.getWidth();
    final int h = source.getHeight();
    final int size = 2 * radius + 1;
    ImageStack spots = new ImageStack(size, size, rankedResults.size());

    // To assist the extraction of data from the image source, process them in time order to allow 
    // frame caching. Then set the appropriate slice in the result stack
    Collections.sort(rankedResults, new Comparator<PeakResultRank>() {
        public int compare(PeakResultRank o1, PeakResultRank o2) {
            if (o1.peakResult.peak < o2.peakResult.peak)
                return -1;
            if (o1.peakResult.peak > o2.peakResult.peak)
                return 1;
            return 0;
        }
    });

    for (PeakResultRank rank : rankedResults) {
        PeakResult r = rank.peakResult;

        // Extract image
        // Note that the coordinates are relative to the middle of the pixel (0.5 offset)
        // so do not round but simply convert to int
        final int x = (int) (r.params[Gaussian2DFunction.X_POSITION]);
        final int y = (int) (r.params[Gaussian2DFunction.Y_POSITION]);

        // Extract a region but crop to the image bounds
        int minX = x - radius;
        int minY = y - radius;
        int maxX = FastMath.min(x + radius + 1, w);
        int maxY = FastMath.min(y + radius + 1, h);

        int padX = 0, padY = 0;
        if (minX < 0) {
            padX = -minX;
            minX = 0;
        }
        if (minY < 0) {
            padY = -minY;
            minY = 0;
        }
        int sizeX = maxX - minX;
        int sizeY = maxY - minY;

        float[] data = source.get(r.peak, new Rectangle(minX, minY, sizeX, sizeY));
        // Prevent errors with missing data
        if (data == null)
            data = new float[sizeX * sizeY];
        ImageProcessor spotIp = new FloatProcessor(sizeX, sizeY, data, null);

        // Pad if necessary, i.e. the crop is too small for the stack
        if (padX > 0 || padY > 0 || sizeX < size || sizeY < size) {
            ImageProcessor spotIp2 = spotIp.createProcessor(size, size);
            spotIp2.insert(spotIp, padX, padY);
            spotIp = spotIp2;
        }
        int slice = rank.rank + 1;
        spots.setPixels(spotIp.getPixels(), slice);
        spots.setSliceLabel(Utils.rounded(rank.originalScore), slice);
    }

    source.close();

    ImagePlus imp = Utils.display(TITLE, spots);
    imp.setRoi((PointRoi) null);

    // Make bigger      
    for (int i = 10; i-- > 0;)
        imp.getWindow().getCanvas().zoomIn(imp.getWidth() / 2, imp.getHeight() / 2);
}

From source file:com.github.jessemull.microflex.stat.statbiginteger.MinBigIntegerTest.java

/**
 * Tests well calculation using indices.
 *///from w w w  . ja  v a2s.  c  o  m
@Test
public void testWellIndices() {

    for (PlateBigInteger plate : arrayIndices) {

        for (WellBigInteger well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigInteger bi : well) {
                input[index++] = bi.doubleValue();
            }

            int size = arrayIndices[0].first().size();
            int begin = random.nextInt(size - 5);
            int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double resultDouble = stat.getMin();

            BigDecimal returned = min.well(well, begin, end - begin);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);
            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.MinTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the array.//from  ww  w  .j av  a2  s  .co  m
 */
@Test
public void testAggregatedPlateArrayIndices() {

    int size = arrayIndices[0].first().size();
    int begin = random.nextInt(size - 5);
    int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

    Map<Plate, BigDecimal> aggregatedReturnedMap = min.platesAggregated(arrayIndices, begin, end - begin);
    Map<Plate, BigDecimal> aggregatedResultMap = new TreeMap<Plate, BigDecimal>();

    for (Plate plate : arrayIndices) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (Well well : plate) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getMin();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (Plate plate : arrayIndices) {

        BigDecimal result = aggregatedResultMap.get(plate);
        BigDecimal returned = aggregatedReturnedMap.get(plate);
        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.MinTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the collection.// w w w.  jav  a  2 s .com
 */
@Test
public void testAggregatedPlateCollectionIndices() {

    int size = arrayIndices[0].first().size();
    int begin = random.nextInt(size - 5);
    int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

    List<Plate> collection = Arrays.asList(arrayIndices);
    Map<Plate, BigDecimal> aggregatedReturnedMap = min.platesAggregated(collection, begin, end - begin);

    Map<Plate, BigDecimal> aggregatedResultMap = new TreeMap<Plate, BigDecimal>();

    for (Plate plate : collection) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (Well well : plate) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getMin();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (Plate plate : collection) {

        BigDecimal result = aggregatedResultMap.get(plate);
        BigDecimal returned = aggregatedReturnedMap.get(plate);
        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}