Created
April 27, 2018 09:06
-
-
Save AlexandreSi/1069b476b55e8fe23ed1d783a7340c31 to your computer and use it in GitHub Desktop.
connect4ai - QLearning
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
| // @flow | |
| const NeuralNetwork = require('./NeuralNetwork'); | |
| exports.trainOnPreviousPlays = ( | |
| networkType: string, | |
| myNetwork: any, | |
| myTrainer: any, | |
| boards: Array<any>, | |
| plays: Array<number>, | |
| learningRate: number, | |
| reward: number, | |
| discount: number, | |
| gamma: number, | |
| ) => { | |
| const playsLength = plays.length; | |
| let previousQValue = NeuralNetwork.predict( | |
| networkType, | |
| myNetwork, | |
| boards[playsLength - 1], | |
| ); | |
| for (let playIndex = playsLength - 2; playIndex >= 0; playIndex--) { | |
| NeuralNetwork.backPropagate( | |
| networkType, | |
| myTrainer, | |
| boards[playIndex], | |
| discount ** (playsLength - playIndex - 1) * reward + gamma * Math.max(...previousQValue), | |
| plays[playIndex], | |
| learningRate | |
| ) | |
| previousQValue = NeuralNetwork.predict( | |
| networkType, | |
| myNetwork, | |
| boards[playIndex], | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment