Used to shuffle the dataset at each iteration.
(n, minibatch_size, shuffle=False)
| 28 | |
| 29 | |
| 30 | def get_minibatches_idx(n, minibatch_size, shuffle=False): |
| 31 | """ |
| 32 | Used to shuffle the dataset at each iteration. |
| 33 | """ |
| 34 | |
| 35 | idx_list = numpy.arange(n, dtype="int32") |
| 36 | |
| 37 | if shuffle: |
| 38 | numpy.random.shuffle(idx_list) |
| 39 | |
| 40 | minibatches = [] |
| 41 | minibatch_start = 0 |
| 42 | for i in range(n // minibatch_size): |
| 43 | minibatches.append(idx_list[minibatch_start: |
| 44 | minibatch_start + minibatch_size]) |
| 45 | minibatch_start += minibatch_size |
| 46 | |
| 47 | if (minibatch_start != n): |
| 48 | # Make a minibatch out of what is left |
| 49 | minibatches.append(idx_list[minibatch_start:]) |
| 50 | |
| 51 | return zip(range(len(minibatches)), minibatches) |
| 52 | |
| 53 | |
| 54 | def get_dataset(name): |