-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (24 loc) · 725 Bytes
/
Copy pathindex.js
File metadata and controls
28 lines (24 loc) · 725 Bytes
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
const { Network, Trainer } = require( './brain' )
const net = new Network()
net.forge( 2, 4, 1 )
console.log(`
predictions before training:
\t[0,0]: ${net.run([ 0, 0 ])[ 0 ]}
\t[1,0]: ${net.run([ 1, 0 ])[ 0 ]}
\t[0,1]: ${net.run([ 0, 1 ])[ 0 ]}
\t[1,1]: ${net.run([ 1, 1 ])[ 0 ]}
`)
const trainer = new Trainer( net )
trainer.train([
{ input: [ 0, 0 ], output: [ 0 ] },
{ input: [ 1, 0 ], output: [ 1 ] },
{ input: [ 0, 1 ], output: [ 1 ] },
{ input: [ 1, 1 ], output: [ 0 ] }
])
console.log(`
predictions after training:
\t[0,0]: ${net.run([ 0, 0 ])[ 0 ]}
\t[1,0]: ${net.run([ 1, 0 ])[ 0 ]}
\t[0,1]: ${net.run([ 0, 1 ])[ 0 ]}
\t[1,1]: ${net.run([ 1, 1 ])[ 0 ]}
`)