brain.js correct training of the neuralNetwork

百般思念 提交于 2019-12-21 20:54:11

问题


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?


回答1:


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 }



来源:https://stackoverflow.com/questions/50894323/brain-js-correct-training-of-the-neuralnetwork

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!