liquidcarrot / carrot

🥕 Evolutionary Neural Networks in JavaScript
https://liquidcarrot.io/carrot/
MIT License
295 stars 34 forks source link

Neat.prototype.evolve() breaking in Google Chrome console #193

Open luiscarbonell opened 4 years ago

luiscarbonell commented 4 years ago

Description

Trying to run Neat.prototype.evolve() to train an image grey-scaling network - it fails throwing the errors shown below.

My Code

let { Neat } = carrot;

function randomColor() {
  return [
    Math.random() * 255,  // red
    Math.random() * 255,  // green
    Math.random() * 255   // blue
  ];
}

function greyScale(color) {
    return [(color[0] + color[1] + color[2]) / 3]; // average "brightness"
}

let greyScaleData = Array.from({ length: 100 }, (_, i) => {
    let color = randomColor();
    let blackwhite = greyscale(color);

    return { inputs: color, outputs: blackwhite };
});

let greyScaleNetwork = new Neat(3,1,greyScaleData);

greyScaleNetwork.evolve(); 
// TypeError: Cannot read property '0' of undefined
//     at h.c.activate (<anonymous>:36:79239)
//     at <anonymous>:36:88410
//     at de (<anonymous>:36:6989)
//     at Function.hr.times (<anonymous>:36:64026)
//     at h.c.test (<anonymous>:36:88356)
//     at a.fitness (<anonymous>:47:14935)
//     at a.c.evaluate (<anonymous>:47:13886)
//     at a.c.evolve (<anonymous>:47:11780)
//     at <anonymous>:1:12

Screenshots

image

To Reproduce

Additional Information

The stack-trace is wrangled and very difficult to trace with the obfuscated variable names.