List of usage examples for org.apache.commons.math3.stat.descriptive StatisticalSummary getStandardDeviation
double getStandardDeviation();
From source file:com.github.christofluyten.experiment.MeasureGendreau.java
/** * @param args/*w w w . ja va2 s.c o m*/ * @throws IOException */ public static void main(String[] args) throws IOException { final List<Gendreau06Scenario> scns = new ArrayList<>( Gendreau06Parser.parser().addDirectory("files/gendreau2006/requests").parse()); Collections.sort(scns, new Comparator<Gendreau06Scenario>() { @Override public int compare(Gendreau06Scenario o1, Gendreau06Scenario o2) { final int compare = o1.getProblemClass().getId().compareTo(o2.getProblemClass().getId()); if (compare == 0) { return o1.getProblemInstanceId().compareTo(o2.getProblemInstanceId()); } return compare; } }); final List<Map<Property, Object>> propsList = new ArrayList<>(); for (final Gendreau06Scenario scen : scns) { final StatisticalSummary urgency = Metrics.measureUrgency(scen); final Multiset<Class<?>> counts = Metrics.getEventTypeCounts(scen); final long scenarioLength = scen.getProblemClass().duration * 60000; final double dyn = Metrics.measureDynamism(scen, scenarioLength); final ImmutableMap<Property, Object> prop = ImmutableMap.<Property, Object>builder() .put(Property.PROBLEM_CLASS, scen.getProblemClass().getId()) .put(Property.INSTANCE_ID, scen.getProblemInstanceId()).put(Property.DYNAMISM, dyn) .put(Property.URGENCY_MEAN, urgency.getMean() / 60000d) .put(Property.URGENCY_SD, urgency.getStandardDeviation() / 60000d) .put(Property.NUM_ORDERS, counts.count(AddParcelEvent.class)) .put(Property.NUM_VEHICLES, counts.count(AddVehicleEvent.class)) .putAll(MAP.get(scen.getProblemInstanceId() + scen.getProblemClass().getId())).build(); propsList.add(prop); } final File targetFile = new File(PROPS_FILE); write(propsList, targetFile, asList(Property.values())); System.out.println("Results written to " + targetFile.getAbsolutePath()); }
From source file:joinery.impl.Aggregation.java
@SuppressWarnings("unchecked") public static <V> DataFrame<V> describe(final DataFrame<V> df) { final DataFrame<V> desc = new DataFrame<>(); for (final Object col : df.columns()) { for (final Object row : df.index()) { final V value = df.get(row, col); if (value instanceof StatisticalSummary) { if (!desc.columns().contains(col)) { desc.add(col);//from w ww .j av a 2 s . c o m if (desc.isEmpty()) { for (final Object r : df.index()) { for (final Object stat : Arrays.asList("count", "mean", "std", "var", "max", "min")) { final Object name = name(df, r, stat); desc.append(name, Collections.<V>emptyList()); } } } } final StatisticalSummary summary = StatisticalSummary.class.cast(value); desc.set(name(df, row, "count"), col, (V) new Double(summary.getN())); desc.set(name(df, row, "mean"), col, (V) new Double(summary.getMean())); desc.set(name(df, row, "std"), col, (V) new Double(summary.getStandardDeviation())); desc.set(name(df, row, "var"), col, (V) new Double(summary.getVariance())); desc.set(name(df, row, "max"), col, (V) new Double(summary.getMax())); desc.set(name(df, row, "min"), col, (V) new Double(summary.getMin())); } } } return desc; }
From source file:com.github.rinde.dynurg.Generator.java
static void createScenarios(RandomGenerator rng, GeneratorSettings generatorSettings, ScenarioGenerator generator, double dynLb, double dynUb, int levels) { final List<Scenario> scenarios = newArrayList(); final Multimap<Double, Scenario> dynamismScenariosMap = LinkedHashMultimap.create(); while (scenarios.size() < levels * TARGET_NUM_INSTANCES) { final Scenario scen = generator.generate(rng, "temp"); Metrics.checkTimeWindowStrictness(scen); final StatisticalSummary urgency = Metrics.measureUrgency(scen); final long expectedUrgency = generatorSettings.urgency * 60000L; if (Math.abs(urgency.getMean() - expectedUrgency) < 0.01 && urgency.getStandardDeviation() < 0.01) { final int numParcels = Metrics.getEventTypeCounts(scen).count(PDPScenarioEvent.ADD_PARCEL); if (numParcels == NUM_ORDERS) { final double dynamism = Metrics.measureDynamism(scen, generatorSettings.officeHours); System.out.print(String.format("%1.3f ", dynamism)); if ((dynamism % DYN_STEP_SIZE < DYN_BANDWIDTH || dynamism % DYN_STEP_SIZE > DYN_STEP_SIZE - DYN_BANDWIDTH) && dynamism <= dynUb && dynamism >= dynLb) { final double targetDyn = Math.round(dynamism / DYN_STEP_SIZE) * DYN_STEP_SIZE; final int numInstances = dynamismScenariosMap.get(targetDyn).size(); if (numInstances < TARGET_NUM_INSTANCES) { final String instanceId = "#" + Integer.toString(numInstances); dynamismScenariosMap.put(targetDyn, scen); final String problemClassId = String.format("%d-%1.2f", (long) (urgency.getMean() / 60000), targetDyn); System.out.println(); System.out.println(" > ACCEPT " + problemClassId); final String fileName = DATASET_DIR + problemClassId + instanceId; try { Files.createParentDirs(new File(fileName)); writePropertiesFile(scen, urgency, dynamism, problemClassId, instanceId, generatorSettings, fileName); MetricsIO.writeLocationList(Metrics.getServicePoints(scen), new File(fileName + ".points")); MetricsIO.writeTimes(scen.getTimeWindow().end, Metrics.getArrivalTimes(scen), new File(fileName + ".times")); final ProblemClass pc = new SimpleProblemClass(problemClassId); final Scenario finalScenario = Scenario.builder(pc).copyProperties(scen) .problemClass(pc).instanceId(instanceId).build(); ScenarioIO.write(finalScenario, new File(fileName + ".scen").toPath()); } catch (final IOException e) { throw new IllegalStateException(e); }/*w w w. ja v a2 s . co m*/ scenarios.add(scen); } } } } } }
From source file:com.github.rinde.dynurg.Generator.java
static void writePropertiesFile(Scenario scen, StatisticalSummary urgency, double dynamism, String problemClassId, String instanceId, GeneratorSettings settings, String fileName) { final DateTimeFormatter formatter = ISODateTimeFormat.dateHourMinuteSecondMillis(); final ImmutableMap.Builder<String, Object> properties = ImmutableMap.<String, Object>builder() .put("problem_class", problemClassId).put("id", instanceId).put("dynamism", dynamism) .put("urgency_mean", urgency.getMean()).put("urgency_sd", urgency.getStandardDeviation()) .put("creation_date", formatter.print(System.currentTimeMillis())) .put("creator", System.getProperty("user.name")).put("day_length", settings.dayLength) .put("office_opening_hours", settings.officeHours); properties.putAll(settings.properties); final ImmutableMultiset<Enum<?>> eventTypes = Metrics.getEventTypeCounts(scen); for (final Multiset.Entry<Enum<?>> en : eventTypes.entrySet()) { properties.put(en.getElement().name(), en.getCount()); }/*from w w w . j a v a 2 s . c o m*/ try { Files.write(Joiner.on("\n").withKeyValueSeparator(" = ").join(properties.build()), new File(fileName + ".properties"), Charsets.UTF_8); } catch (final IOException e) { throw new IllegalStateException(e); } }
From source file:com.github.rinde.datgen.pdptw.ScenarioCreator.java
@Nullable @Override// www .j a v a2 s . co m public GeneratedScenario call() throws Exception { final RandomGenerator rng = new MersenneTwister(getSeed()); final Scenario scen = getGenerator().generate(rng, Long.toString(getId())); Metrics.checkTimeWindowStrictness(scen); // check that urgency matches expected urgency final StatisticalSummary urgency = Metrics.measureUrgency(scen); final long expectedUrgency = getSettings().getUrgency(); if (!(Math.abs(urgency.getMean() - expectedUrgency) < URGENCY_THRESHOLD && urgency.getStandardDeviation() < URGENCY_THRESHOLD)) { System.out.println("Urgency too strict?"); return null; } // check num orders final int numParcels = Metrics.getEventTypeCounts(scen).count(AddParcelEvent.class); if (numParcels != getSettings().getNumOrders()) { System.out.println("Parcels wrong number!"); return null; } // check if dynamism fits in a bin final double dynamism = Metrics.measureDynamism(scen, getSettings().getOfficeHours()); @Nullable final Double dynamismBin = getSettings().getDynamismRangeCenters().get(dynamism); if (dynamismBin == null) { System.out.println("Dynamism " + dynamism + " is too strict"); return null; } return GeneratedScenario.create(scen, getSettings(), getId(), getSeed(), dynamismBin, dynamism); }
From source file:be.ugent.maf.cellmissy.gui.view.table.model.SingleCellStatSummaryTableModel.java
/** * Initialize table/* ww w .j ava 2s . c o m*/ */ private void initTable() { // list of summaries from the analysis group: number of rows List<StatisticalSummary> statisticalSummaries = singleCellAnalysisGroup.getStatisticalSummaries(); int size = statisticalSummaries.size(); // columns: 1 + 6 for statistical numbers columnNames = new String[7]; columnNames[0] = ""; columnNames[1] = "Max"; columnNames[2] = "Min"; columnNames[3] = "Mean"; columnNames[4] = "N"; columnNames[5] = "SD"; columnNames[6] = "Variance"; singleCellAnalysisGroup.getConditionDataHolders(); data = new Object[size][columnNames.length]; // fill in data for (int rowIndex = 0; rowIndex < data.length; rowIndex++) { data[rowIndex][0] = "Cond " + (singleCellAnalysisGroup.getConditionDataHolders().get(rowIndex).getPlateCondition()); // summary for a row StatisticalSummary statisticalSummary = statisticalSummaries.get(rowIndex); // distribute statistical objects per columns data[rowIndex][1] = statisticalSummary.getMax(); data[rowIndex][2] = statisticalSummary.getMin(); data[rowIndex][3] = statisticalSummary.getMean(); data[rowIndex][4] = statisticalSummary.getN(); data[rowIndex][5] = statisticalSummary.getStandardDeviation(); data[rowIndex][6] = statisticalSummary.getVariance(); } }
From source file:ijfx.core.stats.DefaultImageStatisticsService.java
@Override public Map<String, Double> summaryStatisticsToMap(StatisticalSummary summaryStats) { Map<String, Double> statistics = new HashMap<>(); statistics.put(LBL_MEAN, summaryStats.getMean()); statistics.put(LBL_MIN, summaryStats.getMin()); statistics.put(LBL_MAX, summaryStats.getMax()); statistics.put(LBL_SD, summaryStats.getStandardDeviation()); statistics.put(LBL_VARIANCE, summaryStats.getVariance()); statistics.put(LBL_PIXEL_COUNT, (double) summaryStats.getN()); return statistics; }
From source file:net.sourceforge.jabm.gametheory.CompressedPayoffMatrix.java
public void export(DataWriter out) { Iterator<Entry> entries = orderedEntryIterator(); while (entries.hasNext()) { Entry entry = entries.next();/*from w w w. j a v a2s .c o m*/ for (int s = 0; s < numStrategies; s++) { out.newData(entry.getNumAgents(s)); } PayoffMap payoffs = getCompressedPayoffs(entry); for (int i = 0; i < payoffs.size(); i++) { StatisticalSummary payoffStats = payoffs.getPayoffDistribution(i); out.newData(payoffStats.getMean()); out.newData(payoffStats.getStandardDeviation()); out.newData(payoffStats.getN()); } } }
From source file:org.briljantframework.data.dataframe.DataFrames.java
/** * Presents a summary of the given data frame. For each column of {@code df} the returned summary * contains one row. Each row is described by four values, the {@code min}, {@code max}, * {@code mean} and {@code mode}. The first three are presented for numerical columns and the * fourth for categorical./*from www . ja va 2 s. co m*/ * * <pre> * {@code * > DataFrame df = MixedDataFrame.of( * "a", Vector.of(1, 2, 3, 4, 5, 6), * "b", Vector.of("a", "b", "b", "b", "e", "f"), * "c", Vector.of(1.1, 1.2, 1.3, 1.4, 1.5, 1.6) * ); * * > DataFrames.summary(df) * mean var std min max mode * a 3.500 3.500 1.871 1.000 6.000 6 * b NA NA NA NA NA f * c 1.350 0.035 0.187 1.100 1.600 1.1 * * [3 rows x 6 columns] * } * </pre> * * @param df the data frame * @return a data frame summarizing {@code df} */ public static DataFrame summary(DataFrame df) { DataFrame.Builder builder = new MixedDataFrame.Builder(); builder.set("mean", VectorType.DOUBLE).set("var", VectorType.DOUBLE).set("std", VectorType.DOUBLE) .set("min", VectorType.DOUBLE).set("max", VectorType.DOUBLE).set("mode", VectorType.OBJECT); for (Object columnKey : df.getColumnIndex().keySet()) { Vector column = df.get(columnKey); if (Is.numeric(column)) { StatisticalSummary summary = column.collect(Number.class, Collectors.statisticalSummary()); builder.set(columnKey, "mean", summary.getMean()).set(columnKey, "var", summary.getVariance()) .set(columnKey, "std", summary.getStandardDeviation()) .set(columnKey, "min", summary.getMin()).set(columnKey, "max", summary.getMax()); } builder.set(columnKey, "mode", column.collect(Collectors.mode())); } return builder.build(); }
From source file:org.briljantframework.data.dataframe.transform.ZNormalizer.java
@Override public Transformer fit(DataFrame df) { Vector.Builder meanBuilder = Vector.Builder.of(Double.class); Vector.Builder stdBuilder = Vector.Builder.of(Double.class); for (Object columnKey : df) { StatisticalSummary stats = Vectors.statisticalSummary(df.get(columnKey)); if (stats.getN() <= 0 || Is.NA(stats.getMean()) || Is.NA(stats.getStandardDeviation())) { throw new IllegalArgumentException("Illegal value for column " + columnKey); }/*from w ww. ja v a2s . c o m*/ meanBuilder.set(columnKey, stats.getMean()); stdBuilder.set(columnKey, stats.getStandardDeviation()); } Vector mean = meanBuilder.build(); Vector sigma = stdBuilder.build(); return new ZNormalizerTransformer(mean, sigma); }