private Integer getSkeletonCategoryFromPercentiles(
      Integer value, DescriptiveStatistics windowStats) {
    Integer skeletonCategory = 0;
    // Calculate skeleton category
    if (value == (int) windowStats.getMin()) {
      skeletonCategory = 10;
    } else if (value < windowStats.getPercentile(10)) {
      skeletonCategory = 9;
    } else if (value < windowStats.getPercentile(15)) {
      skeletonCategory = 8;
    } else if (value < windowStats.getPercentile(20)) {
      skeletonCategory = 7;
    } else if (value < windowStats.getPercentile(25)) {
      skeletonCategory = 6;
    } else if (value < windowStats.getPercentile(30)) {
      skeletonCategory = 5;
    } else if (value < windowStats.getPercentile(35)) {
      skeletonCategory = 4;
    } else if (value < windowStats.getPercentile(40)) {
      skeletonCategory = 3;
    } else if (value < windowStats.getPercentile(45)) {
      skeletonCategory = 2;
    } else if (value < windowStats.getPercentile(50)) {
      skeletonCategory = 1;
    }

    return skeletonCategory;
  }
  private void writeErrorFile(DescriptiveStatistics error, String file, boolean append) {
    try {
      BufferedWriter writer = new BufferedWriter(new FileWriter(file, append));
      if (!append) {
        // write header
        writer.write("mean\tvar\tstderr\tmin\tmax");
        writer.newLine();
      }

      writer.write(String.valueOf(error.getMean()));
      writer.write("\t");
      writer.write(String.valueOf(error.getVariance()));
      writer.write("\t");
      writer.write(String.valueOf(error.getStandardDeviation()));
      writer.write("\t");
      writer.write(String.valueOf(error.getMin()));
      writer.write("\t");
      writer.write(String.valueOf(error.getMax()));
      writer.newLine();

      writer.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Beispiel #3
0
  @Override
  public String getSummaryReport() {
    final StringBuilder outBuffer = new StringBuilder();

    final DescriptiveStatistics ds = computeStats();
    outBuffer.append("Aggregate P@" + N + " Statistics:\n");
    outBuffer.append(String.format("%-15s\t%6d\n", "num_q", ds.getN()));
    outBuffer.append(String.format("%-15s\t%6.4f\n", "min", ds.getMin()));
    outBuffer.append(String.format("%-15s\t%6.4f\n", "max", ds.getMax()));
    outBuffer.append(String.format("%-15s\t%6.4f\n", "mean", ds.getMean()));
    outBuffer.append(String.format("%-15s\t%6.4f\n", "std dev", ds.getStandardDeviation()));
    outBuffer.append(String.format("%-15s\t%6.4f\n", "median", ds.getPercentile(50)));
    outBuffer.append(String.format("%-15s\t%6.4f\n", "skewness", ds.getSkewness()));
    outBuffer.append(String.format("%-15s\t%6.4f\n", "kurtosis", ds.getKurtosis()));

    return outBuffer.toString();
  }
  public void test() {
    SparseGraphBuilder builder = new SparseGraphBuilder();
    SparseGraph graph = builder.createGraph();

    SparseVertex v1 = builder.addVertex(graph);
    SparseVertex v2 = builder.addVertex(graph);
    SparseVertex v3 = builder.addVertex(graph);
    SparseVertex v4 = builder.addVertex(graph);
    SparseVertex v5 = builder.addVertex(graph);
    SparseVertex v6 = builder.addVertex(graph);

    builder.addEdge(graph, v1, v2);
    builder.addEdge(graph, v2, v3);
    builder.addEdge(graph, v3, v4);
    builder.addEdge(graph, v4, v5);
    builder.addEdge(graph, v5, v6);
    builder.addEdge(graph, v6, v1);
    builder.addEdge(graph, v2, v5);

    Degree degree = Degree.getInstance();

    DescriptiveStatistics stats = degree.statistics(graph.getVertices());
    assertEquals(2.33, stats.getMean(), 0.01);
    assertEquals(2.0, stats.getMin());
    assertEquals(3.0, stats.getMax());

    TObjectDoubleHashMap<? extends Vertex> values = degree.values(graph.getVertices());
    TObjectDoubleIterator<? extends Vertex> it = values.iterator();

    int count2 = 0;
    int count3 = 0;
    for (int i = 0; i < values.size(); i++) {
      it.advance();
      if (it.value() == 2) count2++;
      else if (it.value() == 3) count3++;
    }

    assertEquals(4, count2);
    assertEquals(2, count3);

    assertEquals(-0.166, degree.assortativity(graph), 0.001);
  }
  private Integer getSkeletonCategoryFromCropper1979(
      Integer value, DescriptiveStatistics windowStats, Double criticalLevel) {
    Integer skeletonCategory = 0;

    if (criticalLevel == null) criticalLevel = 0.5;
    double mean = windowStats.getMean();
    double stdev = windowStats.getStandardDeviation();
    double smallRingThreshold = mean - (stdev * criticalLevel);
    int min = (int) windowStats.getMin();

    if (value == min) {
      skeletonCategory = 10;
    } else if (value > smallRingThreshold) {
      skeletonCategory = 0;
    } else {
      Integer range = (int) (smallRingThreshold - min);
      Integer categoryStepSize = range / 10;
      skeletonCategory = (int) (0 - ((value - smallRingThreshold) / categoryStepSize));
    }

    return skeletonCategory;
  }
  private void writeReport(String test, String name, DescriptiveStatistics statistics)
      throws IOException {
    File report = new File("target", test + ".txt");

    boolean needsPrefix = !report.exists();
    PrintWriter writer = new PrintWriter(new FileWriterWithEncoding(report, "UTF-8", true));
    try {
      if (needsPrefix) {
        writer.format("# %-34.34s     min     10%%     50%%     90%%     max%n", test);
      }

      writer.format(
          "%-36.36s  %6.0f  %6.0f  %6.0f  %6.0f  %6.0f%n",
          name,
          statistics.getMin(),
          statistics.getPercentile(10.0),
          statistics.getPercentile(50.0),
          statistics.getPercentile(90.0),
          statistics.getMax());
    } finally {
      writer.close();
    }
  }
 /**
  * Returns the minimal throughput time. Note that method calculateProcessMetrics() should be
  * called before this method.
  *
  * @return double
  */
 public double getMinThroughputTime() {
   return timeStats.getMin();
 }
  @Override
  public void notifyAfterMobsim(AfterMobsimEvent event) {
    Network network = event.getServices().getScenario().getNetwork();
    DescriptiveStatistics error = new DescriptiveStatistics();
    DescriptiveStatistics errorAbs = new DescriptiveStatistics();
    DescriptivePiStatistics errorWeighted = new WSMStatsFactory().newInstance();

    TDoubleArrayList errorVals = new TDoubleArrayList();
    TDoubleArrayList caps = new TDoubleArrayList();
    TDoubleArrayList speeds = new TDoubleArrayList();

    for (Count count : counts.getCounts().values()) {
      if (!count.getId().toString().startsWith(ODCalibrator.VIRTUAL_ID_PREFIX)) {
        double obsVal = 0;
        for (int i = 1; i < 25; i++) {
          obsVal += count.getVolume(i).getValue();
        }

        if (obsVal > 0) {
          double simVal = calculator.getOccupancy(count.getId());
          simVal *= factor;

          double err = (simVal - obsVal) / obsVal;

          error.addValue(err);
          errorAbs.addValue(Math.abs(err));
          errorWeighted.addValue(Math.abs(err), 1 / obsVal);

          Link link = network.getLinks().get(count.getId());
          errorVals.add(Math.abs(err));
          caps.add(link.getCapacity());
          speeds.add(link.getFreespeed());
        }
      }
    }

    logger.info(
        String.format(
            "Relative counts error: mean = %s, var = %s, stderr = %s, min = %s, max = %s",
            error.getMean(),
            error.getVariance(),
            error.getStandardDeviation(),
            error.getMin(),
            error.getMax()));
    logger.info(
        String.format(
            "Absolute relative counts error: mean = %s, var = %s, stderr = %s, min = %s, max = %s",
            errorAbs.getMean(),
            errorAbs.getVariance(),
            errorAbs.getStandardDeviation(),
            errorAbs.getMin(),
            errorAbs.getMax()));
    logger.info(
        String.format(
            "Absolute weigthed relative counts error: mean = %s, var = %s, stderr = %s, min = %s, max = %s",
            errorWeighted.getMean(),
            errorWeighted.getVariance(),
            errorWeighted.getStandardDeviation(),
            errorWeighted.getMin(),
            errorWeighted.getMax()));

    String outdir = event.getServices().getControlerIO().getIterationPath(event.getIteration());

    try {
      TDoubleDoubleHashMap map = Correlations.mean(caps.toArray(), errorVals.toArray());
      StatsWriter.writeHistogram(
          map, "capacity", "counts", String.format("%s/countsError.capacity.txt", outdir));

      map = Correlations.mean(speeds.toArray(), errorVals.toArray());
      StatsWriter.writeHistogram(
          map, "speed", "counts", String.format("%s/countsError.speed.txt", outdir));

      StatsWriter.writeHistogram(
          Histogram.createHistogram(error, new LinearDiscretizer(0.1), false),
          "Error",
          "Frequency",
          String.format("%s/countsError.hist.txt", outdir));
      StatsWriter.writeHistogram(
          Histogram.createHistogram(errorAbs, new LinearDiscretizer(0.1), false),
          "Error (absolute)",
          "Frequency",
          String.format("%s/countsErrorAbs.hist.txt", outdir));
      StatsWriter.writeHistogram(
          Histogram.createHistogram(errorWeighted, new LinearDiscretizer(0.1), true),
          "Error (weighted)",
          "Frequency",
          String.format("%s/countsErrorWeighted.hist.txt", outdir));

      CountsCompare2GeoJSON.write(calculator, counts, factor, network, outdir);
      NetworkLoad2GeoJSON.write(
          event.getServices().getScenario().getNetwork(),
          calculator,
          factor,
          outdir + "/network.json");
    } catch (Exception e) {
      e.printStackTrace();
    }

    String rootOutDir = event.getServices().getControlerIO().getOutputPath();
    boolean append = false;
    if (event.getIteration() > 0) {
      append = true;
    }
    writeErrorFile(error, String.format("%s/countsError.txt", rootOutDir), append);
    writeErrorFile(errorAbs, String.format("%s/countsAbsError.txt", rootOutDir), append);
  }
 /**
  * Get the min of y values.
  *
  * @return y values min
  */
 public double getYMin() {
   return yData.getMin();
 }
 /**
  * Get the min of x values.
  *
  * @return x values min
  */
 public double getXMin() {
   return xData.getMin();
 }
 /**
  * Creates a colorizer which color spectrum is scaled to the degree distribution of
  * <tt>graph</tt>.
  *
  * @param graph a graph
  */
 public VertexDegreeColorizer(Graph graph) {
   Degree degree = Degree.getInstance();
   DescriptiveStatistics distr = degree.statistics(graph.getVertices());
   k_min = (int) distr.getMin();
   k_max = (int) distr.getMax();
 }