-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrain.js
More file actions
51 lines (39 loc) · 1.13 KB
/
brain.js
File metadata and controls
51 lines (39 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// https://github.com/harthur/brain/
var _ = require('underscore');
var brain = require('brain')
, net = new brain.NeuralNetwork();
var dataset = []
_.each(_.range(300), function(item) {
var out = {};
out[ ((Math.random() > 0.5) ? 'black' : 'white') ] = Math.random();
inputVal = _.reduce(_.range(20), function(memo, num) {
var aaa = {};
aaa['a'+num] = Math.random();
return _.extend(memo, aaa);
}, {});
dataset.push({'input':inputVal, 'output':out});
});
console.log('~~~');
console.log(dataset);
console.log('~~~');
/*
Math.random()
[{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: 0.9 }}];
*/
net.train(dataset);
var output = net.run( _.reduce(_.range(20), function(memo, num) {
var aaa = {};
aaa['a'+num] = Math.random();
return _.extend(memo, aaa);
}, {}));
console.log(output);
console.log(
net.run(
_.reduce(_.range(20), function(memo, num) {
var aaa = {};
aaa['a'+num] = Math.random();
return _.extend(memo, aaa);
}, {})
));