代码之家  ›  专栏  ›  技术社区  ›  Norfeldt

Brain.js神经网络的正确训练

  •  3
  • Norfeldt  · 技术社区  · 8 年前

    我一定是在 brain.js instructions on training

    我玩过这个 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
    

    希望结果是 { indicatorA: 0.07 }

    我做错什么了?

    1 回复  |  直到 8 年前
        1
  •  2
  •   xrisk    8 年前

    增加迭代次数并减少对我有效的错误阈值:

    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);
    // 
    

    结果: { indicatorA: 0.0693388432264328 }