@Test public void datasetFromListNumber() { ListNumber values = new ArrayDouble(5, 3, 7, -1, 2, 2); ListNumber xBoundaries = new ArrayDouble(-1, 0, 1); ListNumber yBoundaries = new ArrayDouble(0, 1, 2, 3); Cell2DDataset dataset = Cell2DDatasets.datasetFrom(values, xBoundaries, yBoundaries); assertThat(dataset.getXCount(), equalTo(2)); assertThat(dataset.getXRange().getMinimum(), equalTo(-1.0)); assertThat(dataset.getXRange().getMaximum(), equalTo(1.0)); assertThat(dataset.getYCount(), equalTo(3)); assertThat(dataset.getYRange().getMinimum(), equalTo(0.0)); assertThat(dataset.getYRange().getMaximum(), equalTo(3.0)); assertThat(dataset.getStatistics().getAverage(), equalTo(3.0)); assertThat(dataset.getStatistics().getStdDev(), closeTo(2.51661, 0.0001)); assertThat(dataset.getStatistics().getRange().getMinimum(), equalTo((Number) (-1.0))); assertThat(dataset.getStatistics().getRange().getMaximum(), equalTo((Number) 7.0)); assertThat(dataset.getStatistics().getCount(), equalTo(6)); assertThat(dataset.getXBoundaries().getDouble(0), equalTo(-1.0)); assertThat(dataset.getXBoundaries().getDouble(1), equalTo(0.0)); assertThat(dataset.getXBoundaries().getDouble(2), equalTo(1.0)); assertThat(dataset.getYBoundaries().getDouble(0), equalTo(0.0)); assertThat(dataset.getYBoundaries().getDouble(1), equalTo(1.0)); assertThat(dataset.getYBoundaries().getDouble(2), equalTo(2.0)); assertThat(dataset.getYBoundaries().getDouble(3), equalTo(3.0)); assertThat(dataset.getValue(0, 0), equalTo(5.0)); assertThat(dataset.getValue(1, 0), equalTo(3.0)); assertThat(dataset.getValue(0, 1), equalTo(7.0)); assertThat(dataset.getValue(1, 1), equalTo(-1.0)); assertThat(dataset.getValue(0, 2), equalTo(2.0)); assertThat(dataset.getValue(1, 2), equalTo(2.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);  }