Created
October 17, 2020 20:35
-
-
Save MCarlomagno/9fe408389554dea36019947834706008 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var underscore = require('underscore'); | |
var replay = async function (batchSize, index) { | |
var minibatch = []; | |
if (index === subzeroIndex) { | |
minibatch = underscore.sample(subzeroMemory, batchSize); | |
} else { | |
minibatch = underscore.sample(kanoMemory, batchSize); | |
} | |
for (var i = 0; i < minibatch.length; i++) { | |
// deconstructs secuence | |
var { state, action, reward, nextState, done } = minibatch[i]; | |
// predicts action | |
var tensorState = stateToTensor(state, index); | |
target = model.predict(tensorState); | |
if (done) { | |
target.dataSync()[action] = reward; | |
} else { | |
var tensorNextState = stateToTensor(nextState, index); | |
t = targetModel.predict(tensorNextState).dataSync(); | |
target.dataSync()[action] = reward + gamma * Math.max(...t); | |
} | |
await model.fit(tensorState, target); | |
} | |
if (epsilon > epsilonMin) { | |
epsilon *= epsilonDecay; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment