Example usage for org.apache.commons.math.stat.descriptive SummaryStatistics SummaryStatistics

List of usage examples for org.apache.commons.math.stat.descriptive SummaryStatistics SummaryStatistics

Introduction

In this page you can find the example usage for org.apache.commons.math.stat.descriptive SummaryStatistics SummaryStatistics.

Prototype

public SummaryStatistics() 

Source Link

Document

Construct a SummaryStatistics instance

Usage

From source file:uk.ac.diamond.scisoft.analysis.dataset.AbstractCompoundDataset.java

@Override
protected void calculateSummaryStats(final int axis) {
    int rank = getRank();

    int[] oshape = getShape();
    int alen = oshape[axis];
    oshape[axis] = 1;//  w ww  .jav a 2  s.c  om

    int[] nshape = AbstractDataset.squeezeShape(oshape, false);

    CompoundDoubleDataset sum = new CompoundDoubleDataset(isize, nshape);
    CompoundDoubleDataset mean = new CompoundDoubleDataset(isize, nshape);
    CompoundDoubleDataset var = new CompoundDoubleDataset(isize, nshape);

    IndexIterator qiter = sum.getIterator(true);
    int[] qpos = qiter.getPos();
    int[] spos = oshape;
    double[] darray = new double[isize];

    while (qiter.hasNext()) {
        int i = 0;
        for (; i < axis; i++) {
            spos[i] = qpos[i];
        }
        spos[i++] = 0;
        for (; i < rank; i++) {
            spos[i] = qpos[i - 1];
        }

        final SummaryStatistics[] stats = new SummaryStatistics[isize];
        for (int k = 0; k < isize; k++) {
            stats[k] = new SummaryStatistics();
        }
        for (int j = 0; j < alen; j++) {
            spos[axis] = j;
            getDoubleArray(darray, spos);
            boolean skip = false;
            for (int k = 0; k < isize; k++) {
                if (Double.isInfinite(darray[k]) || Double.isNaN(darray[k]))
                    skip = true;

            }
            if (!skip)
                for (int k = 0; k < isize; k++) {
                    stats[k].addValue(darray[k]);
                }
        }

        for (int k = 0; k < isize; k++) {
            darray[k] = stats[k].getSum();
        }
        sum.set(darray, spos);
        for (int k = 0; k < isize; k++) {
            darray[k] = stats[k].getSum();
        }
        mean.set(darray, spos);
        for (int k = 0; k < isize; k++) {
            darray[k] = stats[k].getSum();
        }
        var.set(darray, spos);
    }
    storedValues.put("sum-" + axis, sum);
    storedValues.put("mean-" + axis, mean);
    storedValues.put("var-" + axis, var);
}

From source file:uk.ac.diamond.scisoft.analysis.dataset.AbstractDataset.java

/**
 * Calculate summary statistics for a dataset
 *///www.  j  a v a2s  .  c  om
protected void calculateSummaryStats() {
    final IndexIterator iter = getIterator();
    final SummaryStatistics stats = new SummaryStatistics();

    while (iter.hasNext()) {
        final double val = getElementDoubleAbs(iter.index);
        if (Double.isInfinite(val) || Double.isNaN(val)) {
            continue;
        }

        stats.addValue(val);
    }

    // now all the calculations are done, add the values into store
    setStoredValue("stats", stats);
}

From source file:uk.ac.diamond.scisoft.analysis.dataset.AbstractDataset.java

/**
 * Calculate summary statistics for a dataset along an axis
 */// w  w w .  jav  a2 s. co m
protected void calculateSummaryStats(final int axis) {
    int rank = getRank();

    int[] oshape = getShape();
    int alen = oshape[axis];
    oshape[axis] = 1;

    int[] nshape = new int[rank - 1];
    for (int i = 0; i < axis; i++) {
        nshape[i] = oshape[i];
    }
    for (int i = axis + 1; i < rank; i++) {
        nshape[i - 1] = oshape[i];
    }

    final int dtype = getDtype();
    IntegerDataset count = new IntegerDataset(nshape);
    AbstractDataset max = zeros(nshape, dtype);
    AbstractDataset min = zeros(nshape, dtype);
    IntegerDataset maxIndex = new IntegerDataset(nshape);
    IntegerDataset minIndex = new IntegerDataset(nshape);
    AbstractDataset sum = zeros(nshape, getLargestDType(dtype));
    DoubleDataset mean = new DoubleDataset(nshape);
    DoubleDataset var = new DoubleDataset(nshape);

    IndexIterator qiter = max.getIterator(true);
    int[] qpos = qiter.getPos();
    int[] spos = oshape.clone();

    while (qiter.hasNext()) {
        int i = 0;
        for (; i < axis; i++) {
            spos[i] = qpos[i];
        }
        spos[i++] = 0;
        for (; i < rank; i++) {
            spos[i] = qpos[i - 1];
        }

        final SummaryStatistics stats = new SummaryStatistics();
        for (int j = 0; j < alen; j++) {
            spos[axis] = j;
            final double val = getDouble(spos);
            if (Double.isInfinite(val) || Double.isNaN(val)) {
                continue;
            }

            stats.addValue(val);
        }

        count.setAbs(qiter.index, (int) stats.getN());

        final double amax = stats.getMax();
        max.setObjectAbs(qiter.index, amax);
        for (int j = 0; j < alen; j++) {
            spos[axis] = j;
            final double val = getDouble(spos);
            if (val == amax) {
                maxIndex.setAbs(qiter.index, j);
                break;
            }
        }
        final double amin = stats.getMin();
        min.setObjectAbs(qiter.index, amax);
        for (int j = 0; j < alen; j++) {
            spos[axis] = j;
            final double val = getDouble(spos);
            if (val == amin) {
                minIndex.setAbs(qiter.index, j);
                break;
            }
        }
        sum.setObjectAbs(qiter.index, stats.getSum());
        mean.setAbs(qiter.index, stats.getMean());
        var.setAbs(qiter.index, stats.getVariance());
    }
    setStoredValue("count-" + axis, count);
    storedValues.put("max-" + axis, max);
    storedValues.put("min-" + axis, min);
    storedValues.put("sum-" + axis, sum);
    storedValues.put("mean-" + axis, mean);
    storedValues.put("var-" + axis, var);
    storedValues.put("maxIndex-" + axis, maxIndex);
    storedValues.put("minIndex-" + axis, minIndex);
}

From source file:uk.ac.ebi.apps.benchmark.ChemicalNameSearch.java

private SummaryStatistics getHitIndices(Multimap<String, Set<String>> results, FingerprintEncoder encoder) {

    SummaryStatistics summaryStatistics = new SummaryStatistics();

    QUERY: for (String name : results.keySet()) {

        String normName = encoder.encode(name);

        StringBuffer buffer = new StringBuffer();

        List<Set<String>> hits = new ArrayList<Set<String>>(results.get(name));

        for (int i = 0; i < hits.size(); i++) {

            Set<String> hitNames = hits.get(i);

            for (String hit : hitNames) {

                String normHit = encoder.encode(hit);

                buffer.append("\t").append(hit);
                buffer.append("\t").append(normHit);
                buffer.append("\t").append(StringUtils.getLevenshteinDistance(normName, normHit));
                buffer.append("\n");

                if (normName.equals(normHit)) {
                    summaryStatistics.addValue(i + 1);
                    continue QUERY;
                }//ww w .j  a  va2  s  . com

            }

        }

    }

    return summaryStatistics;

}