* Constructor of SnakeGameAgent. * * @param {SnakeGame} game A game object. * @param {object} config The configuration object with the following keys: * - `replayBufferSize` {number} Size of the replay memory. Must be a * positive integer. * - `epsilonInit` {number} Initial
(game, config)
| 40 | * - `learningRate` {number} The learning rate to use during training. |
| 41 | */ |
| 42 | constructor(game, config) { |
| 43 | assertPositiveInteger(config.epsilonDecayFrames); |
| 44 | |
| 45 | this.game = game; |
| 46 | |
| 47 | this.epsilonInit = config.epsilonInit; |
| 48 | this.epsilonFinal = config.epsilonFinal; |
| 49 | this.epsilonDecayFrames = config.epsilonDecayFrames; |
| 50 | this.epsilonIncrement_ = (this.epsilonFinal - this.epsilonInit) / |
| 51 | this.epsilonDecayFrames; |
| 52 | |
| 53 | this.onlineNetwork = |
| 54 | createDeepQNetwork(game.height, game.width, NUM_ACTIONS); |
| 55 | this.targetNetwork = |
| 56 | createDeepQNetwork(game.height, game.width, NUM_ACTIONS); |
| 57 | // Freeze taget network: it's weights are updated only through copying from |
| 58 | // the online network. |
| 59 | this.targetNetwork.trainable = false; |
| 60 | |
| 61 | this.optimizer = tf.train.adam(config.learningRate); |
| 62 | |
| 63 | this.replayBufferSize = config.replayBufferSize; |
| 64 | this.replayMemory = new ReplayMemory(config.replayBufferSize); |
| 65 | this.frameCount = 0; |
| 66 | this.reset(); |
| 67 | } |
| 68 | |
| 69 | reset() { |
| 70 | this.cumulativeReward_ = 0; |
nothing calls this directly
no test coverage detected