Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function handleReset(Dinos) {
- // Checks if this is the first time it is called and set first time as false
- if (firstTime) {
- firstTime = false;
- // Initialize the random Model for each Dino.
- Dinos.forEach((dino) => {
- dino.model = new RandomModel();
- dino.model.init();
- });
- }
- else {
- /* If this is not the first time it is called, then we need to train
- our model to form next generation.*/
- // Train model before restarting
- console.info('Training');
- /* We create an array called chromosomes which uses the getChromosome
- function of the randomModel class which converts weights ans bias
- into an array of size 4 [w1,w2,w3,b1].so each element of chromosomes
- array is another array of size 4 */
- const chromosomes = rankList.map((dino) => dino.model.getChromosome());
- // console.info(chromosomes)
- // Clear rankList
- // We empty the ranklist so that we can store the next gen in it.
- rankList.splice(0);
- /* We call the fit function of the genetic model on chromosomes array
- which then calls our genetic operators and creates the new chromosomes
- array and sets them in the models of the dinos.
- */
- chromosomes = geneticModel.fit(chromosomes);
- Dinos.forEach((dino, i) => {
- dino.model.setChromosome(chromosomes[i]);
- });
- }
- }
Add Comment
Please, Sign In to add comment