在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:harthur/brain开源软件地址:https://github.com/harthur/brain开源编程语言:JavaScript 100.0%开源软件介绍:This project has reached the end of its development as a simple neural network library. Feel free to browse the code, but please use other JavaScript neural network libraries in development like brain.js and convnetjs. brain
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 nodeIf you have node you can install with npm:
Using in the browserDownload the latest brain.js. Training is computationally expensive, so you should try to train the network offline (or on a Worker) and use the TrainingUse Data formatEach training pattern should have an 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 } Options
net.train(data, {
errorThresh: 0.005, // error threshold to reach
iterations: 20000, // maximum training iterations
log: true, // console.log() progress periodically
logPeriod: 10, // number of iterations between logging
learningRate: 0.3 // learning rate
}) The network will train until the training error has gone below the threshold (default By default training won't let you know how its doing until the end, but set The learning rate is a parameter that influences how quickly the network trains. It's a number from OutputThe output of {
error: 0.0039139985510105032, // training error
iterations: 406 // training iterations
} FailingIf the network failed to train, the error will be above the error threshold. This could happen because the training data is too noisy (most likely), the network doesn't have enough hidden layers or nodes to handle the complexity of the data, or it hasn't trained for enough iterations. If the training error is still something huge like JSONSerialize or load in the state of a trained network with JSON: var json = net.toJSON();
net.fromJSON(json); You can also get a custom standalone function from a trained network that acts just like var run = net.toFunction();
var output = run({ r: 1, g: 0.4, b: 0 });
console.log(run.toString()); // copy and paste! no need to import brain.js Options
var net = new brain.NeuralNetwork({
hiddenLayers: [4],
learningRate: 0.6 // global learning rate, useful when training using streams
}); hiddenLayersSpecify the number of hidden layers in the network and the size of each layer. For example, if you want two hidden layers - the first with 3 nodes and the second with 4 nodes, you'd give:
By default StreamsThe network now has a WriteStream. You can train the network by using ExampleRefer to InitializationTo train the network using a stream you must first create the stream by calling
{
error: 0.0039139985510105032, // training error
iterations: 406 // training iterations
} TransformUse a Transform to coerce the data into the correct format. You might also use a Transform stream to normalize your data on the fly. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论