【问题标题】:Run Brain JS in headless Node JS script在无头 Node JS 脚本中运行 Brain JS
【发布时间】:2019-11-23 00:03:05
【问题描述】:

我希望在无头 Node JS 脚本中运行 Brain JS,我尝试通过 NPM 通过我的 js/run.js 页面要求 Brain JS,但错误:net.train is not a function。

const net = require('brain.js')

net.train([
  { input: [0, 0], output: [0] },
  { input: [0, 1], output: [1] },
  { input: [1, 0], output: [1] },
  { input: [1, 1], output: [0] },
])

const output = net.run([1, 0]) // [0.987]

【问题讨论】:

    标签: javascript node.js shell brain.js


    【解决方案1】:

    你可以试试这个代码,它应该做你想做的事,使用 Brain.js 文档中的配置。

    const brain = require('brain.js')
    
    // provide optional config object, defaults shown. See brain.js docs for details.
    const config = {
      binaryThresh: 0.5,
      hiddenLayers: [3], // array of ints for the sizes of the hidden layers in the network
      activation: 'sigmoid', // supported activation types: ['sigmoid', 'relu', 'leaky-relu', 'tanh'],
      leakyReluAlpha: 0.01, // supported for activation type 'leaky-relu'
    }
    
    const net = new brain.NeuralNetwork(config);
    
    net.train([
     { input: [0, 0], output: [0] },
     { input: [0, 1], output: [1] },
     { input: [1, 0], output: [1] },
     { input: [1, 1], output: [0] },
    ])
    
    for(let input of [[0,0], [0,1], [1,0], [1,1]]) {
        console.log(`Input: [${input[0]},${input[1]}]: output: ${net.run(input)}`);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-27
      • 2018-08-04
      • 2021-06-03
      • 2023-02-18
      • 2020-10-24
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      相关资源
      最近更新 更多