List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getMin
public double getMin()
From source file:com.loadtesting.core.data.TimeSerieData.java
public TimeSerieData(String name, List<TimeSample> samples, CapturerConfig config) { this.name = name; this.unit = config.getUnit(); this.volume = samples.size(); if (volume > 0) { TimeSample first = samples.get(0); this.unit = first.getTimeUnit(); this.opening = first.getTime(unit); TimeSample last = samples.get(volume - 1); this.closing = last.getTime(unit); this.samples = config.getFilter().filter(samples); DescriptiveStatistics stats = new DescriptiveStatistics(volume); for (TimeSample timeSample : samples) { stats.addValue(timeSample.getTime(unit)); }/* w w w. j a va 2 s .c o m*/ this.high = stats.getMax(); this.low = stats.getMin(); this.median = (high + low) / 2; this.typical = (high + low + closing) / 3; this.weightedClose = (high + low + closing + closing) / 4; this.sma = stats.getMean(); this.variance = stats.getVariance(); this.sd = stats.getStandardDeviation(); this.sum = stats.getSum(); this.sumsq = stats.getSumsq(); this.skewness = stats.getSkewness(); this.kurtosis = stats.getKurtosis(); this.geometricMean = stats.getGeometricMean(); this.populationVariance = stats.getPopulationVariance(); } else { this.samples = samples; } }
From source file:com.caseystella.analytics.outlier.batch.rpca.RPCAOutlierAlgorithm.java
public double outlierScore(List<DataPoint> dataPoints, DataPoint value) { double[] inputData = new double[dataPoints.size() + 1]; int numNonZero = 0; if (scaling != ScalingFunctions.NONE) { int i = 0; final DescriptiveStatistics stats = new DescriptiveStatistics(); for (DataPoint dp : dataPoints) { inputData[i++] = dp.getValue(); stats.addValue(dp.getValue()); numNonZero += dp.getValue() > EPSILON ? 1 : 0; }/* www .j a v a2s . co m*/ inputData[i] = value.getValue(); GlobalStatistics globalStats = new GlobalStatistics() { { setMax(stats.getMax()); setMin(stats.getMin()); setMax(stats.getMean()); setStddev(stats.getStandardDeviation()); } }; for (i = 0; i < inputData.length; ++i) { inputData[i] = scaling.scale(inputData[i], globalStats); } } else { int i = 0; for (DataPoint dp : dataPoints) { inputData[i++] = dp.getValue(); numNonZero += dp.getValue() > EPSILON ? 1 : 0; } inputData[i] = value.getValue(); } int nCols = 1; int nRows = inputData.length; if (numNonZero > minRecords) { AugmentedDickeyFuller dickeyFullerTest = new AugmentedDickeyFuller(inputData); double[] inputArrayTransformed = inputData; if (!this.isForceDiff && dickeyFullerTest.isNeedsDiff()) { // Auto Diff inputArrayTransformed = dickeyFullerTest.getZeroPaddedDiff(); } else if (this.isForceDiff) { // Force Diff inputArrayTransformed = dickeyFullerTest.getZeroPaddedDiff(); } if (this.spenalty == null) { this.lpenalty = this.LPENALTY_DEFAULT; this.spenalty = this.SPENALTY_DEFAULT / Math.sqrt(Math.max(nCols, nRows)); } // Calc Mean double mean = 0; for (int n = 0; n < inputArrayTransformed.length; n++) { mean += inputArrayTransformed[n]; } mean /= inputArrayTransformed.length; // Calc STDEV double stdev = 0; for (int n = 0; n < inputArrayTransformed.length; n++) { stdev += Math.pow(inputArrayTransformed[n] - mean, 2); } stdev = Math.sqrt(stdev / (inputArrayTransformed.length - 1)); // Transformation: Zero Mean, Unit Variance for (int n = 0; n < inputArrayTransformed.length; n++) { inputArrayTransformed[n] = (inputArrayTransformed[n] - mean) / stdev; } // Read Input Data into Array // Read Input Data into Array double[][] input2DArray = new double[nRows][nCols]; input2DArray = VectorToMatrix(inputArrayTransformed, nRows, nCols); RPCA rSVD = new RPCA(input2DArray, this.lpenalty, this.spenalty); double[][] outputE = rSVD.getE().getData(); double[][] outputS = rSVD.getS().getData(); double[][] outputL = rSVD.getL().getData(); return outputS[nRows - 1][0]; } else { return Double.NaN; } }
From source file:de.iisys.schub.processMining.similarity.AlgoController.java
private String showDocMetaData(List<Double> cosineSimValues) { DescriptiveStatistics stat = new DescriptiveStatistics(); for (int i = 0; i < cosineSimValues.size(); i++) { stat.addValue(cosineSimValues.get(i)); }//ww w . j a va 2 s . co m double min = Math.round(stat.getMin() * 1000) / 1000.0; double max = Math.round(stat.getMax() * 1000) / 1000.0; double arithMean = Math.round(stat.getMean() * 10000) / 10000.0; double percentile = Math.round(stat.getPercentile(PERCENTILE) * 1000) / 1000.0; DecimalFormat df = new DecimalFormat("#00.00"); String meta = "Min: " + df.format(min * 100) + " %" + ", Max: " + df.format(max * 100) + " %" + ", Arith. Mean: " + df.format(arithMean * 100) + " %" + ", Percentile (" + PERCENTILE + " %): " + df.format(percentile * 100) + " %"; return meta; }
From source file:com.iorga.webappwatcher.analyzer.ws.statistics.DailyStatisticsWS.java
@GET @Path("/compute") public StreamingOutput compute() throws ClassNotFoundException, IOException { final List<DayStatistic> computeDayStatistics = durationPerPrincipalStats.computeDayStatistics(); return new StreamingOutput() { @Override/*from ww w . jav a2 s .c om*/ public void write(final OutputStream output) throws IOException, WebApplicationException { final JsonGenerator generator = OBJECT_MAPPER.getJsonFactory().createJsonGenerator(output, JsonEncoding.UTF8); generator.writeStartArray(); for (final DayStatistic dayStatistic : computeDayStatistics) { generator.writeStartObject(); generator.writeFieldName("startDate"); OBJECT_MAPPER.writeValue(generator, dayStatistic.getStartDate()); generator.writeFieldName("endDate"); OBJECT_MAPPER.writeValue(generator, dayStatistic.getEndDate()); generator.writeArrayFieldStart("statistics"); // write each statistic for (final String statisticType : new String[] { "distinctUsers", "numberOfRequests", "durationsFor1clickSum", "durationsFor1clickMean", "durationsFor1clickMedian", "durationsFor1click90c", "durationsFor1clickMin", "durationsFor1clickMax" }) { // generator.writeFieldName(statisticType); generator.writeStartObject(); generator.writeStringField("type", statisticType); // get the statistics from the dayStatistic DescriptiveStatistics descriptiveStatistics; try { descriptiveStatistics = (DescriptiveStatistics) dayStatistic.getClass() .getMethod("get" + StringUtils.capitalize(statisticType)).invoke(dayStatistic); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new IOException( "Problem while invoking getter for statisticType " + statisticType, e); } generator.writeNumberField("min", descriptiveStatistics.getMin()); generator.writeNumberField("max", descriptiveStatistics.getMax()); generator.writeNumberField("mean", descriptiveStatistics.getMean()); generator.writeNumberField("median", descriptiveStatistics.getPercentile(50)); generator.writeEndObject(); } generator.writeEndArray(); generator.writeFieldName("distinctPrincipalsSize"); OBJECT_MAPPER.writeValue(generator, dayStatistic.getPrincipals().size()); generator.writeEndObject(); } generator.writeEndArray(); generator.flush(); // required else all the stream is not sent } }; }
From source file:mase.app.allocation.AllocationProblem.java
@Override public EvaluationResult[] evaluateSolution(GroupController gc, long seed) { AgentController[] acs = gc.getAgentControllers(numAgents); RealMatrix distanceMatrix = new Array2DRowRealMatrix(numAgents, types.length); for (int i = 0; i < numAgents; i++) { AllocationAgent aa = (AllocationAgent) acs[i]; for (int j = 0; j < types.length; j++) { distanceMatrix.setEntry(i, j, DIST.compute(aa.getLocation(), types[j])); }//from ww w. java 2 s .c o m } DescriptiveStatistics pd = pairDistances(distanceMatrix); // fitness FitnessResult fr = new FitnessResult(1 - pd.getMean() / FastMath.sqrt(dimensions)); // individual characterisation -- distance to each type List<EvaluationResult> vbrs = new ArrayList<>(); for (double[] dists : distanceMatrix.getData()) { vbrs.add(new VectorBehaviourResult(dists)); } CompoundEvaluationResult ser = new CompoundEvaluationResult(vbrs); // aux characterisation -- min, mean, max, sd pair distances VectorBehaviourResult aux = new VectorBehaviourResult(pd.getMin(), pd.getMean(), pd.getMax(), pd.getStandardDeviation()); return new EvaluationResult[] { fr, aux, ser }; }
From source file:knop.psfj.BeadAverager.java
/** * Average bead./*from w w w. ja v a2s .c o m*/ * * @param frameList the frame list * @return the image plus */ public ImagePlus averageBead(ArrayList<BeadFrame> frameList) { ImagePlus result; DescriptiveStatistics centerX = new DescriptiveStatistics(); DescriptiveStatistics centerY = new DescriptiveStatistics(); DescriptiveStatistics centerZ = new DescriptiveStatistics(); int originalStackSize = frameList.get(0).getSliceNumber(); setTotalBeads(frameList.size()); //frameList = filter(frameList); ArrayList<ImageStack> centeredStacks = new ArrayList<ImageStack>(); for (BeadFrame frame : frameList) { System.out.println(frame.getCentroidXAsInt()); centerX.addValue(frame.getCentroidXAsInt()); centerY.addValue(frame.getCentroidYAsInt()); centerZ.addValue(frame.getCentroidZAsInt()); } int chosenCenter = MathUtils.round(centerZ.getPercentile(50)); int maxUp = chosenCenter - MathUtils.round(chosenCenter - centerZ.getMin()); int maxDown = originalStackSize - MathUtils.round(centerZ.getMax()); System.out.println(maxUp); System.out.println(maxDown); for (BeadFrame frame : frameList) { ImageStack subStack = new ImageStack(frame.getSubstack().getWidth(), frame.getSubstack().getHeight()); int center = frame.getCentroidZAsInt(); int begin = center - maxUp; int end = center + maxDown; System.out.println(String.format(" Groing from %d to %d with a center at %d", begin, end, center)); for (int i = begin; i != end; i++) { subStack.addSlice(frame.getSubstack().getImageStack().getProcessor(i + 1)); } centeredStacks.add(subStack); //new ImagePlus("",subStack).show(); } System.out.println(centerX); System.out.println(centerY); System.out.println(centerZ); return new ImagePlus("", averageStacks(centeredStacks)); }
From source file:com.github.jessemull.microflex.stat.statinteger.MinIntegerTest.java
/** * Tests the plate statistics method./*from w ww.ja v a 2 s . co m*/ */ @Test public void testPlate() { for (PlateInteger plate : array) { Map<WellInteger, Double> resultMap = new TreeMap<WellInteger, Double>(); Map<WellInteger, Double> returnedMap = min.plate(plate); for (WellInteger well : plate) { double[] input = new double[well.size()]; int index = 0; for (double bd : well) { input[index++] = bd; ; } DescriptiveStatistics stat = new DescriptiveStatistics(input); double result = stat.getMin(); resultMap.put(well, result); } for (WellInteger well : plate) { double result = Precision.round(resultMap.get(well), precision); double returned = Precision.round(returnedMap.get(well), precision); assertTrue(result == returned); } } }
From source file:com.github.jessemull.microflexdouble.stat.MinTest.java
/** * Tests the plate statistics method./*from w w w . jav a2 s.co m*/ */ @Test public void testPlate() { for (Plate plate : array) { Map<Well, Double> resultMap = new TreeMap<Well, Double>(); Map<Well, Double> returnedMap = min.plate(plate); for (Well well : plate) { double[] input = new double[well.size()]; int index = 0; for (double bd : well) { input[index++] = bd; ; } DescriptiveStatistics stat = new DescriptiveStatistics(input); double result = stat.getMin(); resultMap.put(well, result); } for (Well well : plate) { double result = Precision.round(resultMap.get(well), precision); double returned = Precision.round(returnedMap.get(well), precision); assertTrue(result == returned); } } }
From source file:com.github.jessemull.microflex.stat.statdouble.MinDoubleTest.java
/** * Tests the plate statistics method.//from w w w .ja v a2 s . co m */ @Test public void testPlate() { for (PlateDouble plate : array) { Map<WellDouble, Double> resultMap = new TreeMap<WellDouble, Double>(); Map<WellDouble, Double> returnedMap = min.plate(plate); for (WellDouble well : plate) { double[] input = new double[well.size()]; int index = 0; for (double bd : well) { input[index++] = bd; ; } DescriptiveStatistics stat = new DescriptiveStatistics(input); double result = stat.getMin(); resultMap.put(well, result); } for (WellDouble well : plate) { double result = Precision.round(resultMap.get(well), precision); double returned = Precision.round(returnedMap.get(well), precision); assertTrue(result == returned); } } }
From source file:com.github.jessemull.microflex.stat.statinteger.MinIntegerTest.java
/** * Tests set calculation.//from w ww . j a v a 2 s .co m */ @Test public void testSet() { for (PlateInteger plate : array) { Map<WellInteger, Double> resultMap = new TreeMap<WellInteger, Double>(); Map<WellInteger, Double> returnedMap = min.set(plate.dataSet()); for (WellInteger well : plate) { double[] input = new double[well.size()]; int index = 0; for (double bd : well) { input[index++] = bd; ; } DescriptiveStatistics stat = new DescriptiveStatistics(input); double result = stat.getMin(); resultMap.put(well, result); } for (WellInteger well : plate) { double result = Precision.round(resultMap.get(well), precision); double returned = Precision.round(returnedMap.get(well), precision); assertTrue(result == returned); } } }