Skip to content

Commit e4a6425

Browse files
authored
Merge pull request #3 from kaustubholpadkar/feature/generalize-model
change map after few successful rounds of map for model generalization
2 parents 30bf13d + fd07549 commit e4a6425

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

sketch.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ let inside = [];
2626
let outside = [];
2727
let checkpoints = [];
2828

29+
// around 5-6 successfully completed rounds will make the fitness of 500+
30+
// so maxFitness is set to 500
31+
// thus the changeMap will flag becomes true and we will create new map
32+
// when any of the particle completes multiple rounds in current map
33+
// this will help to make the current generation to work on new map
34+
// and generalize to variety of maps
35+
const maxFitness = 500;
36+
let changeMap = false;
37+
2938
function buildTrack() {
3039
checkpoints = [];
3140
inside = [];
@@ -104,6 +113,21 @@ function draw() {
104113
if (particle.dead || particle.finished) {
105114
savedParticles.push(population.splice(i, 1)[0]);
106115
}
116+
117+
if (!changeMap && particle.fitness > maxFitness) {
118+
changeMap = true;
119+
}
120+
}
121+
122+
if (population.length !== 0 && changeMap) {
123+
for (let i = population.length - 1; i >= 0; i--) {
124+
savedParticles.push(population.splice(i, 1)[0]);
125+
}
126+
127+
buildTrack();
128+
nextGeneration();
129+
generationCount++;
130+
changeMap=false;
107131
}
108132

109133
if (population.length == 0) {

0 commit comments

Comments
 (0)