MCPcopy
hub / github.com/tensorflow/tfjs-examples / calcQValuesAndBestAction

Function calcQValuesAndBestAction

snake-dqn/index.js:93–103  ·  view source on GitHub ↗

Calculate the current Q-values and the best action.

()

Source from the content-addressed store, hash-verified

91
92/** Calculate the current Q-values and the best action. */
93async function calcQValuesAndBestAction() {
94 if (currentQValues != null) {
95 return;
96 }
97 tf.tidy(() => {
98 const stateTensor = getStateTensor(game.getState(), game.height, game.width);
99 const predictOut = qNet.predict(stateTensor);
100 currentQValues = predictOut.dataSync();
101 bestAction = ALL_ACTIONS[predictOut.argMax(-1).dataSync()[0]];
102 });
103}
104
105function invalidateQValuesAndBestAction() {
106 currentQValues = null;

Callers 2

resetFunction · 0.85
stepFunction · 0.85

Calls 3

getStateTensorFunction · 0.90
getStateMethod · 0.80
predictMethod · 0.45

Tested by

no test coverage detected