@Test public void linearRangeFromFunction2D() { Cell2DDataset dataset = Cell2DDatasets.linearRange(new Cell2DDatasets.Function2D() { @Override public double getValue(double x, double y) { return x + y; } }, Ranges.range(0, 1), 10, Ranges.range(0, 1), 20); assertThat(dataset.getXCount(), equalTo(10)); assertThat(dataset.getXRange().getMinimum(), equalTo(0.0)); assertThat(dataset.getXRange().getMaximum(), equalTo(1.0)); assertThat(dataset.getYCount(), equalTo(20)); assertThat(dataset.getYRange().getMinimum(), equalTo(0.0)); assertThat(dataset.getYRange().getMaximum(), equalTo(1.0)); assertThat(dataset.getStatistics().getAverage(), closeTo(1.0, 0.0001)); assertThat(dataset.getStatistics().getStdDev(), closeTo(0.40697, 0.0001)); assertThat(dataset.getStatistics().getCount(), equalTo(200)); assertThat(dataset.getStatistics().getRange().getMinimum(), closeTo(0.075, 0.0001)); assertThat(dataset.getStatistics().getRange().getMaximum(), closeTo(1.925, 0.0001)); assertThat(dataset.getXBoundaries().getDouble(0), equalTo(0.0)); assertThat(dataset.getYBoundaries().getDouble(0), equalTo(0.0)); assertThat(dataset.getValue(0, 0), closeTo(0.075, 0.0001)); assertThat(dataset.getValue(9, 19), closeTo(1.925, 0.0001)); assertThat(dataset.getXBoundaries().getDouble(10), equalTo(1.0)); assertThat(dataset.getYBoundaries().getDouble(20), equalTo(1.0)); }
public static Cell2DDataset linearRange(final ListNumber data, final Range xRange, final int xCount, final Range yRange, final int yCount) { if (data.size() == 0) { throw new IllegalArgumentException("Empty Dataset. zData size = " + data.size()); } if (xCount <= 0 || yCount <= 0) { throw new IllegalArgumentException("Number of X (or Y) values must be greater than 0. xCount = " + xCount + " yCount = " + yCount); } final int expectedSize = xCount * yCount; if (expectedSize != data.size()) { throw new IllegalArgumentException("Unexpected number of X (or Y) values. Array length = " + (data.size()) + ", Predicted size(given X and Y) = " + expectedSize + ", xCount = " + xCount + ", yCount = " + yCount); } final ListNumber xBoundaries = ListNumbers.linearListFromRange(xRange.getMinimum(), xRange.getMaximum(), xCount + 1); final ListNumber yBoundaries = ListNumbers.linearListFromRange(yRange.getMinimum(), yRange.getMaximum(), yCount + 1); final Statistics stats = StatisticsUtil.statisticsOf(data); return new Cell2DDataset() { @Override public double getValue(int x, int y) { return data.getDouble(y * xCount + x); } @Override public Statistics getStatistics() { return stats; } @Override public Range getDisplayRange() { return stats.getRange(); } @Override public ListNumber getXBoundaries() { return xBoundaries; } @Override public Range getXRange() { return xRange; } @Override public int getXCount() { return xCount; } @Override public ListNumber getYBoundaries() { return yBoundaries; } @Override public Range getYRange() { return yRange; } @Override public int getYCount() { return yCount; } }; }
Cell2DDatasets { public static Cell2DDataset linearRange(final ListNumber data, final Range xRange, final int xCount, final Range yRange, final int yCount) { if (data.size() == 0) { throw new IllegalArgumentException("Empty Dataset. zData size = " + data.size()); } if (xCount <= 0 || yCount <= 0) { throw new IllegalArgumentException("Number of X (or Y) values must be greater than 0. xCount = " + xCount + " yCount = " + yCount); } final int expectedSize = xCount * yCount; if (expectedSize != data.size()) { throw new IllegalArgumentException("Unexpected number of X (or Y) values. Array length = " + (data.size()) + ", Predicted size(given X and Y) = " + expectedSize + ", xCount = " + xCount + ", yCount = " + yCount); } final ListNumber xBoundaries = ListNumbers.linearListFromRange(xRange.getMinimum(), xRange.getMaximum(), xCount + 1); final ListNumber yBoundaries = ListNumbers.linearListFromRange(yRange.getMinimum(), yRange.getMaximum(), yCount + 1); final Statistics stats = StatisticsUtil.statisticsOf(data); return new Cell2DDataset() { @Override public double getValue(int x, int y) { return data.getDouble(y * xCount + x); } @Override public Statistics getStatistics() { return stats; } @Override public Range getDisplayRange() { return stats.getRange(); } @Override public ListNumber getXBoundaries() { return xBoundaries; } @Override public Range getXRange() { return xRange; } @Override public int getXCount() { return xCount; } @Override public ListNumber getYBoundaries() { return yBoundaries; } @Override public Range getYRange() { return yRange; } @Override public int getYCount() { return yCount; } }; } }
Cell2DDatasets { public static Cell2DDataset linearRange(final ListNumber data, final Range xRange, final int xCount, final Range yRange, final int yCount) { if (data.size() == 0) { throw new IllegalArgumentException("Empty Dataset. zData size = " + data.size()); } if (xCount <= 0 || yCount <= 0) { throw new IllegalArgumentException("Number of X (or Y) values must be greater than 0. xCount = " + xCount + " yCount = " + yCount); } final int expectedSize = xCount * yCount; if (expectedSize != data.size()) { throw new IllegalArgumentException("Unexpected number of X (or Y) values. Array length = " + (data.size()) + ", Predicted size(given X and Y) = " + expectedSize + ", xCount = " + xCount + ", yCount = " + yCount); } final ListNumber xBoundaries = ListNumbers.linearListFromRange(xRange.getMinimum(), xRange.getMaximum(), xCount + 1); final ListNumber yBoundaries = ListNumbers.linearListFromRange(yRange.getMinimum(), yRange.getMaximum(), yCount + 1); final Statistics stats = StatisticsUtil.statisticsOf(data); return new Cell2DDataset() { @Override public double getValue(int x, int y) { return data.getDouble(y * xCount + x); } @Override public Statistics getStatistics() { return stats; } @Override public Range getDisplayRange() { return stats.getRange(); } @Override public ListNumber getXBoundaries() { return xBoundaries; } @Override public Range getXRange() { return xRange; } @Override public int getXCount() { return xCount; } @Override public ListNumber getYBoundaries() { return yBoundaries; } @Override public Range getYRange() { return yRange; } @Override public int getYCount() { return yCount; } }; }  }
Cell2DDatasets { public static Cell2DDataset linearRange(final ListNumber data, final Range xRange, final int xCount, final Range yRange, final int yCount) { if (data.size() == 0) { throw new IllegalArgumentException("Empty Dataset. zData size = " + data.size()); } if (xCount <= 0 || yCount <= 0) { throw new IllegalArgumentException("Number of X (or Y) values must be greater than 0. xCount = " + xCount + " yCount = " + yCount); } final int expectedSize = xCount * yCount; if (expectedSize != data.size()) { throw new IllegalArgumentException("Unexpected number of X (or Y) values. Array length = " + (data.size()) + ", Predicted size(given X and Y) = " + expectedSize + ", xCount = " + xCount + ", yCount = " + yCount); } final ListNumber xBoundaries = ListNumbers.linearListFromRange(xRange.getMinimum(), xRange.getMaximum(), xCount + 1); final ListNumber yBoundaries = ListNumbers.linearListFromRange(yRange.getMinimum(), yRange.getMaximum(), yCount + 1); final Statistics stats = StatisticsUtil.statisticsOf(data); return new Cell2DDataset() { @Override public double getValue(int x, int y) { return data.getDouble(y * xCount + x); } @Override public Statistics getStatistics() { return stats; } @Override public Range getDisplayRange() { return stats.getRange(); } @Override public ListNumber getXBoundaries() { return xBoundaries; } @Override public Range getXRange() { return xRange; } @Override public int getXCount() { return xCount; } @Override public ListNumber getYBoundaries() { return yBoundaries; } @Override public Range getYRange() { return yRange; } @Override public int getYCount() { return yCount; } }; }  static Cell2DDataset linearRange(final ListNumber data, final Range xRange, final int xCount, final Range yRange, final int yCount); static Cell2DDataset linearRange(final Function2D function, final Range xRange, final int xCount, final Range yRange, final int yCount); static Cell2DDataset datasetFrom(final Function2D function, final ListNumber xBoundaries, final ListNumber yBoundaries); static Cell2DDataset datasetFrom(final ListNumber values, final ListNumber xBoundaries, final ListNumber yBoundaries); }
Cell2DDatasets { public static Cell2DDataset linearRange(final ListNumber data, final Range xRange, final int xCount, final Range yRange, final int yCount) { if (data.size() == 0) { throw new IllegalArgumentException("Empty Dataset. zData size = " + data.size()); } if (xCount <= 0 || yCount <= 0) { throw new IllegalArgumentException("Number of X (or Y) values must be greater than 0. xCount = " + xCount + " yCount = " + yCount); } final int expectedSize = xCount * yCount; if (expectedSize != data.size()) { throw new IllegalArgumentException("Unexpected number of X (or Y) values. Array length = " + (data.size()) + ", Predicted size(given X and Y) = " + expectedSize + ", xCount = " + xCount + ", yCount = " + yCount); } final ListNumber xBoundaries = ListNumbers.linearListFromRange(xRange.getMinimum(), xRange.getMaximum(), xCount + 1); final ListNumber yBoundaries = ListNumbers.linearListFromRange(yRange.getMinimum(), yRange.getMaximum(), yCount + 1); final Statistics stats = StatisticsUtil.statisticsOf(data); return new Cell2DDataset() { @Override public double getValue(int x, int y) { return data.getDouble(y * xCount + x); } @Override public Statistics getStatistics() { return stats; } @Override public Range getDisplayRange() { return stats.getRange(); } @Override public ListNumber getXBoundaries() { return xBoundaries; } @Override public Range getXRange() { return xRange; } @Override public int getXCount() { return xCount; } @Override public ListNumber getYBoundaries() { return yBoundaries; } @Override public Range getYRange() { return yRange; } @Override public int getYCount() { return yCount; } }; }  static Cell2DDataset linearRange(final ListNumber data, final Range xRange, final int xCount, final Range yRange, final int yCount); static Cell2DDataset linearRange(final Function2D function, final Range xRange, final int xCount, final Range yRange, final int yCount); static Cell2DDataset datasetFrom(final Function2D function, final ListNumber xBoundaries, final ListNumber yBoundaries); static Cell2DDataset datasetFrom(final ListNumber values, final ListNumber xBoundaries, final ListNumber yBoundaries);  }