fixes to make it train

This commit is contained in:
wassname
2018-12-01 17:40:44 +08:00
parent d296c91508
commit a7df66c034
2 changed files with 6 additions and 5 deletions
+3 -2
View File
@@ -1,5 +1,5 @@
const { tf } = require('./tf_import')
const {copyModel, Actor, Critic, assignAndStd } = require('./models')
const { copyModel, Actor, Critic, assignAndStd, targetUpdate } = require('./models')
function logTfMemory(){
let mem = tf.memory();
@@ -210,7 +210,8 @@ class DDPG {
getTfBatch(){
// Get batch
const batch = this.memory.popBatch(this.config.batchSize);
// Convert to tensors
// Convert to tensors
const tfActions = tf.tensor2d(batch.actions);
const tfObs0 = tf.tensor2d(batch.obs0);
const tfObs1 = tf.tensor2d(batch.obs1);
+3 -3
View File
@@ -141,8 +141,8 @@ class DDPGAgent {
// Get actions
const tfActions = this.ddpg.perturbedPrediction(tfPreviousStep);
// Step in the environment with theses actions
let mAcions = tfActions.buffer().values;
let [mState, mReward, mDone, info] = this.env.step(mAcions);
let mActions = Array.from(tfActions.buffer().values);
let [mState, mReward, mDone, info] = this.env.step(mActions);
this.rewardsList.push(mReward);
// Get the new observations
let tfState = tf.tensor2d([mState]);
@@ -150,7 +150,7 @@ class DDPGAgent {
mDone = 1;
}
// Add the new tuple to the buffer
this.ddpg.memory.append(mPreviousStep, mAcions, mReward, mState, mDone);
this.ddpg.memory.append(mPreviousStep, mActions, mReward, mState, mDone);
// Dispose tensors
tfPreviousStep.dispose();
tfActions.dispose();