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

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

Introduction

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

Prototype

public DescriptiveStatistics() 

Source Link

Document

Construct a DescriptiveStatistics instance with an infinite window

Usage

From source file:cal.binBased.BinMSnSpectrum.java

public double[] getBin_spectrum(int shift) {
    ArrayList<Double> bin_spec_al = new ArrayList<Double>();
    double binSize = (fragment_tolerance * 2), upperLimit = max_value + 0.00001;
    for (double lowerLimit = min_value; lowerLimit < upperLimit; lowerLimit = lowerLimit + binSize) {
        double tmp_intensity_bin = 0;
        DescriptiveStatistics obj = new DescriptiveStatistics();
        for (Peak p : peakList) {
            double mz = p.getMz() + shift;
            if (mz >= lowerLimit && mz < lowerLimit + binSize) {
                obj.addValue(p.intensity);
            }/*  w  w  w  .j a va 2  s. com*/
        }
        if (obj.getN() > 0) {
            if (intensities_sum_or_mean_or_median == 0) {
                tmp_intensity_bin = obj.getSum();
            } else if (intensities_sum_or_mean_or_median == 1) {
                tmp_intensity_bin = obj.getMean();
            } else if (intensities_sum_or_mean_or_median == 2) {
                tmp_intensity_bin = obj.getPercentile(50);
            }
        }
        // put every bin_pectrum
        bin_spec_al.add(tmp_intensity_bin);
    }
    // convert an arraylist to double array
    // initiate size of array
    bin_size = bin_spec_al.size();
    double[] bin_spectrum = new double[bin_spec_al.size()];
    for (int i = 0; i < bin_spec_al.size(); i++) {
        bin_spectrum[i] = bin_spec_al.get(i);
    }
    return bin_spectrum;
}

From source file:de.mpicbg.knime.hcs.base.nodes.preproc.ParameterMutualInformation.java

@Override
protected BufferedDataTable[] execute(BufferedDataTable[] inData, ExecutionContext exec) throws Exception {

    BufferedDataTable input = inData[0];

    // Get the parameter and make sure there all double value columns
    List<Attribute> parameters = getParameterList(input);

    // Initialize
    int Np = parameters.size();
    int iterations = Np * 2;
    double[][] mutmatrix = new double[Np][Np];
    double[][] sigmatrix = new double[Np][Np];
    ;//from  w w  w.ja va  2 s  . co m
    double[][] biamatrix = new double[Np][Np];
    ;

    MutualInformation mutualinfo = new MutualInformation();
    mutualinfo.set_base(logbase.getDoubleValue());
    mutualinfo.set_method(method.getStringValue());
    mutualinfo.set_axeslinking(linkaxes.getBooleanValue());
    if (binning.getIntValue() > 0)
        mutualinfo.set_binning(binning.getIntValue());

    // Load data.
    Double[][] table = new Double[Np][input.getRowCount()];
    int j = 0;
    for (DataRow row : input) {
        int i = 0;
        for (Attribute param : parameters) {
            table[i][j] = param.getDoubleAttribute(row);
            i++;
        }
        j++;
        exec.checkCanceled();
    }
    BufTableUtils.updateProgress(exec, Np, iterations);

    // Calculate mutual information
    for (int a = 0; a < Np; a++) {
        mutualinfo.set_xvector(table[a]);

        for (int b = a; b < Np; b++) {
            mutualinfo.set_yvector(table[b]);

            // Calculate the mutual info.
            Double[] res = mutualinfo.calculate();

            // Put it into the output matrix
            mutmatrix[a][b] = res[0];
            mutmatrix[b][a] = res[0];
            sigmatrix[a][b] = res[1];
            sigmatrix[b][a] = res[1];
            biamatrix[a][b] = res[2];
            biamatrix[b][a] = res[2];
        }
        BufTableUtils.updateProgress(exec, Np + a, iterations);
        exec.checkCanceled();
    }

    // Create Tables
    BufferedDataContainer matrixContainer = exec.createDataContainer(new DataTableSpec(getMatrixSpec()));
    BufferedDataContainer listContainer = exec.createDataContainer(new DataTableSpec(getListSpec()));
    double thresh = threshold.getDoubleValue();
    int numListCol = listContainer.getTableSpec().getNumColumns();

    for (int a = 0; a < Np; a++) {

        // Initialize
        DataCell[] matrixCells = new DataCell[Np];
        DataCell[] listCells = new DataCell[numListCol];
        String similars = "";
        DescriptiveStatistics mutstats = new DescriptiveStatistics();
        DescriptiveStatistics sigstats = new DescriptiveStatistics();
        ;
        DescriptiveStatistics biastats = new DescriptiveStatistics();
        ;

        // Create matrix rows and collect values for statistics.
        for (int b = 0; b < Np; b++) {
            matrixCells[b] = new DoubleCell(mutmatrix[a][b]);
            if (a != b) {
                mutstats.addValue(mutmatrix[a][b]);
                sigstats.addValue(sigmatrix[a][b]);
                biastats.addValue(biamatrix[a][b]);
                if (mutmatrix[a][b] > thresh) {
                    similars += parameters.get(b).getName() + ",";
                }
            }
        }

        // Create matrix row
        DataRow matrixRow = new DefaultRow(parameters.get(a).getName(), matrixCells);
        matrixContainer.addRowToTable(matrixRow);

        // Create list row
        listCells[0] = new StringCell(parameters.get(a).getName());
        listCells[1] = new DoubleCell(mutstats.getMin());
        listCells[2] = new DoubleCell(mutstats.getMean());
        listCells[3] = new DoubleCell(mutstats.getMax());
        listCells[4] = new DoubleCell(sigstats.getGeometricMean());
        listCells[5] = new DoubleCell(biastats.getMean());
        listCells[6] = new StringCell(similars);
        DataRow listRow = new DefaultRow("row" + a, listCells);
        listContainer.addRowToTable(listRow);

        exec.checkCanceled();
    }

    matrixContainer.close();
    listContainer.close();
    return new BufferedDataTable[] { listContainer.getTable(), matrixContainer.getTable() };
}

From source file:com.netxforge.netxstudio.common.math.NativeFunctions.java

public BigDecimal standardDeviation(List<?> range) {
    assert range != null : new MathException("Range can't be empty");
    DescriptiveStatistics stats = new DescriptiveStatistics();
    double[] dRange = rangeSelection(range);
    for (int i = 0; i < dRange.length; i++) {
        stats.addValue(dRange[i]);/*from   w  w w  .j  a va2  s .  com*/
    }
    return new BigDecimal(stats.getStandardDeviation());
}

From source file:alma.acs.logging.AcsLogger.java

/**
 * Auxiliary ctor. Don't use it directly from outside of this class.
 * //from   www .  java 2  s  .  c  o  m
 * @param logConfig
 *            may be null if <code>allowNullLogConfig==true</code>
 */
protected AcsLogger(String name, String resourceBundleName, LogConfig logConfig, boolean allowNullLogConfig,
        Logger delegate) {
    super(name, resourceBundleName);
    this.delegate = delegate;
    this.logConfig = logConfig;

    if (DEBUG) {
        System.out.println("*** AcsLogger running in DEBUG mode!");
    }
    if (PROFILE) {
        profileLogTimeStats = new DescriptiveStatistics();
        profileMillisecFormatter = new DecimalFormat("#.#");
    }
    addLoggerClass(AcsLogger.class);
    addLoggerClass(Logger.class);
    if (logConfig != null) {
        configureLogging(logConfig);
        logConfig.addSubscriber(this); // passing "this" should only be done when this object is fully constructed.
    } else if (!allowNullLogConfig) {
        throw new NullPointerException("LogConfig must not be null");
    }
}

From source file:com.mozilla.socorro.hadoop.RawDumpSize.java

public int run(String[] args) throws Exception {
    if (args.length != 1) {
        return printUsage();
    }/*w  w w  .j  a  v a  2 s  . c o  m*/

    int rc = -1;
    Job job = initJob(args);
    job.waitForCompletion(true);
    if (job.isSuccessful()) {
        rc = 0;
        FileSystem hdfs = null;
        DescriptiveStatistics rawStats = new DescriptiveStatistics();
        long rawTotal = 0L;
        DescriptiveStatistics processedStats = new DescriptiveStatistics();
        long processedTotal = 0L;
        try {
            hdfs = FileSystem.get(job.getConfiguration());
            Pattern tabPattern = Pattern.compile("\t");
            for (FileStatus status : hdfs.listStatus(FileOutputFormat.getOutputPath(job))) {
                if (!status.isDir()) {
                    BufferedReader reader = null;
                    try {
                        reader = new BufferedReader(new InputStreamReader(hdfs.open(status.getPath())));
                        String line = null;
                        while ((line = reader.readLine()) != null) {
                            String[] splits = tabPattern.split(line);
                            int byteSize = Integer.parseInt(splits[2]);
                            if ("raw".equals(splits[1])) {
                                rawStats.addValue(byteSize);
                                rawTotal += byteSize;
                            } else if ("processed".equals(splits[1])) {
                                processedStats.addValue(byteSize);
                                processedTotal += byteSize;
                            }
                        }
                    } finally {
                        if (reader != null) {
                            reader.close();
                        }
                    }
                }
            }
        } finally {
            if (hdfs != null) {
                hdfs.close();
            }
        }

        System.out.println("===== " + job.getConfiguration().get(START_DATE) + " raw_data:dump =====");
        System.out.println(String.format("Min: %.02f Max: %.02f Mean: %.02f", rawStats.getMin(),
                rawStats.getMax(), rawStats.getMean()));
        System.out.println(String.format("1st Quartile: %.02f 2nd Quartile: %.02f 3rd Quartile: %.02f",
                rawStats.getPercentile(25.0d), rawStats.getPercentile(50.0d), rawStats.getPercentile(75.0d)));
        System.out.println("Total Bytes: " + rawTotal);
        System.out.println("===== " + job.getConfiguration().get(START_DATE) + " processed_data:json =====");
        System.out.println(String.format("Min: %.02f Max: %.02f Mean: %.02f", processedStats.getMin(),
                processedStats.getMax(), processedStats.getMean()));
        System.out.println(String.format("1st Quartile: %.02f 2nd Quartile: %.02f 3rd Quartile: %.02f",
                processedStats.getPercentile(25.0d), processedStats.getPercentile(50.0d),
                processedStats.getPercentile(75.0d)));
        System.out.println("Total Bytes: " + processedTotal);
    }

    return rc;
}

From source file:com.netxforge.netxstudio.common.math.NativeFunctions.java

public double standardDeviation(double[] range) {
    assert range != null : new MathException("Range can't be empty");
    DescriptiveStatistics stats = new DescriptiveStatistics();

    // Add the data from the array
    for (int i = 0; i < range.length; i++) {
        stats.addValue(range[i]);/*from  w  w  w  .  jav  a2 s  .c  o  m*/
    }
    return stats.getStandardDeviation();
}

From source file:cal.binBased.BinMSnSpectrum.java

private ArrayList<double[]> prepareBinSpectra() {
    // first prepare bin-spectrum to be filled with zero
    int size = (2 * correctionFactor) + 1;

    ArrayList<double[]> shiftedSpectra = new ArrayList<double[]>(size);
    for (int i = 0; i < size; i++) {
        double[] shiftedSpectrum = new double[bin_size];
        shiftedSpectra.add(shiftedSpectrum);
    }//from   w ww  .j  av  a 2s . co  m
    // now fill each bin spectrum with correct mz values.
    double binSize = (fragment_tolerance * 2), upperLimit = max_value + 0.00001;
    int current_index = 0;
    for (double lowerLimit = min_value + correctionFactor; lowerLimit < upperLimit
            - correctionFactor; lowerLimit = lowerLimit + binSize) {
        double tmp_intensity_bin = 0;
        DescriptiveStatistics obj = new DescriptiveStatistics();
        for (Peak p : peakList) {
            double mz = p.getMz();
            if (mz >= lowerLimit && mz < lowerLimit + binSize) {
                obj.addValue(p.intensity);
            }
        }
        if (obj.getN() > 0) {
            if (intensities_sum_or_mean_or_median == 0) {
                tmp_intensity_bin = obj.getSum();
            } else if (intensities_sum_or_mean_or_median == 1) {
                tmp_intensity_bin = obj.getMean();
            } else if (intensities_sum_or_mean_or_median == 2) {
                tmp_intensity_bin = obj.getPercentile(50);
            }
        }
        // put every bin_pectrum            
        int filling_index = current_index;
        // check every bin spectrum            
        for (double[] shifted : shiftedSpectra) {
            shifted[filling_index] = tmp_intensity_bin;
            filling_index++;
        }
        current_index++;
    }
    return shiftedSpectra;
}

From source file:edu.usc.goffish.gopher.sample.stats.N_Hop_Stats.java

@Override
public void reduce(List<SubGraphMessage> messageList) {

    if (getSuperStep() == 0) {

        if (messageList == null || messageList.isEmpty()) {
            voteToHalt();/*from  w  w  w. j  a  v  a 2 s  . c om*/
            return;
        }

        for (SubGraphMessage msg : messageList) {

            SubGraphMessage m = new SubGraphMessage(msg.getData());

            for (int id : partitions) {
                sendMessage(id, m);
            }
        }

    } else {

        DescriptiveStatistics statistics = new DescriptiveStatistics();
        for (SubGraphMessage message : messageList) {

            String data = new String(message.getData());
            Double d = Double.parseDouble(data);
            statistics.addValue(d);

        }

        PrintWriter writer = null;
        try {
            writer = new PrintWriter(new FileWriter("Hop_Stats.log", true));
            System.out.println("LOGGER STD_DIV: " + statistics.getStandardDeviation());
            writer.println("LOGGER STD_DIV: " + statistics.getStandardDeviation());
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    System.out.println(
            "[Gopher]Current Reduce Iteration : " + getIteration() + " Current SuperStep : " + getSuperStep());

}

From source file:guineu.modules.database.openQualityControlFileDB.DatasetOpenDialog.java

/**
 * Creates the datasets from selected nodes. Each selected node can be the name of one sample, or
 * the name of a complete data set.//from  w  w w  . jav  a  2 s  .  c om
 *
 * @param node Node from the tree
 */
private void createDataset(CheckNode node) {
    Dataset dataset = null;
    DecimalFormat formatter = new DecimalFormat("####.##");

    String[] data = nodeTable.get(node);
    try {
        if (data != null) {
            dataset = new SimpleQualityControlDataset(data[0]);
            dataset.setType(DatasetType.QUALITYCONTROL);

            ((SimpleQualityControlDataset) dataset).setParameters(data[1], data[0], data[2], data[3], data[4],
                    data[5]);

            for (int i = 1; i <= 12; i++) {
                dataset.addColumnName(String.valueOf(i));
            }

            dataset.addRow(getRow("Date:", data[1]));

            dataset.addRow(getRow("SampleSet:", data[0]));

            dataset.addRow(getRow("Ion Mode:", data[2]));

            dataset.addRow(getRow("Injection volume:", data[3]));

            dataset.addRow(getRow("Sample type:", data[4]));

            dataset.addRow(getRow("", ""));
            dataset.addRow(getRow("", ""));

            dataset.addRow(getRow("Basic parameters for seronorm control samples & batch standard:", ""));

            dataset.addRow(this.getTitles());

            Stats = new DescriptiveStatistics[9];
            for (int i = 0; i < 9; i++) {
                Stats[i] = new DescriptiveStatistics();
            }

            List<SampleInfo> samples = db.getQualityControlRows(Integer.parseInt(data[6]));

            for (SampleInfo s : samples) {
                PeakListRow row = s.getRow(Stats);
                dataset.addRow(row);
                ((SimpleQualityControlDataset) dataset).setRow(row);
            }

            SimplePeakListRowOther row = new SimplePeakListRowOther();
            row.setPeak("1", "MEAN");
            for (int i = 0; i < 9; i++) {
                row.setPeak(String.valueOf(i + 2), formatter.format(Stats[i].getMean()).toString());
            }
            dataset.addRow(row);

            row = new SimplePeakListRowOther();
            row.setPeak("1", "RSD");
            for (int i = 0; i < 9; i++) {
                row.setPeak(String.valueOf(i + 2), formatter
                        .format((Stats[i].getStandardDeviation() * 100) / Stats[i].getMean()).toString());
            }
            dataset.addRow(row);

            dataset.addRow(getRow("", ""));
            dataset.addRow(getRow("", ""));
            // row8
            SimplePeakListRowOther row8 = new SimplePeakListRowOther();
            row8.setPeak("1", "Additional parameters for seronorm control samples & batch standard:");
            dataset.addRow(row8);

            dataset.addRow(this.getTitle2());

            superStats = new DescriptiveStatistics[9];
            for (int i = 0; i < 9; i++) {
                superStats[i] = new DescriptiveStatistics();
            }
            for (SampleInfo s : samples) {
                PeakListRow row2 = s.getRow2(superStats);
                dataset.addRow(row2);
                ((SimpleQualityControlDataset) dataset).setAdditionalRow(row2);
            }

            row = new SimplePeakListRowOther();
            row.setPeak("1", "MEAN");
            for (int i = 0; i < 9; i++) {
                row.setPeak(String.valueOf(i + 2), formatter.format(superStats[i].getMean()).toString());
            }
            dataset.addRow(row);

            row = new SimplePeakListRowOther();
            row.setPeak("1", "RSD");
            for (int i = 0; i < 9; i++) {
                row.setPeak(String.valueOf(i + 2),
                        formatter.format((superStats[i].getStandardDeviation() * 100) / superStats[i].getMean())
                                .toString());
            }
            dataset.addRow(row);

            dataset.addRow(getRow("", ""));
            dataset.addRow(getRow("", ""));
            dataset.addRow(getRow("Comments:", data[5]));
        }
        this.datasets.add(dataset);
    } catch (Exception e) {
    }

}

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step11GoldDataStatistics.java

/**
 * Other statistics: we want to report how many documents and sentences
 * were judged and how many were found relevant among those.
 * Having the total + standard deviation over queries is enough.
 *//*  w  ww  . j a  v a2s .c o  m*/
public static void statistics5(File inputDir, File outputDir) throws IOException {
    PrintWriter pw = new PrintWriter(new FileWriter(new File(outputDir, "stats5.csv")));

    SortedMap<String, DescriptiveStatistics> result = new TreeMap<>();
    result.put("annotatedDocumentsPerQuery", new DescriptiveStatistics());
    result.put("annotatedSentencesPerQuery", new DescriptiveStatistics());
    result.put("relevantSentencesPerQuery", new DescriptiveStatistics());

    // print header
    for (String mapKey : result.keySet()) {
        pw.printf(Locale.ENGLISH, "%s\t%sStdDev\t", mapKey, mapKey);
    }
    pw.println();

    // iterate over query containers
    for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) {
        QueryResultContainer queryResultContainer = QueryResultContainer
                .fromXML(FileUtils.readFileToString(f, "utf-8"));
        System.out.println("Processing " + f);

        int annotatedDocuments = 0;
        int relevantSentences = 0;
        int totalSentences = 0;

        for (QueryResultContainer.SingleRankedResult rankedResult : queryResultContainer.rankedResults) {

            if (rankedResult.plainText != null && !rankedResult.plainText.isEmpty()) {
                annotatedDocuments++;

                if (rankedResult.goldEstimatedLabels != null) {
                    for (QueryResultContainer.SingleSentenceRelevanceVote sentenceRelevanceVote : rankedResult.goldEstimatedLabels) {
                        totalSentences++;

                        if (Boolean.valueOf(sentenceRelevanceVote.relevant)) {
                            relevantSentences++;
                        }
                    }
                }
            }
        }

        result.get("annotatedDocumentsPerQuery").addValue(annotatedDocuments);
        result.get("annotatedSentencesPerQuery").addValue(totalSentences);
        result.get("relevantSentencesPerQuery").addValue(relevantSentences);
    }

    // print results
    // print header
    for (String mapKey : result.keySet()) {
        pw.printf(Locale.ENGLISH, "%.3f\t%.3f\t", result.get(mapKey).getMean(),
                result.get(mapKey).getStandardDeviation());
    }

    pw.close();

}