List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics DescriptiveStatistics
public DescriptiveStatistics(DescriptiveStatistics original) throws NullArgumentException
From source file:DifferentalEvolution.java
public static void main(String[] args) { solutions = new ArrayList<Double>(ControlVariables.RUNS_PER_FUNCTION); /* An array of the benchmark functions to evalute */ benchmarkFunctions = new ArrayList<FitnessFunction>(); benchmarkFunctions.add(new DeJong()); benchmarkFunctions.add(new HyperEllipsoid()); benchmarkFunctions.add(new Schwefel()); benchmarkFunctions.add(new RosenbrocksValley()); benchmarkFunctions.add(new Rastrigin()); /* Apply the differential evolution algorithm to each benchmark function */ for (FitnessFunction benchmarkFunction : benchmarkFunctions) { /* Set the fitness function for the current benchmark function */ fitnessFunction = benchmarkFunction; /* Execute the differential evolution algorithm a number of times per function */ for (int runs = 0; runs < ControlVariables.RUNS_PER_FUNCTION; ++runs) { int a; int b; int c; boolean validVector = false; Vector noisyVector = null; /* Reset the array of the best values found */ prevAmount = 0;/*from w ww . j a va2 s . c o m*/ lowestFit = new LinkedHashMap<Integer, Double>(); lowestFit.put(prevAmount, Double.MAX_VALUE); initPopulation(fitnessFunction.getBounds()); /* Reset the fitness function NFC each time */ fitnessFunction.resetNFC(); while (fitnessFunction.getNFC() < ControlVariables.MAX_FUNCTION_CALLS) { for (int i = 0; i < ControlVariables.POPULATION_SIZE; i++) { // Select 3 Mutually Exclusive Parents i != a != b != c while (!validVector) { do { a = getRandomIndex(); } while (a == i); do { b = getRandomIndex(); } while (b == i || b == a); do { c = getRandomIndex(); } while (c == i || c == a || c == b); // Catch invalid vectors try { validVector = true; noisyVector = VectorOperations.mutation(population.get(c), population.get(b), population.get(a)); } catch (IllegalArgumentException e) { validVector = false; } } validVector = false; Vector trialVector = VectorOperations.crossover(population.get(i), noisyVector, random); trialVector.setFitness(fitnessFunction.evaluate(trialVector)); population.set(i, VectorOperations.selection(population.get(i), trialVector)); /* Get the best fitness value found so far */ if (population.get(i).getFitness() < lowestFit.get(prevAmount)) { prevAmount = fitnessFunction.getNFC(); bestValue = population.get(i).getFitness(); lowestFit.put(prevAmount, bestValue); } } } /* save the best value found for the entire DE algorithm run */ solutions.add(bestValue); } /* Display the mean and standard deviation */ System.out.println("\nResults for " + fitnessFunction.getName()); DescriptiveStatistics stats = new DescriptiveStatistics(Doubles.toArray(solutions)); System.out.println("AVERAGE BEST FITNESS: " + stats.getMean()); System.out.println("STANDARD DEVIATION: " + stats.getStandardDeviation()); /* Set the last value (NFC) to the best value found */ lowestFit.put(ControlVariables.MAX_FUNCTION_CALLS, bestValue); /* Plot the best value found vs. NFC */ PerformanceGraph.plot(lowestFit, fitnessFunction.getName()); /* Reset the results for the next benchmark function to be evaluated */ solutions.clear(); lowestFit.clear(); bestValue = Double.MAX_VALUE; } }
From source file:FaceRatios.java
@SuppressWarnings("serial") public static void main(String[] args) { int r = FSDK.ActivateLibrary(FACE_SDK_LICENSE); if (r == FSDK.FSDKE_OK) { FSDK.Initialize();/*from ww w .j a va 2 s. c o m*/ FSDK.SetFaceDetectionParameters(true, true, 384); Map<String, Map<String, ArrayList<Double>>> faceProperties = new HashMap<>(); for (String directory : new File(FACE_DIRECTORY).list()) { if (new File(FACE_DIRECTORY + directory).isDirectory()) { Map<String, ArrayList<Double>> properties = new HashMap<String, ArrayList<Double>>() { { for (String property : propertyNames) put(property, new ArrayList<Double>()); } }; File[] files = new File(FACE_DIRECTORY + directory).listFiles(); System.out.println("Analyzing " + directory + " with " + files.length + " files\n"); for (File file : files) { if (file.isFile()) { HImage imageHandle = new HImage(); FSDK.LoadImageFromFileW(imageHandle, file.getAbsolutePath()); FSDK.TFacePosition.ByReference facePosition = new FSDK.TFacePosition.ByReference(); if (FSDK.DetectFace(imageHandle, facePosition) == FSDK.FSDKE_OK) { FSDK_Features.ByReference facialFeatures = new FSDK_Features.ByReference(); FSDK.DetectFacialFeaturesInRegion(imageHandle, (FSDK.TFacePosition) facePosition, facialFeatures); Point[] featurePoints = new Point[FSDK.FSDK_FACIAL_FEATURE_COUNT]; for (int i = 0; i < FSDK.FSDK_FACIAL_FEATURE_COUNT; i++) { featurePoints[i] = new Point(0, 0); featurePoints[i].x = facialFeatures.features[i].x; featurePoints[i].y = facialFeatures.features[i].y; } double eyeDistance = featureDistance(featurePoints, FeatureID.LEFT_EYE, FeatureID.RIGHT_EYE); double rightEyeSize = featureDistance(featurePoints, FeatureID.RIGHT_EYE_INNER_CORNER, FeatureID.RIGHT_EYE_OUTER_CORNER); double leftEyeSize = featureDistance(featurePoints, FeatureID.LEFT_EYE_INNER_CORNER, FeatureID.LEFT_EYE_OUTER_CORNER); double averageEyeSize = (rightEyeSize + leftEyeSize) / 2; double mouthLength = featureDistance(featurePoints, FeatureID.MOUTH_RIGHT_CORNER, FeatureID.MOUTH_LEFT_CORNER); double mouthHeight = featureDistance(featurePoints, FeatureID.MOUTH_BOTTOM, FeatureID.MOUTH_TOP); double noseHeight = featureDistance(featurePoints, FeatureID.NOSE_BOTTOM, FeatureID.NOSE_BRIDGE); double chinHeight = featureDistance(featurePoints, FeatureID.CHIN_BOTTOM, FeatureID.MOUTH_BOTTOM); double chinToBridgeHeight = featureDistance(featurePoints, FeatureID.CHIN_BOTTOM, FeatureID.NOSE_BRIDGE); double faceContourLeft = (featurePoints[FeatureID.CHIN_BOTTOM.getIndex()].getY() - featurePoints[FeatureID.FACE_CONTOUR2.getIndex()].getY()) / (featurePoints[FeatureID.CHIN_BOTTOM.getIndex()].getX() - featurePoints[FeatureID.FACE_CONTOUR2.getIndex()].getX()); double faceContourRight = (featurePoints[FeatureID.CHIN_BOTTOM.getIndex()].getY() - featurePoints[FeatureID.FACE_CONTOUR12.getIndex()].getY()) / (featurePoints[FeatureID.CHIN_BOTTOM.getIndex()].getX() - featurePoints[FeatureID.FACE_CONTOUR12.getIndex()].getX()); double bridgeLeftEyeDistance = featureDistance(featurePoints, FeatureID.LEFT_EYE_INNER_CORNER, FeatureID.NOSE_BRIDGE); double bridgeRightEyeDistance = featureDistance(featurePoints, FeatureID.RIGHT_EYE_INNER_CORNER, FeatureID.NOSE_BRIDGE); properties.get("eyeSize/eyeDistance").add(averageEyeSize / eyeDistance); properties.get("eyeSizeDisparity") .add(Math.abs(leftEyeSize - rightEyeSize) / averageEyeSize); properties.get("bridgeToEyeDisparity") .add(Math.abs(bridgeLeftEyeDistance - bridgeRightEyeDistance) / ((bridgeLeftEyeDistance + bridgeRightEyeDistance) / 2)); properties.get("eyeDistance/mouthLength").add(eyeDistance / mouthLength); properties.get("eyeDistance/noseHeight").add(eyeDistance / noseHeight); properties.get("eyeSize/mouthLength").add(eyeDistance / mouthLength); properties.get("eyeSize/noseHeight").add(eyeDistance / noseHeight); properties.get("mouthLength/mouthHeight").add(mouthLength / mouthHeight); properties.get("chinHeight/noseHeight").add(chinHeight / noseHeight); properties.get("chinHeight/chinToBridgeHeight") .add(chinHeight / chinToBridgeHeight); properties.get("noseHeight/chinToBridgeHeight") .add(noseHeight / chinToBridgeHeight); properties.get("mouthHeight/chinToBridgeHeight") .add(mouthHeight / chinToBridgeHeight); properties.get("faceCountourAngle") .add(Math.toDegrees(Math.atan((faceContourLeft - faceContourRight) / (1 + faceContourLeft * faceContourRight)))); } FSDK.FreeImage(imageHandle); } } System.out.format("%32s\t%8s\t%8s\t%3s%n", "Property", "", "", "c"); System.out.println(new String(new char[76]).replace("\0", "-")); ArrayList<Entry<String, ArrayList<Double>>> propertyList = new ArrayList<>( properties.entrySet()); Collections.sort(propertyList, new Comparator<Entry<String, ArrayList<Double>>>() { @Override public int compare(Entry<String, ArrayList<Double>> arg0, Entry<String, ArrayList<Double>> arg1) { DescriptiveStatistics dStats0 = new DescriptiveStatistics(listToArray(arg0.getValue())); DescriptiveStatistics dStats1 = new DescriptiveStatistics(listToArray(arg1.getValue())); return new Double(dStats0.getStandardDeviation() / dStats0.getMean()) .compareTo(dStats1.getStandardDeviation() / dStats1.getMean()); } }); for (Entry<String, ArrayList<Double>> property : propertyList) { DescriptiveStatistics dStats = new DescriptiveStatistics(listToArray(property.getValue())); System.out.format("%32s\t%4f\t%4f\t%3s%n", property.getKey(), dStats.getMean(), dStats.getStandardDeviation(), Math.round(dStats.getStandardDeviation() / dStats.getMean() * 100) + "%"); } System.out.println("\n"); faceProperties.put(directory, properties); } } for (String propertyName : propertyNames) { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); for (Entry<String, Map<String, ArrayList<Double>>> face : faceProperties.entrySet()) { dataset.add(face.getValue().get(propertyName), "Default Series", face.getKey()); } PropertyBoxWhisker plot = new PropertyBoxWhisker(propertyName, dataset); plot.pack(); plot.setVisible(true); } } }
From source file:com.teradata.benchto.service.model.AggregatedMeasurement.java
public static AggregatedMeasurement aggregate(MeasurementUnit unit, Collection<Double> values) { if (values.size() < 2) { Double value = Iterables.getOnlyElement(values); return new AggregatedMeasurement(unit, value, value, value, 0.0, 0.0); }//from w w w. ja v a2s .c o m DescriptiveStatistics statistics = new DescriptiveStatistics( values.stream().mapToDouble(Double::doubleValue).toArray()); double stdDevPercent = 0.0; if (statistics.getStandardDeviation() > 0.0) { stdDevPercent = (statistics.getStandardDeviation() / statistics.getMean()) * 100; } return new AggregatedMeasurement(unit, statistics.getMin(), statistics.getMax(), statistics.getMean(), statistics.getStandardDeviation(), stdDevPercent); }
From source file:de.uniulm.omi.cloudiator.axe.aggregator.utils.Calc.java
private static DescriptiveStatistics transform(List<Double> values) { double[] arr = toArray(values); return new DescriptiveStatistics(arr); }
From source file:jmb.jcortex.strategies.batchingstrategies.GaussianNoiseBatchingStrategy.java
private SynMatrix calcSD(SynMatrix features) { double[] stds = features.getStreamOfCols().map(col -> new DescriptiveStatistics(col).getStandardDeviation()) .mapToDouble(Double::doubleValue).toArray(); return new SynMatrix(stds); }
From source file:nars.util.meter.func.BasicStatistics.java
public void setWindowSize(int w) { stat = w == 0 ? new SummaryStatistics() : new DescriptiveStatistics(w); }
From source file:es.logongas.encuestas.modelo.resultados.EstadisticaDescriptiva.java
public EstadisticaDescriptiva(double[] datos, int numDecimals) { this.numDecimals = numDecimals; descriptiveStatistics = new DescriptiveStatistics(datos); }
From source file:com.datatorrent.netlet.benchmark.util.BenchmarkResults.java
private DescriptiveStatistics getDescriptiveStatistics() { double[] results = new double[pos]; for (int i = 0; i < pos; i++) { results[i] = this.results[i]; }//from w w w . j a va 2s .c o m return new DescriptiveStatistics(results); }
From source file:com.insightml.evaluation.functions.Gini.java
@Override public DescriptiveStatistics label(final Object[] preds, final Object[] expected, final double[] weights, final ISamples<?, ?> samples, final int labelIndex) { final double gini = gini(preds, expected, false); return new DescriptiveStatistics(new double[] { normalize ? gini / gini(preds, expected, true) : gini, }); }
From source file:edu.nyu.vida.data_polygamy.scalar_function.Median.java
@Override public float getResult() { if (count == 0) return Float.NaN; double[] primitiveValues = new double[floatValues.size()]; for (int i = 0; i < floatValues.size(); i++) primitiveValues[i] = floatValues.get(i); DescriptiveStatistics stats = new DescriptiveStatistics(primitiveValues); return (float) stats.getPercentile(50); }