-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Library can now output network as JSON. Networks can save themselves …
…in JSON form to supplied filename.
- Loading branch information
1 parent
ecb9348
commit b703b01
Showing
12 changed files
with
114 additions
and
59 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
const Network = require('../src/Network.js'); | ||
|
||
test('library can convert a model to JSON', () => { | ||
|
||
// Build the network... | ||
var network = new Network({ | ||
layers: [2,2,1], | ||
bias: false | ||
}); | ||
|
||
// Hard-code weights to create exact JSON | ||
network.layers.map(l => { | ||
l.neurons.map(n => { | ||
n.outputs.map(o => { | ||
o.weight = 0.5; | ||
}); | ||
}); | ||
}); | ||
|
||
const expectedJSON = '{"layers":[{"neurons":[{"type":"Input","label":"input-0","activationType":"sigmoid","outputs":[{"type":"Synapse","label":"input-0--hidden-0","inputLabel":"input-0","outputLabel":"hidden-0","weight":0.5},{"type":"Synapse","label":"input-0--hidden-1","inputLabel":"input-0","outputLabel":"hidden-1","weight":0.5}]},{"type":"Input","label":"input-1","activationType":"sigmoid","outputs":[{"type":"Synapse","label":"input-1--hidden-0","inputLabel":"input-1","outputLabel":"hidden-0","weight":0.5},{"type":"Synapse","label":"input-1--hidden-1","inputLabel":"input-1","outputLabel":"hidden-1","weight":0.5}]}]},{"neurons":[{"type":"Hidden","label":"hidden-0","activationType":"sigmoid","outputs":[{"type":"Synapse","label":"hidden-0--output-0","inputLabel":"hidden-0","outputLabel":"output-0","weight":0.5}]},{"type":"Hidden","label":"hidden-1","activationType":"sigmoid","outputs":[{"type":"Synapse","label":"hidden-1--output-0","inputLabel":"hidden-1","outputLabel":"output-0","weight":0.5}]}]},{"neurons":[{"type":"Output","label":"output-0","activationType":"identity","outputs":[]}]}]}'; | ||
|
||
expect(network.toJSON()).toBe(expectedJSON); | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
|
||
const Network = require('../src/Network.js'); | ||
|
||
test('library can convert a model to JSON', (done) => { | ||
|
||
// Build the network... | ||
var network = new Network({ | ||
layers: [2,2,1], | ||
bias: false | ||
}); | ||
|
||
const filename = './temp.json'; | ||
|
||
network.save(filename,() => { | ||
|
||
expect(fs.existsSync(filename)).toBe(true); | ||
|
||
fs.unlinkSync(filename); | ||
|
||
done(); | ||
|
||
}); | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters