Skip to content

Commit

Permalink
UI and controls updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nenadV91 committed May 12, 2019
1 parent b9d379f commit 7763181
Show file tree
Hide file tree
Showing 13 changed files with 648 additions and 60 deletions.
239 changes: 227 additions & 12 deletions data/brain.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,17 @@



{ "layers": [{ "opts": { "inodes": 6, "onodes": 9, "lr": 0.01 }, "inodes": 6, "onodes": 9, "activationType": "sigmoid", "lr": 0.01, "weights": { "rows": 9, "cols": 6, "data": [
{
"layers": [{
"opts": { "inodes": 6, "onodes": 9, "lr": 0.01 },
"inodes": 6,
"onodes": 9,
"activationType": "sigmoid",
"lr": 0.01,
"weights": {
"rows": 9,
"cols": 6,
"data": [
[-0.4914678432308625, -0.05337960543497511, 0.32667009569589156, -0.5169921236045721, -
0.46960175878520366, 0.11589311847419936
],
Expand Down Expand Up @@ -240,7 +250,12 @@
[0.5321377434327402, -0.4099429502607248, 0.027354688502304728, -2.7651266504792607, 0.3878097149145292,
1.9048106670025948
]
] }, "bias": { "rows": 9, "cols": 1, "data": [
]
},
"bias": {
"rows": 9,
"cols": 1,
"data": [
[-0.722],
[-0.712],
[0.632],
Expand All @@ -250,14 +265,25 @@
[-0.357],
[0.099],
[0.727]
] }, "activation": { "type": "sigmoid", "useX": false }, "input": { "rows": 6, "cols": 1, "data": [
]
},
"activation": { "type": "sigmoid", "useX": false },
"input": {
"rows": 6,
"cols": 1,
"data": [
[0.5750000000000405],
[0.18451136385322073],
[0.5509295817894064],
[0.5625214499618412],
[0.24156880283818058],
[0.4210339452494276]
] }, "output": { "rows": 9, "cols": 1, "data": [
]
},
"output": {
"rows": 9,
"cols": 1,
"data": [
[0.23327033022890367],
[0.08886900860021339],
[0.37256178944567847],
Expand All @@ -267,7 +293,17 @@
[0.3311017493341147],
[0.5284538585902532],
[0.5775295734734875]
] } }, { "opts": { "onodes": 6, "lr": 0.01 }, "onodes": 6, "activationType": "sigmoid", "lr": 0.01, "weights": { "rows": 6, "cols": 9, "data": [
]
}
}, {
"opts": { "onodes": 6, "lr": 0.01 },
"onodes": 6,
"activationType": "sigmoid",
"lr": 0.01,
"weights": {
"rows": 6,
"cols": 9,
"data": [
[1.27757121003574, 2.448522786913634, -1.4878762433861683, 0.9506723851607275, -0.3125191499242206,
0.636892119690058, -1.0670799235225217, -3.992942140390897, 0.3798277218568325
],
Expand All @@ -286,14 +322,25 @@
[-0.5095634305149325, 1.4433223236722121, 0.8598339258586543, 0.35235588897908376, 3.1784698231350363, -
2.3258853346788704, -0.3401879186860945, 0.642785253307818, -1.2241800294560472
]
] }, "bias": { "rows": 6, "cols": 1, "data": [
]
},
"bias": {
"rows": 6,
"cols": 1,
"data": [
[-0.006],
[-0.884],
[-0.621],
[0.772],
[0.188],
[0.72]
] }, "activation": { "type": "sigmoid", "useX": false }, "input": { "rows": 9, "cols": 1, "data": [
]
},
"activation": { "type": "sigmoid", "useX": false },
"input": {
"rows": 9,
"cols": 1,
"data": [
[0.23327033022890367],
[0.08886900860021339],
[0.37256178944567847],
Expand All @@ -303,14 +350,29 @@
[0.3311017493341147],
[0.5284538585902532],
[0.5775295734734875]
] }, "output": { "rows": 6, "cols": 1, "data": [
]
},
"output": {
"rows": 6,
"cols": 1,
"data": [
[0.1812468407729786],
[0.6490191237629044],
[0.2916642692138813],
[0.028266956700006562],
[0.10598957393416694],
[0.8544380670487771]
] } }, { "opts": { "onodes": 4 }, "onodes": 4, "activationType": "sigmoid", "lr": 0.1, "weights": { "rows": 4, "cols": 6, "data": [
]
}
}, {
"opts": { "onodes": 4 },
"onodes": 4,
"activationType": "sigmoid",
"lr": 0.1,
"weights": {
"rows": 4,
"cols": 6,
"data": [
[2.923514451186335, -0.41089811918567043, -0.6658918365006388, -0.876932932789507, 1.153899014020341, -
0.0769199830982282
],
Expand All @@ -323,21 +385,174 @@
[-0.602524262237335, -1.2038777105110696, 0.31398711958695225, 0.04938466132884617, -0.5011469904790768,
0.6091053465063022
]
] }, "bias": { "rows": 4, "cols": 1, "data": [
]
},
"bias": {
"rows": 4,
"cols": 1,
"data": [
[0.476],
[-0.324],
[0.84],
[0.225]
] }, "activation": { "type": "sigmoid", "useX": false }, "input": { "rows": 6, "cols": 1, "data": [
]
},
"activation": { "type": "sigmoid", "useX": false },
"input": {
"rows": 6,
"cols": 1,
"data": [
[0.1812468407729786],
[0.6490191237629044],
[0.2916642692138813],
[0.028266956700006562],
[0.10598957393416694],
[0.8544380670487771]
] }, "output": { "rows": 4, "cols": 1, "data": [
]
},
"output": {
"rows": 4,
"cols": 1,
"data": [
[0.6403238090716709],
[0.47854008760719763],
[0.48697457704525965],
[0.4737132441175516]
]
}
}]
}





{ "layers": [{ "opts": { "inodes": 6, "onodes": 9, "lr": 0.01 }, "inodes": 6, "onodes": 9, "activationType": "sigmoid", "lr": 0.01, "weights": { "rows": 9, "cols": 6, "data": [
[-4.13691613847899, 0.1310857917982513, 3.95597619573589, -5.354211089199022, 10.229178798750139,
1.8404585494992995
],
[1.5322802567102265, 2.9617644564954766, -3.012357499416194, -0.09457864139300215, 2.026034368614857, -
5.753149456527421
],
[-2.7399913622184737, -2.463739901845141, -5.354676086855546, 0.53721740274266, -0.7371511178662296, -
3.534924102115844
],
[-2.367129001429773, -0.6838058382560324, -2.2383999044299148, -3.3768744777320245, 5.32915609657993, -
4.8651174094465475
],
[-3.363985752814462, -1.0308198475571926, 5.593805182147417, 4.553997573107264, -3.6375350969196614, -
5.035319916916141
],
[6.17941339270397, 6.464354834415698, 2.2178844052843347, -2.4945328715488992, 6.902657758626628,
6.202809651093145
],
[-8.193754369470724, 2.1505193069201756, -1.1729428590087978, 3.9260396821859858, 2.311572174532499,
5.659076852057311
],
[-3.071332169940964, -2.0521696382896453, -1.5855776971797457, 4.697158556503691, -1.883428498190033, -
2.1994487670744256
],
[-1.81047434654265, -4.144502535517326, -0.25599709542311033, -3.2467709287632553, -0.44809779446247194,
1.3031179426501016
]
] }, "bias": { "rows": 9, "cols": 1, "data": [
[-0.584],
[-0.2],
[0.154],
[-0.157],
[-0.253],
[0.001],
[-0.859],
[-0.425],
[-0.614]
] }, "activation": { "type": "sigmoid", "useX": false }, "input": { "rows": 6, "cols": 1, "data": [
[0.5607142857144501],
[0.7751929996198138],
[0.5092958178940651],
[0.6088634587726315],
[1],
[0.4518696424716322]
] }, "output": { "rows": 9, "cols": 1, "data": [
[0.9991012384259862],
[0.6877679265034159],
[0.00032650970456758846],
[0.11108850011421012],
[0.03807061910634438],
[0.9999999812721941],
[0.9466217785470842],
[0.010324474735186256],
[0.001103212625277584]
] } }, { "opts": { "onodes": 6, "lr": 0.01 }, "onodes": 6, "activationType": "sigmoid", "lr": 0.01, "weights": { "rows": 6, "cols": 9, "data": [
[1.112885287001739, -3.802243699185878, 4.420518160181297, 1.3662220817032384, 1.1762819385411416, -
3.2273006021373076, 0.3205163930941381, -3.1153389648192595, -1.4260454566547434
],
[1.5630553284572128, -5.067481745957144, 1.3729316145609078, -1.4167302688757204, 1.3611535114590967, -
7.957693965972461, -0.08357909124785134, -0.7325667758826923, 8.092073641337349
],
[-3.6894627019291013, 6.64998355440773, 4.6077488327267, 4.366237265937179, 0.5373562531491309, -
1.397931414938265, 5.971842724698734, -1.1419127228604806, 6.2361618618239625
],
[0.030200440931301253, -5.280988822001069, 2.658366258101526, 0.752068069988004, -5.515817678720758, -
0.329493772538824, 4.6327164825033895, -3.2421593818426055, -2.152878153536186
],
[1.7829707781715913, 0.593555747681572, 3.8758230694355356, 1.1520795156339645, 1.428937172378192,
3.827224101464894, -5.110571155975919, -8.349297653362452, -2.0018237906706893
],
[-2.777669000459493, -2.3913815481560445, 3.0656443689508723, -4.251330704245818, -2.926174328228993,
1.7421804681121627, 0.41849738652035673, 1.2237537700886092, 0.8455985308602412
]
] }, "bias": { "rows": 6, "cols": 1, "data": [
[0.249],
[0.832],
[-0.628],
[0.456],
[-0.595],
[-0.48]
] }, "activation": { "type": "sigmoid", "useX": false }, "input": { "rows": 9, "cols": 1, "data": [
[0.9991012384259862],
[0.6877679265034159],
[0.00032650970456758846],
[0.11108850011421012],
[0.03807061910634438],
[0.9999999812721941],
[0.9466217785470842],
[0.010324474735186256],
[0.001103212625277584]
] }, "output": { "rows": 6, "cols": 1, "data": [
[0.017743909575341388],
[0.00009783182373374444],
[0.9934174876042169],
[0.678871377244049],
[0.6635782594659352],
[0.03453436281645951]
] } }, { "opts": { "onodes": 4 }, "onodes": 4, "activationType": "sigmoid", "lr": 0.1, "weights": { "rows": 4, "cols": 6, "data": [
[-1.12909645609938, 0.018583494722700156, 9.489550299114502, 5.564637888709152, -4.0748054876941,
3.6344649023513114
],
[1.0128271649717657, 5.315248291057755, -2.378669446119791, 4.128963302140043, 4.183284157092385, -
4.103515480036455
],
[4.2939378218362805, 0.6496885272153822, -0.5307042661521948, 5.555084819428852, -5.602860971501337,
1.1407754364902758
],
[2.759579235325642, 2.7160430133566447, 0.04912611033011585, 0.07548689283903859, 0.4048538718223371, -
6.346252037735628
]
] }, "bias": { "rows": 4, "cols": 1, "data": [
[-0.688],
[0.814],
[0.991],
[0.707]
] }, "activation": { "type": "sigmoid", "useX": false }, "input": { "rows": 6, "cols": 1, "data": [
[0.017743909575341388],
[0.00009783182373374444],
[0.9934174876042169],
[0.678871377244049],
[0.6635782594659352],
[0.03453436281645951]
] }, "output": { "rows": 4, "cols": 1, "data": [
[0.999950736971994],
[0.9802903187036666],
[0.6530994350402263],
[0.7121334922581989]
] } }] }
2 changes: 1 addition & 1 deletion data/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const config = {
carPointColor: 'rgb(67, 100, 221)',
red: 'rgb(255, 0, 0)',
green: 'rgb(50, 174, 73)',
checkpoints: true,
checkpoints: false,
currentCheckpoint: false,
visionLines: false,
visionPoints: false,
Expand Down
28 changes: 16 additions & 12 deletions genetic-algo/population.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
class Population {
constructor(Unit, total = 100, opts = {}) {
constructor(Unit, opts = {}) {
this.opts = opts;
this.generation = 1;
this.imortal = false;
this.Unit = Unit;
this.total = total;
this.total = opts.total || 100;
this.mutationRate = opts.mutationRate || 0.25;

this.generation = 1;
this.active = [];
this.saved = [];
this.pool = [];
this.score = 0;
this.mutationRate = opts.mutationRate;

this.create()
}
Expand Down Expand Up @@ -40,12 +40,6 @@ class Population {
this.saved.push(unit);
}

update() {
if(frameCount % 5 === 0) {
this.score += 1;
}
}

load(data) {
for(let i = this.active.length - 1; i >= 0; i--) {
const unit = this.active[i];
Expand All @@ -55,6 +49,15 @@ class Population {
}

reset() {
this.active = [];
this.saved = [];
this.pool = [];
this.generation = 1;
this.score = 0;
this.create();
}

update() {
this.calcFitness();
this.nextGeneration();

Expand Down Expand Up @@ -89,7 +92,8 @@ class Population {
this.pool = this.saved.slice(-5);

const total = this.pool.reduce((r, e) => {
return r + e.score
if(e) return r + e.score;
else return r;
}, 0);

this.pool.forEach(unit => {
Expand Down
Loading

0 comments on commit 7763181

Please sign in to comment.