List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics addValue
public void addValue(double v)
From source file:com.clust4j.algo.preprocess.RobustScaler.java
@Override public RobustScaler fit(RealMatrix X) { synchronized (fitLock) { this.centerer = new MedianCenterer().fit(X); // Get percentile final int n = X.getColumnDimension(); double[][] transpose = X.transpose().getData(); // top row will be 25th, bottom 75 double[][] quantiles_25_75 = new double[2][n]; // Quantile engine DescriptiveStatistics stats; for (int j = 0; j < n; j++) { stats = new DescriptiveStatistics(); for (int i = 0; i < transpose[j].length; i++) { stats.addValue(transpose[j][i]); }/* w w w .j a v a 2 s .com*/ quantiles_25_75[0][j] = stats.getPercentile(25); quantiles_25_75[0][j] = stats.getPercentile(75); } // set the scale this.scale = VecUtils.subtract(quantiles_25_75[1], quantiles_25_75[0]); // If we have a constant value, we might get zeroes in the scale: for (int i = 0; i < scale.length; i++) { if (scale[i] == 0) { scale[i] = 1.0; } } return this; } }
From source file:com.kircherelectronics.accelerationexplorer.data.SampleAxisState.java
/** * Stop recording sample measurements./* w ww .jav a 2 s . c om*/ */ @Override public void stopSample() { sampler.setSampling(false); DescriptiveStatistics stats = new DescriptiveStatistics(); // Add the data from the array for (int i = 0; i < acceleration.length; i++) { stats.addValue(acceleration[i]); } sampleRMS = stats.getStandardDeviation(); sampleMean = StatUtils.mean(acceleration); sampleMax = StatUtils.max(acceleration); sampleMin = StatUtils.min(acceleration); }
From source file:algorithms.quality.AttentionQuality.java
@Override public double getQuality(Colormap2D colormap) { // max L + max c (which is the same as a or b) double normFac = Math.sqrt(100 * 100 + 150 * 150); DescriptiveStatistics stats = new DescriptiveStatistics(); for (Point2D pt : sampling.getPoints()) { Color color = colormap.getColor(pt.getX(), pt.getY()); double[] lch = new CIELABLch().fromColor(color); double attention = Math.sqrt(lch[0] * lch[0] + lch[1] * lch[1]) / normFac; stats.addValue(attention); }/* w ww . ja v a 2 s . c o m*/ return stats.getVariance(); }
From source file:es.csic.iiia.planes.util.InverseWishartDistributionTest.java
private double testScale(double scale, double df) { RealMatrix scaleMatrix = new Array2DRowRealMatrix(new double[][] { { 1 / scale, 0 }, { 0, 1 / scale }, }); DescriptiveStatistics stats = new DescriptiveStatistics(WISHART_SAMPLES * NORMAL_SAMPLES); for (int i = 0; i < WISHART_SAMPLES; i++) { InverseWishartDistribution instance = new InverseWishartDistribution(scaleMatrix, df); stats.addValue(computeRadius(instance)); }//w w w.ja v a2 s . co m return stats.getPercentile(50); }
From source file:es.csic.iiia.planes.util.InverseWishartDistributionTest.java
private double testGaussian(double scale) { double[] means = new double[] { 0, 0 }; double[][] covariances = new double[][] { { scale, 0 }, { 0, scale } }; MultivariateNormalDistribution uniform = new MultivariateNormalDistribution(means, covariances); DescriptiveStatistics stats = new DescriptiveStatistics(NORMAL_SAMPLES); for (int i = 0; i < NORMAL_SAMPLES; i++) { double[] xy = uniform.sample(); final double x = xy[0]; final double y = xy[1]; stats.addValue(Math.sqrt(x * x + y * y)); }//w w w. j av a 2s . c o m return stats.getPercentile(90); }
From source file:es.csic.iiia.planes.util.InverseWishartDistributionTest.java
private double computeRadius(InverseWishartDistribution instance) { double[] means = new double[] { 0, 0 }; MultivariateNormalDistribution uniform = null; while (uniform == null) { try {/* w w w . ja v a2 s .co m*/ double[][] covariances = instance.sample().getData(); uniform = new MultivariateNormalDistribution(means, covariances); } catch (MathUnsupportedOperationException ex) { } } DescriptiveStatistics stats = new DescriptiveStatistics(NORMAL_SAMPLES); for (int i = 0; i < NORMAL_SAMPLES; i++) { double[] xy = uniform.sample(); final double x = xy[0]; final double y = xy[1]; stats.addValue(Math.sqrt(x * x + y * y)); } return stats.getPercentile(90); }
From source file:gr.iti.mklab.reveal.forensics.util.Util.java
public static float[][] medianFilterSingleChannelImage(double[][] imIn, int medianFilterSize) { // Median filter a 2D double array // medianFilterSize should be odd int offset = (medianFilterSize - 1) / 2; int imWidth = imIn.length; int imHeight = imIn[0].length; DescriptiveStatistics blockValues; float[][] filteredImage = new float[imWidth - 2 * offset][imHeight - 2 * offset]; for (int ii = offset; ii <= imWidth - medianFilterSize + offset; ii = ii + 1) { for (int jj = offset; jj <= imHeight - medianFilterSize + offset; jj = jj + 1) { blockValues = new DescriptiveStatistics(); for (int B_ii = ii - offset; B_ii < ii + offset + 1; B_ii++) { for (int B_jj = jj - offset; B_jj < jj + offset + 1; B_jj++) { blockValues.addValue(Math.abs(imIn[B_ii][B_jj])); }//from w w w . ja v a 2 s.c o m } filteredImage[ii - offset][jj - offset] = (float) blockValues.getPercentile(50); } } return filteredImage; }
From source file:io.yields.math.framework.data.DataProvidersTest.java
@Explore(name = "check distributional properties of random numbers", dataProvider = DataProviders.FixedMersenneTwisterDataProvider.class, nrOfRuns = 10000) @Exploration(name = "2D uniform samples", context = FunctionExplorerWithoutProperties.class, group = "data providers") public void testRandomDistribution(Explorer<Pair> explorer) { KolmogorovSmirnovTest ksTest = new KolmogorovSmirnovTest(); DescriptiveStatistics xStats = new DescriptiveStatistics(); DescriptiveStatistics yStats = new DescriptiveStatistics(); explorer.all().forEach(result -> { Pair pair = result.getFunctionOutcome().orElse(new Pair()); xStats.addValue(pair.getX1()); yStats.addValue(pair.getX2());/*from w w w .ja va 2 s . c om*/ }); DescriptiveStatistics cross = new DescriptiveStatistics(); for (int i = 0; i < xStats.getN(); i++) { cross.addValue((xStats.getValues()[i] - .5) * (yStats.getValues()[i] - .5)); } /** * x and y should be uniformly distributed */ assertThat(ksTest.kolmogorovSmirnovStatistic(new UniformRealDistribution(0, 1), xStats.getValues())) .isEqualTo(0, Delta.delta(.015)); assertThat(ksTest.kolmogorovSmirnovStatistic(new UniformRealDistribution(0, 1), yStats.getValues())) .isEqualTo(0, Delta.delta(.015)); /** * and have zero correlation */ assertThat(cross.getMean()).isEqualTo(0, Delta.delta(.05)); }
From source file:knop.psfj.BeadAverager.java
/** * Filter.//w w w .j a v a 2s. c om * * @param frameList the frame list * @return the array list */ public ArrayList<BeadFrame> filter(ArrayList<BeadFrame> frameList) { ArrayList<BeadFrame> filtered = new ArrayList<BeadFrame>(); DescriptiveStatistics centerX = new DescriptiveStatistics(); DescriptiveStatistics centerY = new DescriptiveStatistics(); DescriptiveStatistics centerZ = new DescriptiveStatistics(); for (BeadFrame frame : frameList) { centerX.addValue(frame.getCentroidX()); centerY.addValue(frame.getCentroidY()); centerZ.addValue(frame.getCentroidZ()); } double thresholdUp = centerZ.getPercentile(50) + centerZ.getStandardDeviation(); double thresholdDown = thresholdUp - (centerZ.getStandardDeviation() * 2); for (BeadFrame frame : frameList) { if (frame.getCentroidZ() < thresholdUp && frame.getCentroidZ() > thresholdDown) { filtered.add(frame); } else { incrementFilteredOutBeadCount(); } } return filtered; }
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; }//from www .j a va2 s . c om 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; } }