本文整理汇总了Java中org.apache.commons.math3.stat.descriptive.moment.StandardDeviation类的典型用法代码示例。如果您正苦于以下问题:Java StandardDeviation类的具体用法?Java StandardDeviation怎么用?Java StandardDeviation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StandardDeviation类属于org.apache.commons.math3.stat.descriptive.moment包,在下文中一共展示了StandardDeviation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testStdDevOperation
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; //导入依赖的package包/类
@Test
public void testStdDevOperation() throws Exception {
List<Map<String, Object>> expected = JsonFileUtil.readJsonFromResource("raw.json");
double[] doubleList = new double[expected.size()];
int i = 0;
for (Map<String, Object> o : expected) {
doubleList[i++] = (double) ((Map) o.get("test")).get("f");
}
double stddev = new StandardDeviation().evaluate(doubleList);
Aggregation aggregation = new AggregationBuilder()
.addOperation("stddev", new StdDevPopOperation("test.f"))
.getAggregation();
List<Map<String, Object>> result = aggregation.aggregate(jsonList);
assertEquals("Standard Deviation should be as expected",
stddev,
result.get(0).get("stddev"));
}
示例2: computePopulationStandardDeviationOfBigDecimals
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; //导入依赖的package包/类
public static BigDecimal computePopulationStandardDeviationOfBigDecimals(List<BigDecimal> numbers) {
if ((numbers == null) || numbers.isEmpty()) {
return null;
}
try {
double[] doublesArray = new double[numbers.size()];
for (int i = 0; i < doublesArray.length; i++) {
doublesArray[i] = numbers.get(i).doubleValue();
}
StandardDeviation standardDeviation = new StandardDeviation();
standardDeviation.setBiasCorrected(false);
BigDecimal standardDeviationResult = new BigDecimal(standardDeviation.evaluate(doublesArray));
return standardDeviationResult;
}
catch (Exception e) {
logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
return null;
}
}
示例3: calculateParamStdDev
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; //导入依赖的package包/类
/**
* @param numberOfUtterances number of utterances
* @param fileNumber file number
* @param audioParams audio parameters
* @param stdDevParam old standard deviation value of audio parameter
* @return stdDevParam new standard deviation value of audio parameter
*/
private static double[][] calculateParamStdDev(int numberOfUtterances, int fileNumber, String[][] audioParams, double[][] stdDevParam) {
for (int cols=0; cols<HEADER_COLUMNS; cols++) {
stdDevParam[fileNumber][cols] = 0;
}
for (int cols=HEADER_COLUMNS; cols<PARAMS_NUM; cols++) {
double[] colValues = new double[numberOfUtterances];
for (int rows =0; rows< numberOfUtterances; rows++) {
if (!audioParams[rows][cols].equals("")) {
colValues[rows] = Double.parseDouble(audioParams[rows][cols].replace("%",""));
}
else
colValues[rows] = 0;
}
stdDevParam[fileNumber][cols] = new StandardDeviation().evaluate(colValues);
}
return stdDevParam;
}
示例4: computeStat
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; //导入依赖的package包/类
public void computeStat(double duration, int maxUsers) {
double[] times = getDurationAsArray();
min = (long) StatUtils.min(times);
max = (long) StatUtils.max(times);
double sum = 0;
for (double d : times) sum += d;
avg = sum / times.length;
p50 = (long) StatUtils.percentile(times, 50.0);
p95 = (long) StatUtils.percentile(times, 95.0);
p99 = (long) StatUtils.percentile(times, 99.0);
StandardDeviation stdDev = new StandardDeviation();
stddev = (long) stdDev.evaluate(times, avg);
this.duration = duration;
this.maxUsers = maxUsers;
rps = (count - errorCount) / duration;
startDate = getDateFromInstant(start);
successCount = count - errorCount;
}
示例5: get_cv
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; //导入依赖的package包/类
public Map<String, Double> get_cv(String[] group_var, String[] uniq_group){
Map<String, Double> group_to_cv_map = new TreeMap<String, Double>();
Map<String, ArrayList<Double> > grouped_y = new TreeMap<String, ArrayList<Double>>();
for (String aUniq_group : uniq_group){
grouped_y.put(aUniq_group, new ArrayList<Double>());
for (int i = 0; i < group_var.length; i++) {
if (group_var[i].equals(aUniq_group)){
grouped_y.get(aUniq_group).add(this.y_list.get(i));
}
}
}
StandardDeviation std_stat = new StandardDeviation(true);
Mean mean_stat = new Mean();
for(Iterator<Map.Entry<String, ArrayList<Double>>> it = grouped_y.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, ArrayList<Double>> entry = it.next();
double[] cur_y_arr = ArrayUtils.toPrimitive(entry.getValue().toArray(new Double[entry.getValue().size()]));
double std = std_stat.evaluate(cur_y_arr);
double mean = mean_stat.evaluate(cur_y_arr);
group_to_cv_map.put(entry.getKey(), std/mean);
}
this.cv = group_to_cv_map;
return group_to_cv_map;
}
示例6: calculateT
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; //导入依赖的package包/类
private static double calculateT(final ReadCountCollection tangentNormalizedCoverage, final List<ModeledSegment> segments) {
//Get the segments that are likely copy neutral.
// Math.abs removed to mimic python...
final List<ModeledSegment> copyNeutralSegments = segments.stream().filter(s -> s.getSegmentMean() < COPY_NEUTRAL_CUTOFF).collect(Collectors.toList());
// Get the targets that correspond to the copyNeutralSegments... note that individual targets, due to noise,
// can be far away from copy neutral
final TargetCollection<ReadCountRecord.SingleSampleRecord> targetsWithCoverage =
new HashedListTargetCollection<>(tangentNormalizedCoverage.records().stream().map(ReadCountRecord::asSingleSampleRecord).collect(Collectors.toList()));
final double[] copyNeutralTargetsCopyRatio = copyNeutralSegments.stream()
.flatMap(s -> targetsWithCoverage.targets(s).stream())
.mapToDouble(ReadCountRecord.SingleSampleRecord::getCount).toArray();
final double meanCopyNeutralTargets = new Mean().evaluate(copyNeutralTargetsCopyRatio);
final double sigmaCopyNeutralTargets = new StandardDeviation().evaluate(copyNeutralTargetsCopyRatio);
// Now we filter outliers by only including those w/in 2 standard deviations.
final double [] filteredCopyNeutralTargetsCopyRatio = Arrays.stream(copyNeutralTargetsCopyRatio)
.filter(c -> Math.abs(c - meanCopyNeutralTargets) < sigmaCopyNeutralTargets * Z_THRESHOLD).toArray();
return new StandardDeviation().evaluate(filteredCopyNeutralTargetsCopyRatio);
}
示例7: testSliceSamplingOfNormalDistribution
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; //导入依赖的package包/类
/**
* Test slice sampling of a normal distribution. Checks that input mean and standard deviation are recovered
* by 10000 samples to a relative error of 0.5% and 2%, respectively.
*/
@Test
public void testSliceSamplingOfNormalDistribution() {
rng.setSeed(RANDOM_SEED);
final double mean = 5.;
final double standardDeviation = 0.75;
final NormalDistribution normalDistribution = new NormalDistribution(mean, standardDeviation);
final Function<Double, Double> normalLogPDF = normalDistribution::logDensity;
final double xInitial = 1.;
final double xMin = Double.NEGATIVE_INFINITY;
final double xMax = Double.POSITIVE_INFINITY;
final double width = 0.5;
final int numSamples = 10000;
final SliceSampler normalSampler = new SliceSampler(rng, normalLogPDF, xMin, xMax, width);
final double[] samples = Doubles.toArray(normalSampler.sample(xInitial, numSamples));
final double sampleMean = new Mean().evaluate(samples);
final double sampleStandardDeviation = new StandardDeviation().evaluate(samples);
Assert.assertEquals(relativeError(sampleMean, mean), 0., 0.005);
Assert.assertEquals(relativeError(sampleStandardDeviation, standardDeviation), 0., 0.02);
}
示例8: evaluate
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; //导入依赖的package包/类
@Override
/**
* @return [0] Mean distance [1] SD distance
*/
public double[] evaluate() {
splinefit = new TrajectorySplineFit(t,nSegments);
splinefit.calculateSpline();
if(!splinefit.wasSuccessfull()){
return new double[] {Double.NaN,Double.NaN};
}
double[] data = new double[t.size()];
for(int i = 0; i < t.size(); i++){
Point2D.Double help = new Point2D.Double(splinefit.getRotatedTrajectory().get(i).x, splinefit.getRotatedTrajectory().get(i).y);
data[i] = help.distance(splinefit.minDistancePointSpline(new Point2D.Double(splinefit.getRotatedTrajectory().get(i).x, splinefit.getRotatedTrajectory().get(i).y), 50));
}
Mean m = new Mean();
StandardDeviation sd = new StandardDeviation();
result = new double[] {m.evaluate(data),sd.evaluate(data)};
return result;
}
示例9: assertLongTermStd
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; //导入依赖的package包/类
/**
* Assert that the long term mean of values drawn from a {@link RandomSeries} object
* is as expected.
*
* @param series (<code>S</code>) <br>
* The {@link RandomSeries} object to test.
* @param numberOfSamples <br>
* The number of samples to draw from <code>S</code>.
* @param expectedLongTermStd <br>
* The expected long term standard deviation of the series.
*/
protected void assertLongTermStd(
RandomSeries series,
final int numberOfSamples,
final double expectedLongTermStd
) {
final List<Double>
observations = new ArrayList<Double>();
for(int i = 0; i< numberOfSamples; ++i)
observations.add(series.next());
final double observedMean =
(new StandardDeviation()).evaluate(ArrayUtils.toPrimitive(
observations.toArray(new Double[observations.size()])));
Assert.assertEquals(observedMean, expectedLongTermStd, 1.e-1);
}
示例10: testPinkNoise
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; //导入依赖的package包/类
@Test
public void testPinkNoise() {
short[] pinkNoise = SOSSignalProcessing.makePinkNoise(441000, (short)2500, 0);
FFTSignalProcessing fftSignalProcessing = new FFTSignalProcessing(44100,
ThirdOctaveBandsFiltering.STANDARD_FREQUENCIES_REDUCED, pinkNoise.length);
fftSignalProcessing.addSample(pinkNoise);
FFTSignalProcessing.ProcessingResult result = fftSignalProcessing.processSample(false,
false,
false);
// Compute
StandardDeviation standardDeviation = new StandardDeviation();
double[] dArray = new double[result.dBaLevels.length];
for(int i = 0; i < result.dBaLevels.length; i++) {
dArray[i] = result.dBaLevels[i];
}
assertEquals(0, standardDeviation.evaluate(dArray), 0.25);
}
示例11: buildRun
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; //导入依赖的package包/类
private Callable<Result> buildRun(final int kSize, final int numRuns,
final List<String> lines) {
return new Callable<Result>() {
public Result call() throws Exception {
long start = System.currentTimeMillis();
final double[] results = new double[numRuns];
for (int i = 0; i < numRuns; i++) {
Recordinality rec = new Recordinality(kSize);
for (String line : lines) rec.observe(line);
results[i] = rec.estimateCardinality();
}
double mean = new Mean().evaluate(results);
double stdDev = new StandardDeviation().evaluate(results);
double stdError = stdDev / 3193;
long runTime = System.currentTimeMillis() - start;
return new Result(kSize, mean, stdError, runTime);
}
};
}
示例12: testInformationNumericFeature
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; //导入依赖的package包/类
@Test
public void testInformationNumericFeature() {
ExampleSet exampleSet = examplesForFeaturesValues(
new float[]{0.0f, 1.0f, 2.0f, 4.0f},
new float[]{1.0f, 1.5f, 2.0f, 5.0f}
);
List<Decision> decisions = Decision.decisionsFromExamples(exampleSet, 0, 100);
assertEquals(3, decisions.size());
assertEquals(3.0f, ((NumericDecision) decisions.get(0)).getThreshold());
assertEquals(1.5f, ((NumericDecision) decisions.get(1)).getThreshold());
assertEquals(0.5f, ((NumericDecision) decisions.get(2)).getThreshold());
Pair<Decision,Double> best = NumericalInformation.bestGain(decisions, exampleSet);
assertEquals(1.5f, ((NumericDecision) best.getFirst()).getThreshold());
StandardDeviation all = new StandardDeviation();
all.incrementAll(new double[] {1.0,1.5,2.0,5.0});
StandardDeviation positive = new StandardDeviation();
positive.incrementAll(new double[] {1.0,1.5});
StandardDeviation negative = new StandardDeviation();
negative.incrementAll(new double[] {2.0,5.0});
assertEquals(differentialEntropy(all)
- (2.0/4.0)*differentialEntropy(positive)
- (2.0/4.0)*differentialEntropy(negative),
best.getValue().doubleValue());
}
示例13: standardDeviation
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; //导入依赖的package包/类
private static double standardDeviation(List<Double> values) {
double[] array = new double[values.size()];
for (int i = 0; i < array.length; i++) {
array[i] = values.get(i);
}
return new StandardDeviation().evaluate(array);
}
示例14: Endpoint
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; //导入依赖的package包/类
protected Endpoint(String path, double relativeProb) {
Preconditions.checkArgument(relativeProb > 0.0);
this.path = path;
this.relativeProb = relativeProb;
meanTimeNanos = new Mean();
stdevTimeNanos = new StandardDeviation();
}
示例15: stdDev
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; //导入依赖的package包/类
private static double stdDev(List<Long> data) {
double[] asDouble = new double[data.size()];
int i = 0;
for (Long l : data) {
asDouble[i++] = (double) l;
}
return new StandardDeviation().evaluate(asDouble);
}