mirror of
https://github.com/wassname/rl_2d_walker.js.git
synced 2026-09-09 11:33:20 +08:00
fixes to make it train
This commit is contained in:
+3
-2
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user