List of usage examples for org.apache.commons.math3.stat.descriptive.moment StandardDeviation evaluate
@Override public double evaluate(final double[] values) throws MathIllegalArgumentException
Double.NaN
if the array is empty. From source file:com.musicg.experiment.test.Test1.java
/** * @param args/*w w w .j av a 2 s. c om*/ */ public static void main(String[] args) { String filename = "audio_work/lala.wav"; // create a wave object Wave wave = null; try { wave = new Wave(filename); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // TimeDomainRepresentations int fftSampleSize = 1024; int overlapFactor = 1; Spectrogram spectrogram = new Spectrogram(wave, fftSampleSize, overlapFactor); int fps = spectrogram.getFramesPerSecond(); double unitFrequency = spectrogram.getUnitFrequency(); // set boundary int highPass = 100; int lowerBoundary = (int) (highPass / unitFrequency); int lowPass = 4000; int upperBoundary = (int) (lowPass / unitFrequency); // end set boundary double[][] spectrogramData = spectrogram.getNormalizedSpectrogramData(); double[][] absoluteSpectrogramData = spectrogram.getAbsoluteSpectrogramData(); double[][] boundedSpectrogramData = new double[spectrogramData.length][]; // SpectralCentroid sc=new SpectralCentroid(); StandardDeviation sd = new StandardDeviation(); ArrayRankDouble arrayRankDouble = new ArrayRankDouble(); // zrc short[] amps = wave.getSampleAmplitudes(); int numFrame = amps.length / 1024; double[] zcrs = new double[numFrame]; for (int i = 0; i < numFrame; i++) { short[] temp = new short[1024]; System.arraycopy(amps, i * 1024, temp, 0, temp.length); int numZC = 0; int size = temp.length; for (int j = 0; j < size - 1; j++) { if ((temp[j] >= 0 && temp[j + 1] < 0) || (temp[j] < 0 && temp[j + 1] >= 0)) { numZC++; } } zcrs[i] = numZC; } // end zcr for (int i = 0; i < spectrogramData.length; i++) { double[] temp = new double[upperBoundary - lowerBoundary + 1]; System.arraycopy(spectrogramData[i], lowerBoundary, temp, 0, temp.length); int maxIndex = arrayRankDouble.getMaxValueIndex(temp); // sc.setValues(temp); double sdValue = sd.evaluate(temp); System.out.println(i + " " + (double) i / fps + "s\t" + maxIndex + "\t" + sdValue + "\t" + zcrs[i]); boundedSpectrogramData[i] = temp; } // Graphic render GraphicRender render = new GraphicRender(); render.setHorizontalMarker(61); render.setVerticalMarker(200); render.renderSpectrogramData(boundedSpectrogramData, filename + ".jpg"); PitchHandler ph = new PitchHandler(); for (int frame = 0; frame < absoluteSpectrogramData.length; frame++) { System.out.print("frame " + frame + ": "); double[] temp = new double[upperBoundary - lowerBoundary + 1]; double sdValue = sd.evaluate(temp); double passSd = 0.1; if (sdValue < passSd) { System.arraycopy(spectrogramData[frame], lowerBoundary, temp, 0, temp.length); double maxFrequency = arrayRankDouble.getMaxValueIndex(temp) * unitFrequency; double passFrequency = 400; int numRobust = 2; double[] robustFrequencies = new double[numRobust]; double nthValue = arrayRankDouble.getNthOrderedValue(temp, numRobust, false); int count = 0; for (int b = lowerBoundary; b <= upperBoundary; b++) { if (spectrogramData[frame][b] >= nthValue) { robustFrequencies[count++] = b * unitFrequency; if (count >= numRobust) { break; } } } double passIntensity = 1000; double intensity = 0; for (int i = 0; i < absoluteSpectrogramData[frame].length; i++) { intensity += absoluteSpectrogramData[frame][i]; } intensity /= absoluteSpectrogramData[frame].length; System.out.print(" intensity: " + intensity + " pitch: " + maxFrequency); if (intensity > passIntensity && maxFrequency > passFrequency) { double p = ph.getHarmonicProbability(robustFrequencies); System.out.print(" P: " + p); } } System.out.print(" zcr:" + zcrs[frame]); System.out.println(); } }
From source file:com.facebook.presto.operator.aggregation.TestDoubleStdDevAggregation.java
@Override public Number getExpectedValue(int start, int length) { if (length < 2) { return null; }//from w w w . ja va2 s.co m double[] values = new double[length]; for (int i = 0; i < length; i++) { values[i] = start + i; } StandardDeviation stdDev = new StandardDeviation(); return stdDev.evaluate(values); }
From source file:com.facebook.presto.operator.aggregation.TestDoubleStdDevPopAggregation.java
@Override public Number getExpectedValue(int start, int length) { if (length == 0) { return null; }/* www.j a v a 2 s .c o m*/ double[] values = new double[length]; for (int i = 0; i < length; i++) { values[i] = start + i; } StandardDeviation stdDev = new StandardDeviation(false); return stdDev.evaluate(values); }
From source file:com.itemanalysis.psychometrics.kernel.LikelihoodCrossValidation.java
private void computeBounds() { StandardDeviation sd = new StandardDeviation(); this.max = sd.evaluate(x); }
From source file:net.sf.sessionAnalysis.SessionVisitorSessionLengthNanosStatistics.java
public double computeSessionLengthStdDev() { double[] lengths = computeLengthVector(); StandardDeviation stdDevObj = new StandardDeviation(); return stdDevObj.evaluate(lengths); }
From source file:com.graphhopper.jsprit.core.algorithm.acceptor.SchrimpfInitialThresholdGenerator.java
@Override public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection<VehicleRoutingProblemSolution> solutions) { logger.info("prepare schrimpfAcceptanceFunction, i.e. determine initial threshold"); double now = System.currentTimeMillis(); /*/*from w w w . j a va2 s . c om*/ * randomWalk to determine standardDev */ final double[] results = new double[nOfRandomWalks]; Jsprit.Builder builder = new GreedySchrimpfFactory().createGreedyAlgorithmBuilder(problem); builder.setCustomAcceptor(new AcceptNewRemoveFirst(1)); VehicleRoutingAlgorithm vra = builder.buildAlgorithm(); vra.setMaxIterations(nOfRandomWalks); vra.getAlgorithmListeners().addListener(new IterationEndsListener() { @Override public void informIterationEnds(int iteration, VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) { double result = Solutions.bestOf(solutions).getCost(); // logger.info("result={}", result); results[iteration - 1] = result; } }); vra.searchSolutions(); StandardDeviation dev = new StandardDeviation(); double standardDeviation = dev.evaluate(results); double initialThreshold = standardDeviation / 2; schrimpfAcceptance.setInitialThreshold(initialThreshold); logger.info("took {} seconds", ((System.currentTimeMillis() - now) / 1000.0)); logger.debug("initial threshold: {}", initialThreshold); logger.info("---------------------------------------------------------------------"); }
From source file:de.biomedical_imaging.traJ.features.SplineCurveSpatialFeature.java
@Override /**//from ww w . j a v a2s. c o m * @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; }
From source file:de.biomedical_imaging.traj.math.MomentsCalculator.java
public double calculateNthMoment(int n) { Array2DRowRealMatrix gyr = RadiusGyrationTensor2D.getRadiusOfGyrationTensor(t); EigenDecomposition eigdec = new EigenDecomposition(gyr); Vector2d eigv = new Vector2d(eigdec.getEigenvector(0).getEntry(0), eigdec.getEigenvector(0).getEntry(1)); double[] projected = new double[t.size()]; for (int i = 0; i < t.size(); i++) { Vector2d pos = new Vector2d(t.get(i).x, t.get(i).y); double v = eigv.dot(pos); projected[i] = v;//from w w w . ja va 2s . c om } Mean m = new Mean(); StandardDeviation s = new StandardDeviation(); double mean = m.evaluate(projected); double sd = s.evaluate(projected); double sumPowN = 0; for (int i = 0; i < projected.length; i++) { sumPowN += Math.pow((projected[i] - mean) / sd, n); } double nThMoment = sumPowN / projected.length; return nThMoment; }
From source file:com.itemanalysis.psychometrics.kernel.LeastSquaresCrossValidation.java
private void computeBounds() throws Exception { StandardDeviation stdev = new StandardDeviation(); this.sd = stdev.evaluate(x); Min min = new Min(); double from = min.evaluate(x); Max max = new Max(); double to = max.evaluate(x); }
From source file:eagle.security.userprofile.model.kde.UserProfileKDEModeler.java
private void computeStats(RealMatrix m) { if (m.getColumnDimension() != this.cmdTypes.length) { LOG.error("Please fix the commands list in config file"); }//from ww w. j ava 2s. c o m statistics = new UserCommandStatistics[m.getColumnDimension()]; for (int i = 0; i < m.getColumnDimension(); i++) { UserCommandStatistics stats = new UserCommandStatistics(); stats.setCommandName(this.cmdTypes[i]); RealVector colData = m.getColumnVector(i); StandardDeviation deviation = new StandardDeviation(); double stddev = deviation.evaluate(colData.toArray()); if (LOG.isDebugEnabled()) LOG.debug("Stddev is NAN ? " + (Double.isNaN(stddev) ? "yes" : "no")); if (stddev <= lowVarianceVal) stats.setLowVariant(true); else stats.setLowVariant(false); stats.setStddev(stddev); Mean mean = new Mean(); double mu = mean.evaluate(colData.toArray()); if (LOG.isDebugEnabled()) LOG.debug("mu is NAN ? " + (Double.isNaN(mu) ? "yes" : "no")); stats.setMean(mu); statistics[i] = stats; } }