TAGraph { static XYDataset getMinMax(XYDataset data, int series, int distance) { XYSeriesCollection seriesCollection = new XYSeriesCollection(); XYSeries mins = new XYSeries("min"); XYSeries maxs = new XYSeries("max"); seriesCollection.addSeries(maxs); seriesCollection.addSeries(mins); double[] coeffs = getRegressionWithSigma(data, 0); Function2D[] funcs = new Function2D[]{ new LineFunction2D(coeffs[0] + distance * coeffs[2], coeffs[1] + distance * coeffs[3]), new LineFunction2D(coeffs[0] + distance * coeffs[2], coeffs[1] - distance * coeffs[3]), new LineFunction2D(coeffs[0] - distance * coeffs[2], coeffs[1] + distance * coeffs[3]), new LineFunction2D(coeffs[0] - distance * coeffs[2], coeffs[1] - distance * coeffs[3]) }; int n = data.getItemCount(series); for (int i = 0; i < n; i++) { double x = data.getXValue(series, i); double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; for (Function2D func : funcs) { double y = func.getValue(x); min = Math.min(min, y); max = Math.max(max, y); } mins.add(x, min); maxs.add(x, max); } return seriesCollection; } TAGraph(TAResult taResult); JFreeChart createAnomalyGraph(String regionName, int featureIndex); JFreeChart createYearlyCyclGaph(String regionName, int featureIndex); JFreeChart createTimeseriesGaph(String regionName, int featureIndex); JFreeChart createTimeseriesSigmaGraph(String regionName, int featureIndex, int sigmaIndex); static void writeChart(JFreeChart chart, OutputStream outputStream); static void main(String[] args); static final String DATE_PATTERN; static final DateFormat DATE_FORMAT; }
@Test public void testGetMinMax() throws Exception { double[][] data = { {-3.20, 4.49, -1.66, 0.64, -2.43, -0.89, -0.12, 1.41, 2.95, 2.18, 3.72, 5.26}, {-7.14, -1.30, -4.26, -1.90, -6.19, -3.98, -2.87, -1.66, -0.78, -2.61, 0.31, 1.74} }; DefaultXYDataset xyDataset = new DefaultXYDataset(); xyDataset.addSeries("", data); assertEquals(1.74, DatasetUtilities.findMaximumRangeValue(xyDataset).doubleValue(), 1E-6); assertEquals(-7.14, DatasetUtilities.findMinimumRangeValue(xyDataset).doubleValue(), 1E-6); XYDataset minMax = TAGraph.getMinMax(xyDataset, 0, 2); assertNotNull(minMax); assertEquals(12, minMax.getItemCount(0)); assertEquals(2.7237106448737287, DatasetUtilities.findMaximumRangeValue(minMax).doubleValue(), 1E-6); assertEquals(-7.420430270367225, DatasetUtilities.findMinimumRangeValue(minMax).doubleValue(), 1E-6); minMax = TAGraph.getMinMax(xyDataset, 0, 1); assertNotNull(minMax); assertEquals(12, minMax.getItemCount(0)); assertEquals(1.9199516236179388, DatasetUtilities.findMaximumRangeValue(minMax).doubleValue(), 1E-6); assertEquals(-6.820921995237573, DatasetUtilities.findMinimumRangeValue(minMax).doubleValue(), 1E-6); }