()
| 23 | |
| 24 | |
| 25 | def get_batch(): |
| 26 | global BATCH_START, TIME_STEPS |
| 27 | # xs shape (50batch, 20steps) |
| 28 | xs = np.arange(BATCH_START, BATCH_START+TIME_STEPS*BATCH_SIZE).reshape((BATCH_SIZE, TIME_STEPS)) / (10*np.pi) |
| 29 | seq = np.sin(xs) |
| 30 | res = np.cos(xs) |
| 31 | BATCH_START += TIME_STEPS |
| 32 | # plt.plot(xs[0, :], res[0, :], 'r', xs[0, :], seq[0, :], 'b--') |
| 33 | # plt.show() |
| 34 | # returned seq, res and xs: shape (batch, step, input) |
| 35 | return [seq[:, :, np.newaxis], res[:, :, np.newaxis], xs] |
| 36 | |
| 37 | |
| 38 | class LSTMRNN(object): |