clip_norm=5.0) buffer = ReplayBuffer(buffer_size=replay) with tf.Session() as sess: sess.run(model.tf_init()) losses = [] for epoch in range(1, NUM_EPOCHS + 1): batch_losses = 0.0 for bTrainX, bTrainY in batch_gen.load_train(): if buffer.size < buffer.max_size: buffer.add(state=bTrainX, action=bTrainY) continue else: buffer.add(state=bTrainX, action=bTrainY) state, reward, action = buffer.get_batch(bsz=BSZ) loss = model.optimize(sess, state, action) losses.append(loss) print("Epoch {} Average Train Loss: {}, validating...".format( epoch, np.mean(losses))) losses = [] allocation_wts = [] price_change_vec = [] for bEvalX, bEvalYFat in batch_gen.load_test(): bEvalY = bEvalYFat[:, -1, :] pred_allocations = model.predict_allocation(sess, bEvalX) assert bEvalY.shape == pred_allocations.shape price_change_vec.append(bEvalY) allocation_wts.append(pred_allocations)
asset_list=ASSETS, randomize_train=randomize_train, overlapping_train=overlapping_train) model = CNNModel(num_hid=NUM_HID, bptt=BPTT, num_assets=len(asset_list), lr=LR, clip_norm=5.0) with tf.Session() as sess: sess.run(model.tf_init()) losses = [] for epoch in range(1, NUM_EPOCHS + 1): for bTrainX, bTrainY in batch_gen.load_train(): loss = model.optimize(sess, bTrainX, bTrainY) losses.append(loss) print("Epoch {} Average Train Loss: {}, validating...".format( epoch, sum(losses) / len(losses))) losses = [] allocation_wts = [] price_change_vec = [] for bEvalX, bEvalYFat in batch_gen.load_test(): bEvalY = bEvalYFat[:, -1, :] pred_allocations = model.predict_allocation(sess, bEvalX) assert bEvalY.shape == pred_allocations.shape price_change_vec.append(bEvalY) allocation_wts.append(pred_allocations) true_change_vec = np.concatenate(price_change_vec)