4

I must clearly have misunderstood something in the brain.js instructions on training

I played around with this repl.it code

const brain = require('brain.js');

const network = new brain.NeuralNetwork();

network.train([
    { input: { doseA: 0 }, output: { indicatorA: 0 } },
    { input: { doseA: 0.1 }, output: { indicatorA: 0.02 } },
    { input: { doseA: 0.2 }, output: { indicatorA: 0.04 } },
    { input: { doseA: 0.3 }, output: { indicatorA: 0.06 } },
    { input: { doseA: 0.4 }, output: { indicatorA: 0.08 } },
    { input: { doseA: 0.5 }, output: { indicatorA: 0.10 } },
    { input: { doseA: 0.6 }, output: { indicatorA: 0.12 } },
    { input: { doseA: 0.7 }, output: { indicatorA: 0.14 } },
]);

const result = network.run({ doseA: 0.35 });

console.log(result);

>> { indicatorA: 0.12165333330631256 }
    => undefined

was expecting the results to be { indicatorA: 0.07 }

What am I doing wrong?

Norfeldt
  • 8,272
  • 23
  • 96
  • 152

1 Answers1

4

Increasing the number of iterations and decreasing the error threshold worked for me:

const brain = require('brain.js');

const network = new brain.NeuralNetwork();

network.train([
    { input: { doseA: 0 }, output: { indicatorA: 0 } },
    { input: { doseA: 0.1 }, output: { indicatorA: 0.02 } },
    { input: { doseA: 0.2 }, output: { indicatorA: 0.04 } },
    { input: { doseA: 0.3 }, output: { indicatorA: 0.06 } },
    { input: { doseA: 0.4 }, output: { indicatorA: 0.08 } },
    { input: { doseA: 0.5 }, output: { indicatorA: 0.10 } },
    { input: { doseA: 0.6 }, output: { indicatorA: 0.12 } },
    { input: { doseA: 0.7 }, output: { indicatorA: 0.14 } },
], {
  log: true,
  iterations: 1e6,
  errorThresh: 0.00001
});

const result = network.run({ doseA: 0.35 });

console.log(result);
// 

Result : { indicatorA: 0.0693388432264328 }

xrisk
  • 3,790
  • 22
  • 45
  • Is there a good rule of thumb on how to determine if more training is needed or adjustment to `iterations` or `errorTresh`? – Norfeldt Jun 18 '18 at 07:01
  • More data can help @Norfeldt. – Robert Plummer Jun 20 '18 at 01:47
  • More data is always better @robertplummer ;-) but is it better to provide more of the same data (so fx two dose 0.5) or new data (dose 0.8)? – Norfeldt Jun 20 '18 at 08:33
  • I am not sure how the error threshold is computed in brain.js. It is not well documented and I don't feel like reading through the documentation, but really even 100 iterations should produce a better result than what brain.js initially produces. – xrisk Jun 20 '18 at 14:54