本文整理汇总了Java中org.apache.commons.math3.stat.descriptive.DescriptiveStatistics.getStandardDeviation方法的典型用法代码示例。如果您正苦于以下问题:Java DescriptiveStatistics.getStandardDeviation方法的具体用法?Java DescriptiveStatistics.getStandardDeviation怎么用?Java DescriptiveStatistics.getStandardDeviation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.stat.descriptive.DescriptiveStatistics
的用法示例。
在下文中一共展示了DescriptiveStatistics.getStandardDeviation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findLocalMaxima
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; //导入方法依赖的package包/类
/**
* 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;
}
示例2: statBasedSelectMetricHistory
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; //导入方法依赖的package包/类
/**
* filter snapshots using statistically significant points only
* @param selectedLists list of snapshots
*/
private void statBasedSelectMetricHistory(final LinkedList<InMemoryHistoryNode> selectedLists)
throws ClassCastException {
logger.debug("selecting snapshots which are far away from mean value");
DescriptiveStatistics descStats = getDescriptiveStatistics(selectedLists);
Double mean = descStats.getMean();
Double std = descStats.getStandardDeviation();
Iterator<InMemoryHistoryNode> ite = selectedLists.iterator();
while (ite.hasNext()) {
InMemoryHistoryNode currentNode = ite.next();
double value = ((Number) currentNode.getValue()).doubleValue();
// remove all elements which lies in 95% value band
if (value < mean + standardDeviationFactor * std && value > mean - standardDeviationFactor * std) {
ite.remove();
}
}
}
示例3: normalize
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; //导入方法依赖的package包/类
/**
* 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;
}
示例4: getOutlierScore
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; //导入方法依赖的package包/类
/**
* Calculates the outlier score using value to be checked and time series data
*
* @param valueToCheck the given values to check
* @param timeSeriesData the time series data
* @return an outlier score
* @throws Exception
*/
public double getOutlierScore(double valueToCheck, double[] timeSeriesData) {
// get mean and standard deviation
DescriptiveStatistics statistics = new DescriptiveStatistics(timeSeriesData);
double sampleMean = statistics.getMean();
double sampleStdDev = statistics.getStandardDeviation();
// get k (number of standard deviations away from the mean)
double k = getK(probabilityThreshold);
validateChebyshev(valueToCheck, sampleMean, sampleStdDev, k);
double acceptableDeviation = k * sampleStdDev;
double min = sampleMean - acceptableDeviation;
double max = sampleMean + acceptableDeviation;
double currentDeviation = Math.abs(valueToCheck - sampleMean);
double outlierScore = currentDeviation / acceptableDeviation;
UtilsRG.debug("outlierScore = " + outlierScore);
UtilsRG.debug(Math.floor(acceptableDeviation) + " acceptableDeviation");
UtilsRG.debug(valueToCheck + " observed");
UtilsRG.debug(Math.floor(min) + " min");
UtilsRG.debug(Math.floor(max) + " max");
return outlierScore;
}
示例5: testOutlierUsing3SigmaRule
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; //导入方法依赖的package包/类
@Test
public void testOutlierUsing3SigmaRule(){
// some observed data points
double dataPoints[] = {0.464,0.443,0.424,0.386,0.367,0.382,0.455,0.410,0.411,0.424,0.338,0.355,0.342,0.324,
0.354,0.322,0.364,0.375,1.085,0.575,0.597,0.464,0.414,0.408,1.156,0.819,1.156,1.024,1.152,1.103,
0.431,0.378,0.358,0.382,0.354,0.435,0.386,0.361,0.397,0.362,0.334,0.357,0.344,0.362,0.317,0.331,
0.199,0.351,0.284,0.343,0.354,0.336,0.280,0.312,0.778,0.723,0.755,0.774,0.759,0.762,0.490,0.400,
0.364,0.439,0.441,0.673};
DescriptiveStatistics maths = new DescriptiveStatistics(dataPoints);
double sampleMean = maths.getMean();
double sampleStdDev = maths.getStandardDeviation();
double sampleSkev = (Math.abs(sampleMean - maths.getPercentile(50)) / sampleStdDev);
// parameter estimation using method of moments ex-gaussian distribution
double mean = sampleMean - sampleStdDev * Math.pow(sampleSkev/2., 1./3) ;
double stdDev = Math.sqrt(sampleStdDev*(1 - Math.pow(sampleSkev/2., 2./3)));
double tau = sampleStdDev * (Math.pow(sampleSkev/2., 1./3));
double lambda = 1 / tau;
ExponentiallyModifiedGaussianDistribution exGaussian = new ExponentiallyModifiedGaussianDistribution(mean, stdDev, lambda);
isOutlier(exGaussian.getStddev(), 1.2);
}
示例6: isSignificant
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; //导入方法依赖的package包/类
public boolean isSignificant(double singletonKL[],double topValue,double p){
DescriptiveStatistics ds=new DescriptiveStatistics((double[])singletonKL);
double mean=ds.getMean();
double std=ds.getStandardDeviation();
double z=(Math.log(contextShiftingScore)-mean)/std;
//double pValue1;
// Compute z value of the scores based on the null distribution of scores of kmers computed from aptamers with small counts
if (z>0.0)
pvalue = computePValue(z);
else
pvalue=1.0;
if ((pvalue<=p)&&(Math.log(contextShiftingScore)>=topValue))
return true;
else
return false;
}
示例7: getDescStats
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; //导入方法依赖的package包/类
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);
}
示例8: determineSignificance
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; //导入方法依赖的package包/类
/**
* Determines the significance for the given {@link Itemset} by modeling the background normal distribution.
*
* @param itemset The {@link Itemset} for which the significance should be calculated.
*/
private void determineSignificance(Itemset<LabelType> itemset) {
double[] values = backgroundDistributions.get(itemset).getObservations().stream()
.mapToDouble(Double::doubleValue).toArray();
// model normal distribution
DescriptiveStatistics descriptiveStatistics = new DescriptiveStatistics(values);
double mean = descriptiveStatistics.getMean();
double standardDeviation = descriptiveStatistics.getStandardDeviation();
NormalDistribution normalDistribution = new NormalDistribution(mean, standardDeviation);
// calculate KS p-value to estimate quality of fit
double ks = TestUtils.kolmogorovSmirnovTest(normalDistribution, values, false);
if (ks < ksCutoff) {
logger.warn("itemset {} background distribution of type {} violates KS-cutoff, skipping", itemset, type);
return;
}
double pValue = Double.NaN;
if (type == SignificanceEstimatorType.COHESION) {
pValue = normalDistribution.cumulativeProbability(itemset.getCohesion());
} else if (type == SignificanceEstimatorType.CONSENSUS) {
pValue = normalDistribution.cumulativeProbability(itemset.getConsensus());
} else if (type == SignificanceEstimatorType.AFFINITY) {
pValue = normalDistribution.cumulativeProbability(itemset.getAffinity());
}
logger.debug("p-value for itemset {} is {}", itemset.toSimpleString(), pValue);
if (pValue < significanceCutoff) {
Significance significance = new Significance(pValue, ks);
significantItemsets.put(significance, itemset);
logger.info("itemset {} is significant with {}", itemset.toSimpleString(), significance);
}
}
示例9: appendResultLineWithStats
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; //导入方法依赖的package包/类
private void appendResultLineWithStats(Map<Metric, DescriptiveStatistics> results, boolean formatMillis, StringBuilder sb, Metric metric)
{
DescriptiveStatistics statistics = results.get(metric);
double mean = statistics.getMean();
double stdev = statistics.getStandardDeviation();
double confidenceInterval = computeConfidenceInterval(statistics, 0.05);
if (formatMillis && (metric == Metric.TRAIN_TIME || metric == Metric.TEST_TIME))
sb.append(String.format("%s;%s;%s;", formatMillis(mean), formatMillis(stdev), formatMillis(confidenceInterval)));
else
sb.append(String.format("%.2f;%.2f;%.2f;", mean, stdev, confidenceInterval));
}
示例10: standardDeviation
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; //导入方法依赖的package包/类
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();
}
示例11: maxNormAutoCorr
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; //导入方法依赖的package包/类
/**
* Computes the maximum normalized auto correlation of raw with respect to time lags TAU_MIN and TAU_MAX
*/
private double maxNormAutoCorr() {
List<Double> rawConcat = new ArrayList<>();
double std, mean, stdTau, meanTau, sum;
double max = Double.MIN_VALUE;
//int tauOpt = 0;
for (List<Double> l :
raw) {
rawConcat.addAll(l);
}
//Log.i("walk", "Raw size: " + rawConcat.size());
for (int tau = (FastMath.toIntExact(TAU_MIN) / 100) - 1; tau < FastMath.toIntExact(TAU_MAX) / 100; tau += TAU_STEP / 100) {
int tauIndex = indexOfTau(tau);
for (int m = 0; m < rawConcat.size() - (tauIndex * 2) - 1; m++) {
DescriptiveStatistics stats = getStatsForDataSegment(rawConcat.subList(m, m + tauIndex));
//Log.i("walk", "stats size: " + stats.getValues().length);
std = stats.getStandardDeviation();
mean = stats.getMean();
DescriptiveStatistics statsTau = getStatsForDataSegment(rawConcat.subList(m + tauIndex, m + tauIndex * 2));
//Log.i("walk", "statsTau size: " + statsTau.getValues().length);
stdTau = statsTau.getStandardDeviation();
meanTau = statsTau.getMean();
sum = 0;
int k;
for (k = 0; k < tauIndex - 1; k++) {
sum += (rawConcat.get(m + k) - mean) * (rawConcat.get(m + k + tauIndex) - meanTau);
}
double temp = sum / (std * stdTau * tauIndex);
//Log.i("walk", "Tau: " + tau + " - X(" + m + "," + tauIndex + ") = " + temp);
max = max(max, temp);
//if (temp == max) tauOpt = tau;
}
}
return max;
}
示例12: normalize
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; //导入方法依赖的package包/类
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;
}
示例13: isOutlier
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; //导入方法依赖的package包/类
/**
* Check if given value is an outlier in the time series data using z-score
*
* @param valueToCheck the given values to check
* @param timeSeriesData the time series data
* @return true if value is an outlier. Otherwise false.
*/
public boolean isOutlier(double valueToCheck, double[] timeSeriesData) {
// get mean and standard deviation
DescriptiveStatistics statistics = new DescriptiveStatistics(timeSeriesData);
double sampleMean = statistics.getMean();
double sampleStdDev = statistics.getStandardDeviation();
// get z-score
double zScore = getZScore(valueToCheck, sampleMean, sampleStdDev);
// check if z-score is anomalous
return isOutlier(zScore);
}
示例14: standardDeviation
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; //导入方法依赖的package包/类
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();
}
示例15: computePValue
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; //导入方法依赖的package包/类
public void computePValue(double singletonKL[]){
DescriptiveStatistics ds=new DescriptiveStatistics((double[])singletonKL);
double mean=ds.getMean();
double std=ds.getStandardDeviation();
double z=(Math.log(contextShiftingScore)-mean)/std;
if (z>0.0)
pvalue = computePValue(z);
else
pvalue = 1.0;
}