Search in sources :

Example 1 with StatisticalSummary

use of org.apache.commons.math3.stat.descriptive.StatisticalSummary in project GDSC-SMLM by aherbert.

the class PSFEstimator method checkAngleSignificance.

private boolean checkAngleSignificance() {
    boolean tryAgain = false;
    if (ignore[ANGLE])
        return tryAgain;
    // The angle is relative to the major axis (X). 
    // It could be close to 0, 90 or 180 to allow it to be ignored in favour of a free circular function.
    final double[] angles = sampleNew[ANGLE].getValues();
    for (double testAngle : new double[] { 90, 0, 180 }) {
        // The angle will be in the 0-180 domain.
        // We need to compute the Statistical summary around the testAngle.
        StatisticalSummary sampleStats;
        if (testAngle == 0 || testAngle == 180) {
            SummaryStatistics stats = new SummaryStatistics();
            boolean zeroAngle = (testAngle == 0);
            for (double a : angles) {
                if (zeroAngle) {
                    // Convert to -90-90 domain
                    if (a > 90)
                        a -= 180;
                } else {
                    // Convert to 90-270 domain
                    if (a < 90)
                        a += 180;
                }
                stats.addValue(a);
            }
            sampleStats = stats;
        } else {
            // Already in the 0-180 domain around the angle 90
            sampleStats = sampleNew[ANGLE];
        }
        final double p = TestUtils.tTest(testAngle, sampleStats);
        if (p > settings.pValue) {
            log("NOTE: Angle is not significant: %g ~ %g (p=%g) => Re-run with fixed zero angle", sampleStats.getMean(), testAngle, p);
            ignore[ANGLE] = true;
            config.getFitConfiguration().setFitFunction(FitFunction.FREE_CIRCULAR);
            tryAgain = true;
            break;
        } else
            debug("  NOTE: Angle is significant: %g !~ %g (p=%g)", sampleNew[ANGLE].getMean(), testAngle, p);
    }
    return tryAgain;
}
Also used : StatisticalSummary(org.apache.commons.math3.stat.descriptive.StatisticalSummary) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics)

Example 2 with StatisticalSummary

use of org.apache.commons.math3.stat.descriptive.StatisticalSummary in project lucene-solr by apache.

the class EmpiricalDistributionEvaluator method evaluate.

public Tuple evaluate(Tuple tuple) throws IOException {
    if (subEvaluators.size() != 1) {
        throw new IOException("Empirical dist expects 1 column as a parameters");
    }
    StreamEvaluator colEval1 = subEvaluators.get(0);
    List<Number> numbers1 = (List<Number>) colEval1.evaluate(tuple);
    double[] column1 = new double[numbers1.size()];
    for (int i = 0; i < numbers1.size(); i++) {
        column1[i] = numbers1.get(i).doubleValue();
    }
    Arrays.sort(column1);
    EmpiricalDistribution empiricalDistribution = new EmpiricalDistribution();
    empiricalDistribution.load(column1);
    Map map = new HashMap();
    StatisticalSummary statisticalSummary = empiricalDistribution.getSampleStats();
    map.put("max", statisticalSummary.getMax());
    map.put("mean", statisticalSummary.getMean());
    map.put("min", statisticalSummary.getMin());
    map.put("stdev", statisticalSummary.getStandardDeviation());
    map.put("sum", statisticalSummary.getSum());
    map.put("N", statisticalSummary.getN());
    map.put("var", statisticalSummary.getVariance());
    return new EmpiricalDistributionTuple(empiricalDistribution, column1, map);
}
Also used : EmpiricalDistribution(org.apache.commons.math3.random.EmpiricalDistribution) StatisticalSummary(org.apache.commons.math3.stat.descriptive.StatisticalSummary) HashMap(java.util.HashMap) List(java.util.List) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with StatisticalSummary

use of org.apache.commons.math3.stat.descriptive.StatisticalSummary in project lucene-solr by apache.

the class HistogramEvaluator method evaluate.

public List<Map> evaluate(Tuple tuple) throws IOException {
    StreamEvaluator colEval1 = subEvaluators.get(0);
    List<Number> numbers1 = (List<Number>) colEval1.evaluate(tuple);
    double[] column1 = new double[numbers1.size()];
    for (int i = 0; i < numbers1.size(); i++) {
        column1[i] = numbers1.get(i).doubleValue();
    }
    int bins = 10;
    if (subEvaluators.size() == 2) {
        StreamEvaluator binsEval = subEvaluators.get(1);
        Number binsNum = (Number) binsEval.evaluate(tuple);
        bins = binsNum.intValue();
    }
    EmpiricalDistribution empiricalDistribution = new EmpiricalDistribution(bins);
    empiricalDistribution.load(column1);
    List<Map> binList = new ArrayList();
    List<SummaryStatistics> summaries = empiricalDistribution.getBinStats();
    for (SummaryStatistics statisticalSummary : summaries) {
        Map map = new HashMap();
        map.put("max", statisticalSummary.getMax());
        map.put("mean", statisticalSummary.getMean());
        map.put("min", statisticalSummary.getMin());
        map.put("stdev", statisticalSummary.getStandardDeviation());
        map.put("sum", statisticalSummary.getSum());
        map.put("N", statisticalSummary.getN());
        map.put("var", statisticalSummary.getVariance());
        binList.add(map);
    }
    return binList;
}
Also used : EmpiricalDistribution(org.apache.commons.math3.random.EmpiricalDistribution) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 EmpiricalDistribution (org.apache.commons.math3.random.EmpiricalDistribution)2 StatisticalSummary (org.apache.commons.math3.stat.descriptive.StatisticalSummary)2 SummaryStatistics (org.apache.commons.math3.stat.descriptive.SummaryStatistics)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1