private void nextFold() { int left; int right; if (kCursor == k - 1) { left = totalExamples() - lastBatch; right = totalExamples(); } else { left = kCursor * batch; right = left + batch; } List<DataSet> kMinusOneFoldList = new ArrayList<DataSet>(); if (right < totalExamples()) { if (left > 0) { kMinusOneFoldList.add((DataSet) singleFold.getRange(0, left)); } kMinusOneFoldList.add((DataSet) singleFold.getRange(right, totalExamples())); train = DataSet.merge(kMinusOneFoldList); } else { train = (DataSet) singleFold.getRange(0, left); } test = (DataSet) singleFold.getRange(left, right); kCursor++; }
@Override public DataSet next() { int last = Math.min(numExamples(), cursor() + batch()); DataSet next = (DataSet) data.getRange(cursor, last); if (preProcessor != null) preProcessor.preProcess(next); cursor += batch(); return next; } }
private void nextFold() { int left; int right; if (kCursor == k - 1) { left = totalExamples() - lastBatch; right = totalExamples(); } else { left = kCursor * batch; right = left + batch; } List<DataSet> kMinusOneFoldList = new ArrayList<DataSet>(); if (right < totalExamples()) { if (left > 0) { kMinusOneFoldList.add((DataSet) singleFold.getRange(0, left)); } kMinusOneFoldList.add((DataSet) singleFold.getRange(right, totalExamples())); train = DataSet.merge(kMinusOneFoldList); } else { train = (DataSet) singleFold.getRange(0, left); } test = (DataSet) singleFold.getRange(left, right); kCursor++; }
/** * Returns a batch of the given size * * @param num the size of the batch to return * @return a mini-batch of the given size */ @Override public DataSet next(int num) { // Apply preprocessor if (preProcessor != null) preProcessor.preProcess(data); // Special case: getRange() does not work as expected if there is just a single example if ((cursor == 0) && (num == 1) && (data.numExamples() == 1)) { return data; } DataSet thisBatch = (DataSet) data.getRange(cursor, cursor + num); cursor += num; return thisBatch; }
/** * Returns the next mini batch of data. * * @return the dataset corresponding to the mini batch */ @Override public DataSet next() { // Apply preprocessor if (preProcessor != null) { preProcessor.preProcess(data); } // Special case: getRange() does not work as expected if there is just a single example if ((cursor == 0) && (batchSize == 1) && (data.numExamples() == 1)) { cursor += batchSize; return data; } DataSet thisBatch = (DataSet) data.getRange(cursor, cursor + batchSize); cursor += batchSize; return thisBatch; }
@Override public DataSet next() { //only loop to the end if (cursor + batch() > numExamples()) cursor = cursor() + batch() - numExamples(); DataSet next = (DataSet) data.getRange(cursor, cursor + batch()); if (preProcessor != null) preProcessor.preProcess(next); cursor += batch(); return next; } }