forked from BrainJS/brain.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.js
More file actions
83 lines (70 loc) · 2.43 KB
/
hash.js
File metadata and controls
83 lines (70 loc) · 2.43 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import assert from 'assert';
import brain from '../../src';
describe('hash input and output', () => {
it('runs correctly with array input and output', () => {
let 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] }
]);
let output = net.run([1, 0]);
assert.ok(output[0] > 0.9, 'output: ' + output[0]);
});
it('runs correctly with hash input', () => {
let net = new brain.NeuralNetwork();
net.train([
{ input: { x: 0, y: 0 }, output: [0] },
{ input: { x: 0, y: 1 }, output: [1] },
{ input: { x: 1, y: 0 }, output: [1] },
{ input: { x: 1, y: 1 }, output: [0] }
]);
let output = net.run({x: 1, y: 0});
assert.ok(output[0] > 0.9, 'output: ' + output[0]);
});
it('runs correctly with hash output', () => {
let net = new brain.NeuralNetwork();
net.train([
{ input: [0, 0], output: { answer: 0 } },
{ input: [0, 1], output: { answer: 1 } },
{ input: [1, 0], output: { answer: 1 } },
{ input: [1, 1], output: { answer: 0 } }
]);
let output = net.run([1, 0]);
assert.ok(output.answer > 0.9, 'output: ' + output.answer);
});
it('runs correctly with hash input and output', () => {
let net = new brain.NeuralNetwork();
net.train([
{ input: { x: 0, y: 0 }, output: { answer: 0 } },
{ input: { x: 0, y: 1 }, output: { answer: 1 } },
{ input: { x: 1, y: 0 }, output: { answer: 1 } },
{ input: { x: 1, y: 1 }, output: { answer: 0 } }
]);
let output = net.run({x: 1, y: 0});
assert.ok(output.answer > 0.9, 'output: ' + output.answer);
});
it('runs correctly with sparse hashes', () => {
let net = new brain.NeuralNetwork();
net.train([
{ input: {}, output: {} },
{ input: { y: 1 }, output: { answer: 1 } },
{ input: { x: 1 }, output: { answer: 1 } },
{ input: { x: 1, y: 1 }, output: {} }
]);
let output = net.run({x: 1});
assert.ok(output.answer > 0.9);
});
it('runs correctly with unseen input', () => {
let net = new brain.NeuralNetwork();
net.train([
{ input: {}, output: {} },
{ input: { y: 1 }, output: { answer: 1 } },
{ input: { x: 1 }, output: { answer: 1 } },
{ input: { x: 1, y: 1 }, output: {} }
]);
let output = net.run({x: 1, z: 1});
assert.ok(output.answer > 0.9);
});
});