@Test public void tsGeneratorTest() throws InvalidKerasConfigurationException { INDArray data = Nd4j.create(50, 10); INDArray targets = Nd4j.create(50, 10); int length = 10; int samplingRate = 2; int stride = 1; int startIndex = 0; int endIndex = 49; int batchSize = 1; boolean shuffle = false; boolean reverse = false; TimeSeriesGenerator gen = new TimeSeriesGenerator(data, targets, length, samplingRate, stride, startIndex, endIndex, shuffle, reverse, batchSize); assertEquals(length, gen.getLength()); assertEquals(startIndex + length, gen.getStartIndex()); assertEquals(reverse, gen.isReverse()); assertEquals(shuffle, gen.isShuffle()); assertEquals(endIndex, gen.getEndIndex()); assertEquals(batchSize, gen.getBatchSize()); assertEquals(samplingRate, gen.getSamplingRate()); assertEquals(stride, gen.getStride()); Pair<INDArray, INDArray> next = gen.next(0); }
public Pair<INDArray, INDArray> next(int index) { INDArray rows; if (shuffle) { rows = Nd4j.getRandom().nextInt(endIndex, new int[] {batchSize}); rows.addi(startIndex); } else { int i = startIndex + batchSize + stride * index; rows = Nd4j.arange(i, Math.min(i + batchSize * stride, endIndex + 1)); } INDArray samples = Nd4j.create(rows.length(), length / samplingRate, data.columns()); INDArray targets = Nd4j.create(rows.length(), this.targets.columns()); for (int j = 0; j < rows.rows(); j++) { long idx = (long) rows.getDouble(j); INDArrayIndex indices = NDArrayIndex.interval(idx - this.length, this.samplingRate, idx); samples.putSlice(j, this.data.get(indices)); INDArrayIndex point = NDArrayIndex.point((long) rows.getDouble(j)); targets.putSlice(j, this.targets.get(point)); } if (reverse) samples = Nd4j.reverse(samples); return new Pair<>(samples, targets); }
TimeSeriesGenerator { public Pair<INDArray, INDArray> next(int index) { INDArray rows; if (shuffle) { rows = Nd4j.getRandom().nextInt(endIndex, new int[] {batchSize}); rows.addi(startIndex); } else { int i = startIndex + batchSize + stride * index; rows = Nd4j.arange(i, Math.min(i + batchSize * stride, endIndex + 1)); } INDArray samples = Nd4j.create(rows.length(), length / samplingRate, data.columns()); INDArray targets = Nd4j.create(rows.length(), this.targets.columns()); for (int j = 0; j < rows.rows(); j++) { long idx = (long) rows.getDouble(j); INDArrayIndex indices = NDArrayIndex.interval(idx - this.length, this.samplingRate, idx); samples.putSlice(j, this.data.get(indices)); INDArrayIndex point = NDArrayIndex.point((long) rows.getDouble(j)); targets.putSlice(j, this.targets.get(point)); } if (reverse) samples = Nd4j.reverse(samples); return new Pair<>(samples, targets); } }
TimeSeriesGenerator { public Pair<INDArray, INDArray> next(int index) { INDArray rows; if (shuffle) { rows = Nd4j.getRandom().nextInt(endIndex, new int[] {batchSize}); rows.addi(startIndex); } else { int i = startIndex + batchSize + stride * index; rows = Nd4j.arange(i, Math.min(i + batchSize * stride, endIndex + 1)); } INDArray samples = Nd4j.create(rows.length(), length / samplingRate, data.columns()); INDArray targets = Nd4j.create(rows.length(), this.targets.columns()); for (int j = 0; j < rows.rows(); j++) { long idx = (long) rows.getDouble(j); INDArrayIndex indices = NDArrayIndex.interval(idx - this.length, this.samplingRate, idx); samples.putSlice(j, this.data.get(indices)); INDArrayIndex point = NDArrayIndex.point((long) rows.getDouble(j)); targets.putSlice(j, this.targets.get(point)); } if (reverse) samples = Nd4j.reverse(samples); return new Pair<>(samples, targets); } TimeSeriesGenerator(INDArray data, INDArray targets, int length, int samplingRate, int stride,
                               Integer startIndex, Integer endIndex, boolean shuffle, boolean reverse,
                               int batchSize);  TimeSeriesGenerator(INDArray data, INDArray targets, int length); }
TimeSeriesGenerator { public Pair<INDArray, INDArray> next(int index) { INDArray rows; if (shuffle) { rows = Nd4j.getRandom().nextInt(endIndex, new int[] {batchSize}); rows.addi(startIndex); } else { int i = startIndex + batchSize + stride * index; rows = Nd4j.arange(i, Math.min(i + batchSize * stride, endIndex + 1)); } INDArray samples = Nd4j.create(rows.length(), length / samplingRate, data.columns()); INDArray targets = Nd4j.create(rows.length(), this.targets.columns()); for (int j = 0; j < rows.rows(); j++) { long idx = (long) rows.getDouble(j); INDArrayIndex indices = NDArrayIndex.interval(idx - this.length, this.samplingRate, idx); samples.putSlice(j, this.data.get(indices)); INDArrayIndex point = NDArrayIndex.point((long) rows.getDouble(j)); targets.putSlice(j, this.targets.get(point)); } if (reverse) samples = Nd4j.reverse(samples); return new Pair<>(samples, targets); } TimeSeriesGenerator(INDArray data, INDArray targets, int length, int samplingRate, int stride,
                               Integer startIndex, Integer endIndex, boolean shuffle, boolean reverse,
                               int batchSize);  TimeSeriesGenerator(INDArray data, INDArray targets, int length); static TimeSeriesGenerator fromJson(String jsonFileName); int length(); Pair<INDArray, INDArray> next(int index); }
TimeSeriesGenerator { public Pair<INDArray, INDArray> next(int index) { INDArray rows; if (shuffle) { rows = Nd4j.getRandom().nextInt(endIndex, new int[] {batchSize}); rows.addi(startIndex); } else { int i = startIndex + batchSize + stride * index; rows = Nd4j.arange(i, Math.min(i + batchSize * stride, endIndex + 1)); } INDArray samples = Nd4j.create(rows.length(), length / samplingRate, data.columns()); INDArray targets = Nd4j.create(rows.length(), this.targets.columns()); for (int j = 0; j < rows.rows(); j++) { long idx = (long) rows.getDouble(j); INDArrayIndex indices = NDArrayIndex.interval(idx - this.length, this.samplingRate, idx); samples.putSlice(j, this.data.get(indices)); INDArrayIndex point = NDArrayIndex.point((long) rows.getDouble(j)); targets.putSlice(j, this.targets.get(point)); } if (reverse) samples = Nd4j.reverse(samples); return new Pair<>(samples, targets); } TimeSeriesGenerator(INDArray data, INDArray targets, int length, int samplingRate, int stride,
                               Integer startIndex, Integer endIndex, boolean shuffle, boolean reverse,
                               int batchSize);  TimeSeriesGenerator(INDArray data, INDArray targets, int length); static TimeSeriesGenerator fromJson(String jsonFileName); int length(); Pair<INDArray, INDArray> next(int index);  }