* * @param json * @returns {NeuralNetwork}
(json)
| 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 | * |
nothing calls this directly
no test coverage detected