| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
9年前发布

JavaScript神经网络:Brain

Brain 是一个 JavaScript 神经网络库。下面是一个用它来实现近似 XOR 功能的例子:

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]

There's no reason to use a neural network to figure out XOR however (-: so here's a more involved, realistic example: Demo: training a neural network to recognize color contrast

Using in node

If you have node you can install with npm:

npm install brain

Using in the browser

Download the latest brain.js. Training is computationally expensive, so you should try to train the network offline (or on a Worker) and use thetoFunction()ortoJSON()options to plug the pre-trained network in to your website.

Training

Usetrain()to train the network with an array of training data. The network has to be trained with all the data in bulk in one call totrain(). The more training patterns, the longer it will probably take to train, but the better the network will be at classifiying new patterns.

Data format

Each training pattern should have aninputand anoutput, both of which can be either an array of numbers from0to1or a hash of numbers from0to1. For the color constrast demo it looks something like this:

var net = new brain.NeuralNetwork();    net.train([{input: { r: 0.03, g: 0.7, b: 0.5 }, output: { black: 1 }},             {input: { r: 0.16, g: 0.09, b: 0.2 }, output: { white: 1 }},             {input: { r: 0.5, g: 0.5, b: 1.0 }, output: { white: 1 }}]);    var output = net.run({ r: 1, g: 0.4, b: 0 });  // { white: 0.99, black: 0.002 }

项目主页:http://www.open-open.com/lib/view/home/1436520926911

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1436520926911.html
Brain 神经网络