org.apache.commons.math.stat.descriptive.moment.StandardDeviation Java Examples
The following examples show how to use
org.apache.commons.math.stat.descriptive.moment.StandardDeviation.
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: BucketSampler.java From sql-layer with GNU Affero General Public License v3.0 | 5 votes |
BucketSampler(int maxSize, long estimatedInputs, boolean calculateStandardDeviation) { if (maxSize < 1) throw new IllegalArgumentException("max must be at least 1"); if (estimatedInputs < 0) throw new IllegalArgumentException("estimatedInputs must be non-negative: " + estimatedInputs); this.maxSize = maxSize; this.estimatedInputs = estimatedInputs; this.buckets = new ArrayList<>(maxSize + 1); this.stdDev = calculateStandardDeviation ? new StandardDeviation() : null; computeMedianPointBoundaries(maxSize); }
Example #2
Source File: FindOutliers.java From streamsx.topology with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { final double threshold = args.length == 0 ? 2.0 : Double .parseDouble(args[0]); Topology t = new Topology("StandardDeviationFilter"); final Random rand = new Random(); // Produce a stream of random double values with a normal // distribution, mean 0.0 and standard deviation 1. TStream<Double> values = t.limitedSource(new Supplier<Double>() { private static final long serialVersionUID = 1L; @Override public Double get() { return rand.nextGaussian(); } }, 100000); /* * Filters the values based on calculating the mean and standard * deviation from the incoming data. In this case only outliers are * present in the output stream outliers. A outlier is defined as one * more than (threshold*standard deviation) from the mean. * * This demonstrates an anonymous functional logic class that is * stateful. The two fields mean and sd maintain their values across * multiple invocations of the test method, that is for multiple tuples. * * Note both Mean & StandardDeviation classes are serializable. */ TStream<Double> outliers = values.filter(new Predicate<Double>() { private static final long serialVersionUID = 1L; private final Mean mean = new Mean(); private final StandardDeviation sd = new StandardDeviation(); @Override public boolean test(Double tuple) { mean.increment(tuple); sd.increment(tuple); double multpleSd = threshold * sd.getResult(); double absMean = Math.abs(mean.getResult()); double absTuple = Math.abs(tuple); return absTuple > absMean + multpleSd; } }); outliers.print(); StreamsContextFactory.getEmbedded().submit(t).get(); }