Example usage for org.apache.commons.math.stat.descriptive DescriptiveStatistics addValue

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

Introduction

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

Prototype

public void addValue(double v) 

Source Link

Document

Adds the value to the dataset.

Usage

From source file:guineu.modules.dataanalysis.variationCoefficientRow.variationCoefficientRowFilterTask.java

public double CoefficientOfVariation(PeakListRow row) {
    DescriptiveStatistics stats = new DescriptiveStatistics();
    for (Object peak : row.getPeaks(null)) {
        if (peak != null) {
            stats.addValue((Double) peak);
        }/*www  .  j  av a 2 s.com*/
    }
    return stats.getStandardDeviation() / stats.getMean();
}

From source file:cs.cirg.cida.analysis.ColumnBasedDescriptiveStatistics.java

@Override
public DataTable operate(DataTable dataTable) throws CIlibIOException {
    iterationsDescriptiveStatistics = new ArrayList<DescriptiveStatistics>();

    List<Integer> selectedColumns = this.getSelectedItems();
    int size = dataTable.getNumRows();
    for (int rowIndex = 0; rowIndex < size; rowIndex++) {
        DescriptiveStatistics stats = new DescriptiveStatistics();
        List<Numeric> row = (List<Numeric>) dataTable.getRow(rowIndex);
        for (Integer i : selectedColumns) {
            stats.addValue(row.get(i).getReal());
        }/* ww  w . j a va  2 s . c  om*/
        iterationsDescriptiveStatistics.add(stats);
    }
    return dataTable;
}

From source file:net.sourceforge.jags.model.ModelTest.java

@Test
public void testUnobservedStochasticNode() throws MathException {
    Node mu = model.addConstantNode(new int[] { 1 }, new double[] { 0 });
    Node tau = model.addConstantNode(new int[] { 1 }, new double[] { 1 });
    int N = 1000;
    Node n = model.addStochasticNode("dnorm", new Node[] { mu, tau }, null, null, null);
    model.initialize(true);//w  w  w. j  a v  a  2  s  .c  o m
    model.stopAdapting();
    Monitor m = model.addTraceMonitor(n);
    model.update(N);
    assertEquals(N, model.getCurrentIteration());
    assertEquals(N, m.dim()[1]); // Iterations dimension

    DescriptiveStatistics stats = new DescriptiveStatistics();
    for (double v : m.value(0)) {
        stats.addValue(v);
    }
    TTest test = new TTestImpl();
    assertFalse(test.tTest(0, m.value(0), 0.05));
}

From source file:net.sourceforge.jags.model.ModelTest.java

@Test
public void testObservedStochasticNode() throws MathException {
    double[] data = normalSample();
    Node mu = model.addConstantNode(new int[] { 1 }, new double[] { 1 });
    Node tau = model.addConstantNode(new int[] { 1 }, new double[] { .001 });
    Node n = model.addStochasticNode("dnorm", new Node[] { mu, tau }, null, null, new double[] { 0 });

    model.initialize(true);//from w w  w .  ja v a  2  s .  c o  m
    model.update(1000);

    int N = 1000;
    model.stopAdapting();
    Monitor m = model.addTraceMonitor(n);
    model.update(N);
    assertEquals(N, m.dim()[1]); // Iterations dimension

    DescriptiveStatistics stats = new DescriptiveStatistics();
    for (double v : m.value(0)) {
        stats.addValue(v);
    }
    TTest test = new TTestImpl();
    assertFalse(test.tTest(0, m.value(0), 0.05));
}

From source file:de.unidue.langtech.teaching.rp.uimatools.Stopwatch.java

@Override
public void collectionProcessComplete() throws AnalysisEngineProcessException {
    super.collectionProcessComplete();

    if (isDownstreamTimer()) {
        getLogger().info("Results from Timer '" + timerName + "' after processing all documents.");

        DescriptiveStatistics statTimes = new DescriptiveStatistics();
        for (Long timeValue : times) {
            statTimes.addValue((double) timeValue / 1000);
        }//from ww w.  ja  va2 s .  c  o  m
        double sum = statTimes.getSum();
        double mean = statTimes.getMean();
        double stddev = statTimes.getStandardDeviation();

        StringBuilder sb = new StringBuilder();
        sb.append("Estimate after processing " + times.size() + " documents.");
        sb.append("\n");

        Formatter formatter = new Formatter(sb, Locale.US);

        formatter.format("Aggregated time: %,.1fs\n", sum);
        formatter.format("Time / Document: %,.3fs (%,.3fs)\n", mean, stddev);

        formatter.close();

        getLogger().info(sb.toString());

        if (outputFile != null) {
            try {
                Properties props = new Properties();
                props.setProperty(KEY_SUM, "" + sum);
                props.setProperty(KEY_MEAN, "" + mean);
                props.setProperty(KEY_STDDEV, "" + stddev);
                OutputStream out = new FileOutputStream(outputFile);
                props.store(out, "timer " + timerName + " result file");
            } catch (FileNotFoundException e) {
                throw new AnalysisEngineProcessException(e);
            } catch (IOException e) {
                throw new AnalysisEngineProcessException(e);
            }
        }
    }
}

From source file:gov.nih.nci.caintegrator.analysis.messaging.DataPointVector.java

/**
 * Compute the mean of the values in the list
 * @param values//www .  ja  v  a 2  s.com
 * @return
 */
private Double computeMean(List<Double> values) {

    DescriptiveStatistics stats = DescriptiveStatistics.newInstance();

    //       Add the data from the array
    for (Double value : values) {
        stats.addValue(value);
    }
    double mean = stats.getMean();
    return new Double(mean);
}

From source file:gov.nih.nci.caintegrator.analysis.messaging.DataPointVector.java

private Double computeStdDeviation(List<Double> values) {
    DescriptiveStatistics stats = DescriptiveStatistics.newInstance();

    //       Add the data from the array
    for (Double value : values) {
        stats.addValue(value);
    }//from www .j  a v  a2s  .co m

    //       Compute some statistics 
    //double mean = stats.getMean();
    //      double median = stats.getMedian();
    double std = stats.getStandardDeviation();
    return new Double(std);

}

From source file:info.raack.appliancelabeler.machinelearning.appliancedetection.algorithms.HighConfidenceFSMPowerSpikeDetectionAlgorithm.java

private Map<Integer, Integer[]> computeTrainingInstanceSpikeLimits(
        List<double[]> trainingInstancesWithClassLabels) {
    Map<Integer, List<Double>> trainingSpikes = new HashMap<Integer, List<Double>>();

    // collect all spikes for each class
    for (double[] instance : trainingInstancesWithClassLabels) {
        double clazz = instance[instance.length - 1];
        if (clazz != missingValue) {
            double trainingSpike = instance[0];

            if (!trainingSpikes.containsKey((int) clazz)) {
                trainingSpikes.put((int) clazz, new ArrayList<Double>());
            }//from  ww w.j  a  v a 2s .co  m
            trainingSpikes.get((int) clazz).add(trainingSpike);
        }
    }

    Map<Integer, Integer[]> trainingInstanceLimits = new HashMap<Integer, Integer[]>();

    // calculate interval one standard deviation away from mean of labeled power spikes for each class
    for (Integer clazz : trainingSpikes.keySet()) {
        DescriptiveStatistics stats = new DescriptiveStatistics();
        for (Double spikeValue : trainingSpikes.get(clazz)) {
            stats.addValue(spikeValue);
        }
        trainingInstanceLimits.put(clazz,
                new Integer[] { (int) (stats.getMean() - stats.getStandardDeviation()),
                        (int) (stats.getMean() + stats.getStandardDeviation()) });
    }

    return trainingInstanceLimits;
}

From source file:de.mpicbg.knime.hcs.base.utils.MutualInformation.java

private Double[] minmax(Double[] vect) {
    DescriptiveStatistics stats = new DescriptiveStatistics();
    for (Double value : vect) {
        stats.addValue(value);
    }//from w  w  w  .j ava 2 s  . c  om
    return new Double[] { stats.getMin(), stats.getMax() };
}

From source file:de.mpicbg.knime.hcs.base.utils.MutualInformation.java

private Double[] minmax(Double[] vect1, Double[] vect2) {
    DescriptiveStatistics stats = new DescriptiveStatistics();
    for (Double value : vect1) {
        stats.addValue(value);
    }//  w  w w. j a v  a2s  . c o  m
    for (Double value : vect2) {
        stats.addValue(value);
    }
    return new Double[] { stats.getMin(), stats.getMax() };
}