@Test public void datasetFromFunction2D() { Cell2DDataset dataset = Cell2DDatasets.datasetFrom(new Cell2DDatasets.Function2D() { @Override public double getValue(double x, double y) { return x + y; } }, new ArrayDouble(0, 2, 3, 5), new ArrayDouble(0, 1, 3)); assertThat(dataset.getXCount(), equalTo(3)); assertThat(dataset.getXRange().getMinimum(), equalTo(0.0)); assertThat(dataset.getXRange().getMaximum(), equalTo(5.0)); assertThat(dataset.getYCount(), equalTo(2)); assertThat(dataset.getYRange().getMinimum(), equalTo(0.0)); assertThat(dataset.getYRange().getMaximum(), equalTo(3.0)); assertThat(dataset.getStatistics().getAverage(), equalTo(3.75)); assertThat(dataset.getStatistics().getStdDev(), closeTo(1.43614, 0.0001)); assertThat(dataset.getStatistics().getRange().getMinimum(), equalTo((Number) (1.5))); assertThat(dataset.getStatistics().getRange().getMaximum(), equalTo((Number) 6.0)); assertThat(dataset.getStatistics().getCount(), equalTo(6)); assertThat(dataset.getXBoundaries().getDouble(0), equalTo(0.0)); assertThat(dataset.getXBoundaries().getDouble(1), equalTo(2.0)); assertThat(dataset.getXBoundaries().getDouble(2), equalTo(3.0)); assertThat(dataset.getXBoundaries().getDouble(3), equalTo(5.0)); assertThat(dataset.getYBoundaries().getDouble(0), equalTo(0.0)); assertThat(dataset.getYBoundaries().getDouble(1), equalTo(1.0)); assertThat(dataset.getYBoundaries().getDouble(2), equalTo(3.0)); assertThat(dataset.getValue(0, 0), equalTo(1.5)); assertThat(dataset.getValue(1, 0), equalTo(3.0)); assertThat(dataset.getValue(2, 0), equalTo(4.5)); assertThat(dataset.getValue(0, 1), equalTo(3.0)); assertThat(dataset.getValue(1, 1), equalTo(4.5)); assertThat(dataset.getValue(2, 1), equalTo(6.0)); }
public static Cell2DDataset datasetFrom(final Function2D function, final ListNumber xBoundaries, final ListNumber yBoundaries) { int yCount = yBoundaries.size() - 1; int xCount = xBoundaries.size() - 1; double[] values = new double[yCount * xCount]; for (int y = 0; y < yCount; y++) { double middleY = (yBoundaries.getDouble(y) + yBoundaries.getDouble(y + 1)) / 2; for (int x = 0; x < xCount; x++) { double middleX = (xBoundaries.getDouble(x) + xBoundaries.getDouble(x + 1)) / 2; values[y * xCount + x] = function.getValue(middleX, middleY); } } ListDouble data = new ArrayDouble(values); return datasetFrom(data, xBoundaries, yBoundaries); }
Cell2DDatasets { public static Cell2DDataset datasetFrom(final Function2D function, final ListNumber xBoundaries, final ListNumber yBoundaries) { int yCount = yBoundaries.size() - 1; int xCount = xBoundaries.size() - 1; double[] values = new double[yCount * xCount]; for (int y = 0; y < yCount; y++) { double middleY = (yBoundaries.getDouble(y) + yBoundaries.getDouble(y + 1)) / 2; for (int x = 0; x < xCount; x++) { double middleX = (xBoundaries.getDouble(x) + xBoundaries.getDouble(x + 1)) / 2; values[y * xCount + x] = function.getValue(middleX, middleY); } } ListDouble data = new ArrayDouble(values); return datasetFrom(data, xBoundaries, yBoundaries); } }
Cell2DDatasets { public static Cell2DDataset datasetFrom(final Function2D function, final ListNumber xBoundaries, final ListNumber yBoundaries) { int yCount = yBoundaries.size() - 1; int xCount = xBoundaries.size() - 1; double[] values = new double[yCount * xCount]; for (int y = 0; y < yCount; y++) { double middleY = (yBoundaries.getDouble(y) + yBoundaries.getDouble(y + 1)) / 2; for (int x = 0; x < xCount; x++) { double middleX = (xBoundaries.getDouble(x) + xBoundaries.getDouble(x + 1)) / 2; values[y * xCount + x] = function.getValue(middleX, middleY); } } ListDouble data = new ArrayDouble(values); return datasetFrom(data, xBoundaries, yBoundaries); }  }
Cell2DDatasets { public static Cell2DDataset datasetFrom(final Function2D function, final ListNumber xBoundaries, final ListNumber yBoundaries) { int yCount = yBoundaries.size() - 1; int xCount = xBoundaries.size() - 1; double[] values = new double[yCount * xCount]; for (int y = 0; y < yCount; y++) { double middleY = (yBoundaries.getDouble(y) + yBoundaries.getDouble(y + 1)) / 2; for (int x = 0; x < xCount; x++) { double middleX = (xBoundaries.getDouble(x) + xBoundaries.getDouble(x + 1)) / 2; values[y * xCount + x] = function.getValue(middleX, middleY); } } ListDouble data = new ArrayDouble(values); return datasetFrom(data, xBoundaries, yBoundaries); }  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 datasetFrom(final Function2D function, final ListNumber xBoundaries, final ListNumber yBoundaries) { int yCount = yBoundaries.size() - 1; int xCount = xBoundaries.size() - 1; double[] values = new double[yCount * xCount]; for (int y = 0; y < yCount; y++) { double middleY = (yBoundaries.getDouble(y) + yBoundaries.getDouble(y + 1)) / 2; for (int x = 0; x < xCount; x++) { double middleX = (xBoundaries.getDouble(x) + xBoundaries.getDouble(x + 1)) / 2; values[y * xCount + x] = function.getValue(middleX, middleY); } } ListDouble data = new ArrayDouble(values); return datasetFrom(data, xBoundaries, yBoundaries); }  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);  }