MATSIM
BiasNormalizedErrorGraph.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * BiasErrorGraph.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package org.matsim.counts.algorithms.graphs;
22 
23 import java.awt.Font;
24 import java.util.List;
25 
26 import org.jfree.chart.ChartFactory;
27 import org.jfree.chart.JFreeChart;
28 import org.jfree.chart.axis.AxisLocation;
29 import org.jfree.chart.axis.CategoryAxis;
30 import org.jfree.chart.axis.NumberAxis;
31 import org.jfree.chart.axis.ValueAxis;
32 import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
33 import org.jfree.chart.plot.CategoryPlot;
34 import org.jfree.chart.plot.DatasetRenderingOrder;
35 import org.jfree.chart.plot.PlotOrientation;
36 import org.jfree.chart.renderer.category.LineAndShapeRenderer;
37 import org.jfree.data.category.DefaultCategoryDataset;
40 
41 public final class BiasNormalizedErrorGraph extends CountsGraph {
42 
44 
45  public BiasNormalizedErrorGraph(final List<CountSimComparison> ccl, final int iteration, final String filename,
46  final String chartTitle) {
47  super(ccl, iteration, filename, chartTitle);
48  }
49 
50  @Override
51  public JFreeChart createChart(final int nbr) {
52  DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
53  DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
54 
55  this.errorStats = new ComparisonErrorStatsCalculator(this.ccl_);
56 
57  double[] meanNormRelError = this.errorStats.getMeanNormRelError();
58 // double[] meanAbsError = this.errorStats.getMeanAbsError();
59  double[] meanBias = this.errorStats.getMeanBias();
60 
61  for (int h = 0; h < 24; h++) {
62  meanNormRelError[h] *= 100;
63  dataset0.addValue(meanNormRelError[h], "Mean norm rel error", Integer.toString(h + 1));
64 // dataset1.addValue(meanAbsError[h], "Mean abs error", Integer.toString(h + 1));
65  dataset1.addValue(meanBias[h], "Mean bias", Integer.toString(h + 1));
66  }
67 
68  this.chart_ = ChartFactory.createLineChart("", "Hour", "Mean norm rel error [%]", dataset0, PlotOrientation.VERTICAL,
69  true, // legend?
70  true, // tooltips?
71  false // URLs?
72  );
73  CategoryPlot plot = this.chart_.getCategoryPlot();
74  plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
75  plot.setDataset(1, dataset1);
76  plot.mapDatasetToRangeAxis(1, 1);
77 
78  final LineAndShapeRenderer renderer = new LineAndShapeRenderer();
79  renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator());
80  plot.setRenderer(0, renderer);
81 
82  final CategoryAxis axis1 = new CategoryAxis("Hour");
83  axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
84  plot.setDomainAxis(axis1);
85 
86 // final ValueAxis axis2 = new NumberAxis("Mean abs {bias, error} [veh/h]");
87  final ValueAxis axis2 = new NumberAxis("Mean bias [veh/h]");
88  plot.setRangeAxis(1, axis2);
89 
90  final ValueAxis axis3 = plot.getRangeAxis(0);
91  axis3.setRange(0.0, 100.0);
92 
93  final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
94  renderer2.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator());
95  renderer2.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator());
96 // renderer2.setSeriesPaint(0, Color.black);
97  plot.setRenderer(1, renderer2);
98  plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
99 
100  return this.chart_;
101  }
102 
103  public double[] getMeanNormRelError() {
104  if (this.errorStats == null) {
105  throw new RuntimeException("Object not initialized correctly. Call createChart(..) first!");
106  }
107  return this.errorStats.getMeanRelError();
108  }
109 
110  public double[] getMeanBias() {
111  if (this.errorStats == null) {
112  throw new RuntimeException("Object not initialized correctly. Call createChart(..) first!");
113  }
114  return this.errorStats.getMeanBias();
115  }
116 }
BiasNormalizedErrorGraph(final List< CountSimComparison > ccl, final int iteration, final String filename, final String chartTitle)