@Test public void testStats() { Dataset a = DatasetFactory.createRange(12, Dataset.FLOAT64); assertEquals(11., a.max().doubleValue(), 1e-6); assertEquals(0., a.min().doubleValue(), 1e-6); assertEquals(5.5, ((Number) a.mean()).doubleValue(), 1e-6); assertEquals(3.6055512754639891, a.stdDeviation().doubleValue(), 1e-6); assertEquals(13., a.variance().doubleValue(), 1e-6); a.setShape(3, 1, 4); Dataset b = a.sum(0); assertEquals(2, b.getRank()); assertArrayEquals(new int[] {1, 4}, b.getShape()); assertEquals(12., b.getDouble(0, 0), 1e-6); assertEquals(15., b.getDouble(0, 1), 1e-6); assertEquals(18., b.getDouble(0, 2), 1e-6); assertEquals(21., b.getDouble(0, 3), 1e-6); b = a.sum(1); assertEquals(2, b.getRank()); assertArrayEquals(new int[] {3, 4}, b.getShape()); assertEquals(a.squeeze(), b); a.setShape(3, 1, 4); b = a.sum(2); assertEquals(2, b.getRank()); assertArrayEquals(new int[] {3, 1}, b.getShape()); assertEquals(6., b.getDouble(0), 1e-6); assertEquals(22., b.getDouble(1), 1e-6); assertEquals(38., b.getDouble(2), 1e-6); }
@Test public void testPosition() { double[] da = {0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1}; DoubleDataset a = new DoubleDataset(da); assertEquals(6, a.maxPos()[0]); assertEquals(0, a.minPos()[0]); Dataset b = DatasetFactory.zeros(new int[] {100, 200}, Dataset.FLOAT64); b.set(100.00, new int[] {50, 100}); b.set(-100.00, new int[] {51, 101}); assertEquals(50, b.maxPos()[0]); assertEquals(100, b.maxPos()[1]); assertEquals(51, b.minPos()[0]); assertEquals(101, b.minPos()[1]); b.set(Double.NaN, new int[] {52, 53}); assertEquals(52, b.maxPos()[0]); assertEquals(53, b.maxPos()[1]); assertEquals(50, b.maxPos(true)[0]); assertEquals(100, b.maxPos(true)[1]); Dataset c = DatasetFactory.zeros(new int[] {100, 200}, Dataset.FLOAT64); c.set(100.00, new int[] {99, 50}); c.set(99.99, new int[] {50, 50}); assertEquals(99, c.maxPos()[0]); assertEquals(50, c.maxPos()[1]); c.set(101, new int[] {0, 0}); assertEquals(0, c.maxPos()[0]); assertEquals(0, c.maxPos()[1]); }