MCPcopy
hub / github.com/BrainJS/brain.js / fromJSON

Method fromJSON

src/neural-network.js:903–930  ·  view source on GitHub ↗

* * @param json * @returns {NeuralNetwork}

(json)

Source from the content-addressed store, hash-verified

901 * @returns {NeuralNetwork}
902 */
903 fromJSON(json) {
904 this.sizes = json.sizes;
905 this._initialize();
906
907 for (let i = 0; i <= this.outputLayer; i++) {
908 let layer = json.layers[i];
909 if (i === 0 && (!layer[0] || json.inputLookup)) {
910 this.inputLookup = lookup.lookupFromHash(layer);
911 }
912 else if (i === this.outputLayer && (!layer[0] || json.outputLookup)) {
913 this.outputLookup = lookup.lookupFromHash(layer);
914 }
915 if (i > 0) {
916 const nodes = Object.keys(layer);
917 this.sizes[i] = nodes.length;
918 for (let j in nodes) {
919 const node = nodes[j];
920 this.biases[i][j] = layer[node].bias;
921 this.weights[i][j] = toArray(layer[node].weights);
922 }
923 }
924 }
925 if (json.hasOwnProperty('trainOpts')) {
926 this._updateTrainingOptions(json.trainOpts);
927 }
928 this.setActivation(this.activation || 'sigmoid');
929 return this;
930 }
931
932 /**
933 *

Callers

nothing calls this directly

Calls 5

_initializeMethod · 0.95
setActivationMethod · 0.95
lookupFromHashMethod · 0.80
toArrayFunction · 0.50

Tested by

no test coverage detected