Package org.apache.commons.math.stat.descriptive

Examples of org.apache.commons.math.stat.descriptive.DescriptiveStatistics


     * @param file
     * @param statistical summary
     */
    private void loadStats(String resource, Object u) throws Exception {
       
        DescriptiveStatistics d = null;
        SummaryStatistics s = null;
        if (u instanceof DescriptiveStatistics) {
            d = (DescriptiveStatistics) u;
        } else {
            s = (SummaryStatistics) u;
        }
        u.getClass().getDeclaredMethod(
                "clear", new Class[]{}).invoke(u, new Object[]{});
        mean = Double.NaN;
        std = Double.NaN;
       
        BufferedReader in =
            new BufferedReader(
                    new InputStreamReader(
                            CertifiedDataTest.class.getResourceAsStream(resource)));
       
        String line = null;
       
        for (int j = 0; j < 60; j++) {
            line = in.readLine();
            if (j == 40) {
                mean =
                    Double.parseDouble(
                            line.substring(line.lastIndexOf(":") + 1).trim());
            }
            if (j == 41) {
                std =
                    Double.parseDouble(
                            line.substring(line.lastIndexOf(":") + 1).trim());
            }
        }
       
        line = in.readLine();
       
        while (line != null) {
            if (d != null) {
                d.addValue(Double.parseDouble(line.trim()));
            else {
                s.addValue(Double.parseDouble(line.trim()));
            }
            line = in.readLine();
        }
View Full Code Here


    private SummaryStatistics summaries;
   
    private Map certifiedValues;
   
    protected void setUp() throws Exception {
        descriptives = new DescriptiveStatistics();
        summaries = new SummaryStatistics();
        certifiedValues = new HashMap();
       
        loadData();
    }
View Full Code Here

    @Test
    public void testMultiplePositions()
            throws Exception
    {
        DescriptiveStatistics stats = new DescriptiveStatistics();

        for (int i = 0; i < 500; ++i) {
            int uniques = ThreadLocalRandom.current().nextInt(20000) + 1;

            List<Object> values = createRandomSample(uniques, (int) (uniques * 1.5));

            long actual = estimateCount(values, 0);
            double error = (actual - uniques) * 1.0 / uniques;

            stats.addValue(error);
        }

        assertLessThan(stats.getMean(), 1e-2);
        assertLessThan(Math.abs(stats.getStandardDeviation() - getAggregationFunction().getStandardError()), 1e-2);
    }
View Full Code Here

    @Test
    public void testTableSampleBernoulli()
            throws Exception
    {
        DescriptiveStatistics stats = new DescriptiveStatistics();

        int total = computeExpected("SELECT orderkey FROM orders", TupleInfo.SINGLE_LONG).getMaterializedTuples().size();

        for (int i = 0; i < 100; i++) {
            List<MaterializedTuple> values = computeActual("SELECT orderkey FROM ORDERS TABLESAMPLE BERNOULLI (50)").getMaterializedTuples();

            assertEquals(values.size(), ImmutableSet.copyOf(values).size(), "TABLESAMPLE produced duplicate rows");
            stats.addValue(values.size() * 1.0 / total);
        }

        double mean = stats.getGeometricMean();
        assertTrue(mean > 0.45 && mean < 0.55, String.format("Expected mean sampling rate to be ~0.5, but was %s", mean));
    }
View Full Code Here

    @Test
    public void testTableSampleBernoulli()
            throws Exception
    {
        DescriptiveStatistics stats = new DescriptiveStatistics();

        int total = computeExpected("SELECT orderkey FROM orders", TupleInfo.SINGLE_LONG).getMaterializedTuples().size();

        for (int i = 0; i < 100; i++) {
            List<MaterializedTuple> values = computeActual("SELECT orderkey FROM ORDERS TABLESAMPLE BERNOULLI (50)").getMaterializedTuples();

            assertEquals(values.size(), ImmutableSet.copyOf(values).size(), "TABLESAMPLE produced duplicate rows");
            stats.addValue(values.size() * 1.0 / total);
        }

        double mean = stats.getGeometricMean();
        assertTrue(mean > 0.45 && mean < 0.55, String.format("Expected mean sampling rate to be ~0.5, but was %s", mean));
    }
View Full Code Here

    @Test
    public void testMultiplePositions()
            throws Exception
    {
        DescriptiveStatistics stats = new DescriptiveStatistics();

        for (int i = 0; i < 500; ++i) {
            int uniques = ThreadLocalRandom.current().nextInt(20000) + 1;

            List<Object> values = createRandomSample(uniques, (int) (uniques * 1.5));

            long actual = estimateGroupByCount(values);
            double error = (actual - uniques) * 1.0 / uniques;

            stats.addValue(error);
        }

        assertLessThan(stats.getMean(), 1.0e-2);
        assertLessThan(Math.abs(stats.getStandardDeviation() - ApproximateCountDistinctAggregation.getStandardError()), 1.0e-2);
    }
View Full Code Here

    @Test
    public void testTableSampleBernoulli()
            throws Exception
    {
        DescriptiveStatistics stats = new DescriptiveStatistics();

        int total = computeExpected("SELECT orderkey FROM orders", ImmutableList.of(SINGLE_LONG)).getMaterializedTuples().size();

        for (int i = 0; i < 100; i++) {
            List<MaterializedTuple> values = computeActual("SELECT orderkey FROM ORDERS TABLESAMPLE BERNOULLI (50)").getMaterializedTuples();

            assertEquals(values.size(), ImmutableSet.copyOf(values).size(), "TABLESAMPLE produced duplicate rows");
            stats.addValue(values.size() * 1.0 / total);
        }

        double mean = stats.getGeometricMean();
        assertTrue(mean > 0.45 && mean < 0.55, String.format("Expected mean sampling rate to be ~0.5, but was %s", mean));
    }
View Full Code Here

    return dataMatrix;
  }

  private void scale(double[][] peakList) {
    DescriptiveStatistics stdDevStats = new DescriptiveStatistics();

    for (int columns = 0; columns < peakList.length; columns++) {
      stdDevStats.clear();
      for (int row = 0; row < peakList[columns].length; row++) {
        if (!Double.isInfinite(peakList[columns][row])
            && !Double.isNaN(peakList[columns][row])) {
          stdDevStats.addValue(peakList[columns][row]);
        }
      }

      double stdDev = stdDevStats.getStandardDeviation();

      for (int row = 0; row < peakList[columns].length; row++) {
        if (stdDev != 0) {
          peakList[columns][row] = peakList[columns][row] / stdDev;
        }
View Full Code Here

  private double[][] groupingDataset(UserParameter selectedParameter,
      String referenceGroup) {
    // Collect all data files
    Vector<RawDataFile> allDataFiles = new Vector<RawDataFile>();
    DescriptiveStatistics meanControlStats = new DescriptiveStatistics();
    DescriptiveStatistics meanGroupStats = new DescriptiveStatistics();
    allDataFiles.addAll(Arrays.asList(peakList.getRawDataFiles()));

    // Determine the reference group and non reference group (the rest of
    // the samples) for raw data files
    List<RawDataFile> referenceDataFiles = new ArrayList<RawDataFile>();
    List<RawDataFile> nonReferenceDataFiles = new ArrayList<RawDataFile>();

    List<String> groups = new ArrayList<String>();
    MZmineProject project = MZmineCore.getCurrentProject();

    for (RawDataFile rawDataFile : allDataFiles) {

      Object paramValue = project.getParameterValue(selectedParameter,
          rawDataFile);
      if (!groups.contains(String.valueOf(paramValue))) {
        groups.add(String.valueOf(paramValue));
      }
      if (String.valueOf(paramValue).equals(referenceGroup)) {

        referenceDataFiles.add(rawDataFile);
      } else {

        nonReferenceDataFiles.add(rawDataFile);
      }
    }

    int numRows = 0;
    for (int row = 0; row < peakList.getNumberOfRows(); row++) {

      if (!onlyIdentified
          || (onlyIdentified && peakList.getRow(row)
              .getPeakIdentities().length > 0)) {
        numRows++;
      }
    }

    // Create a new aligned peak list with all the samples if the reference
    // group has to be shown or with only
    // the non reference group if not.
    double[][] dataMatrix = new double[groups.size() - 1][numRows];
    pValueMatrix = new String[groups.size() - 1][numRows];

    // data files that should be in the heat map
    List<RawDataFile> shownDataFiles = nonReferenceDataFiles;

    for (int row = 0, rowIndex = 0; row < peakList.getNumberOfRows(); row++) {
      PeakListRow rowPeak = peakList.getRow(row);
      if (!onlyIdentified
          || (onlyIdentified && rowPeak.getPeakIdentities().length > 0)) {
        // Average area or height of the reference group
        meanControlStats.clear();
        for (int column = 0; column < referenceDataFiles.size(); column++) {

          if (rowPeak.getPeak(referenceDataFiles.get(column)) != null) {

            if (area) {

              meanControlStats.addValue(rowPeak.getPeak(
                  referenceDataFiles.get(column)).getArea());
            } else {

              meanControlStats
                  .addValue(rowPeak.getPeak(
                      referenceDataFiles.get(column))
                      .getHeight());
            }

          }
        }

        // Divide the area or height of each peak by the average of the
        // area or height of the reference peaks in each row
        int columnIndex = 0;
        for (int column = 0; column < groups.size(); column++) {
          String group = groups.get(column);
          meanGroupStats.clear();
          if (!group.equals(referenceGroup)) {

            for (int dataColumn = 0; dataColumn < shownDataFiles
                .size(); dataColumn++) {

              Object paramValue = project.getParameterValue(
                  selectedParameter,
                  shownDataFiles.get(dataColumn));
              if (rowPeak.getPeak(shownDataFiles.get(dataColumn)) != null
                  && String.valueOf(paramValue).equals(group)) {

                ChromatographicPeak peak = rowPeak
                    .getPeak(shownDataFiles.get(dataColumn));

                if (!Double.isInfinite(peak.getArea())
                    && !Double.isNaN(peak.getArea())) {

                  if (area) {

                    meanGroupStats.addValue(peak.getArea());
                  } else {

                    meanGroupStats.addValue(peak
                        .getHeight());
                  }
                }

              }
            }

            double value = meanGroupStats.getMean()
                / meanControlStats.getMean();
            if (meanGroupStats.getN() > 1
                && meanControlStats.getN() > 1) {
              pValueMatrix[columnIndex][rowIndex] = this
                  .getPvalue(meanGroupStats, meanControlStats);
            } else {
              pValueMatrix[columnIndex][rowIndex] = "";
View Full Code Here

  public ReleaseStatistics(Result<Task> task)
  {
    this(task.getTask());
   
    DescriptiveStatistics mem = task.getMemory();
    addMemStat("avg",mem.getMean());
    addMemStat("var",mem.getVariance());
    addMemStat("n",mem.getN());
   
    DescriptiveStatistics time = task.getTime();
    addTimeStat("avg", time.getMean());
    addTimeStat("var", mem.getVariance());
    addTimeStat("n", mem.getN());
  }
View Full Code Here

TOP

Related Classes of org.apache.commons.math.stat.descriptive.DescriptiveStatistics

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.