* * @returns * { * layers: [ * { * x: {}, * y: {} * }, * { * '0': { * bias: -0.98771313, * weights: { * x: 0.8374838, * y: 1.245858 * }, * '1': { *
()
| 852 | * } |
| 853 | */ |
| 854 | toJSON() { |
| 855 | let layers = []; |
| 856 | for (let layer = 0; layer <= this.outputLayer; layer++) { |
| 857 | layers[layer] = {}; |
| 858 | |
| 859 | let nodes; |
| 860 | // turn any internal arrays back into hashes for readable json |
| 861 | if (layer === 0 && this.inputLookup) { |
| 862 | nodes = Object.keys(this.inputLookup); |
| 863 | } |
| 864 | else if (layer === this.outputLayer && this.outputLookup) { |
| 865 | nodes = Object.keys(this.outputLookup); |
| 866 | } |
| 867 | else { |
| 868 | nodes = range(0, this.sizes[layer]); |
| 869 | } |
| 870 | |
| 871 | for (let j = 0; j < nodes.length; j++) { |
| 872 | let node = nodes[j]; |
| 873 | layers[layer][node] = {}; |
| 874 | |
| 875 | if (layer > 0) { |
| 876 | layers[layer][node].bias = this.biases[layer][j]; |
| 877 | layers[layer][node].weights = {}; |
| 878 | for (let k in layers[layer - 1]) { |
| 879 | let index = k; |
| 880 | if (layer === 1 && this.inputLookup) { |
| 881 | index = this.inputLookup[k]; |
| 882 | } |
| 883 | layers[layer][node].weights[k] = this.weights[layer][j][index]; |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | } |
| 888 | return { |
| 889 | sizes: this.sizes, |
| 890 | layers, |
| 891 | outputLookup:!!this.outputLookup, |
| 892 | inputLookup:!!this.inputLookup, |
| 893 | activation: this.activation, |
| 894 | trainOpts: this._getTrainOptsJSON() |
| 895 | }; |
| 896 | } |
| 897 | |
| 898 | /** |
| 899 | * |
no test coverage detected