简体   繁体   English

Brain.js 示例

[英]Brain.js example

I decided to get known with a neural network in js.我决定通过 js 中的神经网络来了解。 I took brain.js library as an example.我以brain.js 库为例。 This is taken from their GitHub page.这是从他们的 GitHub 页面中获取的。 I can understand what that we have two input neurons 1 and 0. do I get also two output 1and 0?我可以理解我们有两个输入神经元 1 和 0。我是否也会得到两个输出 1 和 0? I read about the weights, where are they here and i don't really understand what are they?我读到了重量,它们在哪里,我真的不明白它们是什么? In output what do we pass?在输出中我们传递了什么?

var net = new brain.NeuralNetwork();

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

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

This is a simple neural network that approximates the XOR logic operator.这是一个近似 XOR 逻辑运算符的简单神经网络。 The result of the network will be in range from 0 to 1.网络的结果将在 0 到 1 的范围内。

The result will (mathematically) approach 1 the larger the training set gets.训练集越大,结果将(数学上)接近 1。 Because this is a simple example the value predicted is close enough.因为这是一个简单的例子,所以预测的值足够接近。

Usually, one will use a threshold/stepping function like the sigmoid function, to transform the output from linearly separable to approximately binary.通常,人们会使用像 sigmoid 函数这样的阈值/步进函数,将输出从线性可分转换为近似二进制。

Here's a possible, simple NN for XOR approximation:这是一个用于 XOR 近似的可能的简单 NN: 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM