Java Code Examples for org.apache.commons.math3.stat.descriptive.DescriptiveStatistics#getStandardDeviation()

The following examples show how to use org.apache.commons.math3.stat.descriptive.DescriptiveStatistics#getStandardDeviation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Spectrum.java    From cineast with MIT License 6 votes vote down vote up
/**
 * Find local maxima in the spectrum and returns the indices of those maxima as integer
 * array.
 *
 * @param threshold Threshold for search. Values bellow that threshold won't be considered.
 * @return Array containing indices (zero-based) of local maxima.
 */
public List<Pair<Float, Double>> findLocalMaxima(double threshold, boolean significant) {
    List<Pair<Float,Double>> peaks = new ArrayList<>();
    for (int i=1;i<this.spectrum.length-1;i++) {
        if (this.spectrum[i] < threshold) {
          continue;
        }
        if (spectrum[i] > Math.max(spectrum[i+1], spectrum[i-1])) {
          peaks.add(this.get(i));
        }
    }

    if (significant) {
        DescriptiveStatistics statistics = new DescriptiveStatistics();
        for (Pair<Float, Double> peak : peaks) {
            statistics.addValue(peak.second);
        }
        final double mean = statistics.getMean();
        final double stddev = statistics.getStandardDeviation();
        peaks.removeIf(p -> p.second < (mean + stddev * 2));
    }

    return peaks;
}
 
Example 2
Source File: ExecuteOutlierErrors.java    From BART with MIT License 6 votes vote down vote up
private String printStat(DescriptiveStatistics stats) {
    double mean = stats.getMean();
    double std = stats.getStandardDeviation();
    double median = stats.getPercentile(50);
    double q1 = stats.getPercentile(25);
    double q3 = stats.getPercentile(75);
    double iqr = q3 - q1;
    double trimmedMean = (q1 + q3 + 2 * median) / 4;
    double skewness = stats.getSkewness();

    StringBuilder sb = new StringBuilder();
    sb.append(" *** Distribution Analysis ***").append("\n")
            .append("\tMean= ").append(mean).append("\n")
            .append("\tStd= ").append(std).append("\n")
            .append("\tMedian= ").append(median).append("\n")
            .append("\tQ1= ").append(q1).append("\tQ3=").append(q3).append("\tIQR=").append(iqr).append("\n")
            .append("\tTrimmed Mean= ").append(trimmedMean).append("\n")
            .append("\tSkewness= ").append(skewness).append("\n");
    return sb.toString();
}
 
Example 3
Source File: StatUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Normalize (standardize) the sample, so it is has a mean of 0 and a standard deviation of 1.
 *
 * @param sample Sample to normalize.
 * @return normalized (standardized) sample.
 * @since 2.2
 */
public static double[] normalize(final double[] sample) {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    // Add the data from the series to stats
    for (int i = 0; i < sample.length; i++) {
        stats.addValue(sample[i]);
    }

    // Compute mean and standard deviation
    double mean = stats.getMean();
    double standardDeviation = stats.getStandardDeviation();

    // initialize the standardizedSample, which has the same length as the sample
    double[] standardizedSample = new double[sample.length];

    for (int i = 0; i < sample.length; i++) {
        // z = (x- mean)/standardDeviation
        standardizedSample[i] = (sample[i] - mean) / standardDeviation;
    }
    return standardizedSample;
}
 
Example 4
Source File: StatUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Normalize (standardize) the series, so in the end it is having a mean of 0 and a standard deviation of 1.
 *
 * @param sample Sample to normalize.
 * @return normalized (standardized) sample.
 * @since 2.2
 */
public static double[] normalize(final double[] sample) {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    // Add the data from the series to stats
    for (int i = 0; i < sample.length; i++) {
        stats.addValue(sample[i]);
    }

    // Compute mean and standard deviation
    double mean = stats.getMean();
    double standardDeviation = stats.getStandardDeviation();

    // initialize the standardizedSample, which has the same length as the sample
    double[] standardizedSample = new double[sample.length];

    for (int i = 0; i < sample.length; i++) {
        // z = (x- mean)/standardDeviation
        standardizedSample[i] = (sample[i] - mean) / standardDeviation;
    }
    return standardizedSample;
}
 
Example 5
Source File: StatUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Normalize (standardize) the series, so in the end it is having a mean of 0 and a standard deviation of 1.
 *
 * @param sample Sample to normalize.
 * @return normalized (standardized) sample.
 * @since 2.2
 */
public static double[] normalize(final double[] sample) {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    // Add the data from the series to stats
    for (int i = 0; i < sample.length; i++) {
        stats.addValue(sample[i]);
    }

    // Compute mean and standard deviation
    double mean = stats.getMean();
    double standardDeviation = stats.getStandardDeviation();

    // initialize the standardizedSample, which has the same length as the sample
    double[] standardizedSample = new double[sample.length];

    for (int i = 0; i < sample.length; i++) {
        // z = (x- mean)/standardDeviation
        standardizedSample[i] = (sample[i] - mean) / standardDeviation;
    }
    return standardizedSample;
}
 
Example 6
Source File: StatUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Normalize (standardize) the sample, so it is has a mean of 0 and a standard deviation of 1.
 *
 * @param sample Sample to normalize.
 * @return normalized (standardized) sample.
 * @since 2.2
 */
public static double[] normalize(final double[] sample) {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    // Add the data from the series to stats
    for (int i = 0; i < sample.length; i++) {
        stats.addValue(sample[i]);
    }

    // Compute mean and standard deviation
    double mean = stats.getMean();
    double standardDeviation = stats.getStandardDeviation();

    // initialize the standardizedSample, which has the same length as the sample
    double[] standardizedSample = new double[sample.length];

    for (int i = 0; i < sample.length; i++) {
        // z = (x- mean)/standardDeviation
        standardizedSample[i] = (sample[i] - mean) / standardDeviation;
    }
    return standardizedSample;
}
 
Example 7
Source File: StatUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Normalize (standardize) the series, so in the end it is having a mean of 0 and a standard deviation of 1.
 *
 * @param sample Sample to normalize.
 * @return normalized (standardized) sample.
 * @since 2.2
 */
public static double[] normalize(final double[] sample) {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    // Add the data from the series to stats
    for (int i = 0; i < sample.length; i++) {
        stats.addValue(sample[i]);
    }

    // Compute mean and standard deviation
    double mean = stats.getMean();
    double standardDeviation = stats.getStandardDeviation();

    // initialize the standardizedSample, which has the same length as the sample
    double[] standardizedSample = new double[sample.length];

    for (int i = 0; i < sample.length; i++) {
        // z = (x- mean)/standardDeviation
        standardizedSample[i] = (sample[i] - mean) / standardDeviation;
    }
    return standardizedSample;
}
 
Example 8
Source File: StatUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Normalize (standardize) the sample, so it is has a mean of 0 and a standard deviation of 1.
 *
 * @param sample Sample to normalize.
 * @return normalized (standardized) sample.
 * @since 2.2
 */
public static double[] normalize(final double[] sample) {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    // Add the data from the series to stats
    for (int i = 0; i < sample.length; i++) {
        stats.addValue(sample[i]);
    }

    // Compute mean and standard deviation
    double mean = stats.getMean();
    double standardDeviation = stats.getStandardDeviation();

    // initialize the standardizedSample, which has the same length as the sample
    double[] standardizedSample = new double[sample.length];

    for (int i = 0; i < sample.length; i++) {
        // z = (x- mean)/standardDeviation
        standardizedSample[i] = (sample[i] - mean) / standardDeviation;
    }
    return standardizedSample;
}
 
Example 9
Source File: StatUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Normalize (standardize) the sample, so it is has a mean of 0 and a standard deviation of 1.
 *
 * @param sample Sample to normalize.
 * @return normalized (standardized) sample.
 * @since 2.2
 */
public static double[] normalize(final double[] sample) {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    // Add the data from the series to stats
    for (int i = 0; i < sample.length; i++) {
        stats.addValue(sample[i]);
    }

    // Compute mean and standard deviation
    double mean = stats.getMean();
    double standardDeviation = stats.getStandardDeviation();

    // initialize the standardizedSample, which has the same length as the sample
    double[] standardizedSample = new double[sample.length];

    for (int i = 0; i < sample.length; i++) {
        // z = (x- mean)/standardDeviation
        standardizedSample[i] = (sample[i] - mean) / standardDeviation;
    }
    return standardizedSample;
}
 
Example 10
Source File: StatUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Normalize (standardize) the sample, so it is has a mean of 0 and a standard deviation of 1.
 *
 * @param sample Sample to normalize.
 * @return normalized (standardized) sample.
 * @since 2.2
 */
public static double[] normalize(final double[] sample) {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    // Add the data from the series to stats
    for (int i = 0; i < sample.length; i++) {
        stats.addValue(sample[i]);
    }

    // Compute mean and standard deviation
    double mean = stats.getMean();
    double standardDeviation = stats.getStandardDeviation();

    // initialize the standardizedSample, which has the same length as the sample
    double[] standardizedSample = new double[sample.length];

    for (int i = 0; i < sample.length; i++) {
        // z = (x- mean)/standardDeviation
        standardizedSample[i] = (sample[i] - mean) / standardDeviation;
    }
    return standardizedSample;
}
 
Example 11
Source File: DescriptiveStats.java    From Java-Data-Science-Cookbook with MIT License 5 votes vote down vote up
public void getDescStats(double[] values){
	DescriptiveStatistics stats = new DescriptiveStatistics();
	for( int i = 0; i < values.length; i++) {
	        stats.addValue(values[i]);
	}
	double mean = stats.getMean();
	double std = stats.getStandardDeviation();
	double median = stats.getPercentile(50);
	System.out.println(mean + "\t" + std + "\t" + median);
}
 
Example 12
Source File: ColumnarStructureX.java    From mmtf-spark with Apache License 2.0 5 votes vote down vote up
/**
 * Returns z-scores for B-factors (normalized B-factors).
 * 
 * Critical z-score values: Confidence level Tail Area z critical 
 *                          90%              0.05      +-1.645 
 *                          95%              0.025     +-1.96 
 *                          99%              0.005     +-2.576
 * 
 * @return
 */
public float[] getNormalizedbFactors() {
    if (normalizedbFactors == null) {
        normalizedbFactors = new float[getNumAtoms()];

        float[] bFactors = getbFactors();
        String[] types = getEntityTypes();

        DescriptiveStatistics stats = new DescriptiveStatistics();
        for (int i = 0; i < getNumAtoms(); i++) {
            if (! (types[i].equals("WAT"))) {
                stats.addValue(bFactors[i]);
            }
        }
        double mean = stats.getMean();
        double stddev = stats.getStandardDeviation();

        if (stddev > EPSILON) {
            for (int i = 0; i < getNumAtoms(); i++) {
                normalizedbFactors[i] = (float) ((bFactors[i] - mean) / stddev);
            }
        } else {
            Arrays.fill(normalizedbFactors, Float.MAX_VALUE);
        }
    }

    return normalizedbFactors;
}
 
Example 13
Source File: CorrelationTechniquesReducer.java    From data-polygamy with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private double[] normalize(double[] array) {
    DescriptiveStatistics stats = new DescriptiveStatistics(array);
    double mean = stats.getMean();
    double stdDev = stats.getStandardDeviation();
    for (int i = 0; i < array.length; i++) {
        array[i] = (array[i] - mean)/stdDev;
    }
    return array;
}
 
Example 14
Source File: RespTimeStdDevTest.java    From lightning with MIT License 5 votes vote down vote up
@Override
protected void calculateActualResult(JmeterTransactions jmeterTransactions) {
    DescriptiveStatistics ds = new DescriptiveStatistics();
    jmeterTransactions.asStream()
            .map(t -> (double) t.getElapsed())
            .forEach(ds::addValue);
    actualResult = (int) ds.getStandardDeviation();
}
 
Example 15
Source File: RPCA.java    From Surus with Apache License 2.0 5 votes vote down vote up
private double standardDeviation(double[][] x) {
	DescriptiveStatistics stats = new DescriptiveStatistics();
	for (int i = 0; i < x.length; i ++)
		for (int j = 0; j < x[i].length; j++)
			stats.addValue(x[i][j]);
	return stats.getStandardDeviation();
}