(json)
| 462 | } |
| 463 | |
| 464 | fromJSON(json) { |
| 465 | const defaults = this.constructor.defaults; |
| 466 | const options = json.options; |
| 467 | this.model = null; |
| 468 | this.hiddenLayers = null; |
| 469 | const allMatrices = []; |
| 470 | const input = Matrix.fromJSON(json.input); |
| 471 | allMatrices.push(input); |
| 472 | const hiddenLayers = []; |
| 473 | |
| 474 | // backward compatibility for hiddenSizes |
| 475 | (json.hiddenLayers || json.hiddenSizes).forEach((hiddenLayer) => { |
| 476 | let layers = {}; |
| 477 | for (let p in hiddenLayer) { |
| 478 | layers[p] = Matrix.fromJSON(hiddenLayer[p]); |
| 479 | allMatrices.push(layers[p]); |
| 480 | } |
| 481 | hiddenLayers.push(layers); |
| 482 | }); |
| 483 | |
| 484 | const outputConnector = Matrix.fromJSON(json.outputConnector); |
| 485 | allMatrices.push(outputConnector); |
| 486 | const output = Matrix.fromJSON(json.output); |
| 487 | allMatrices.push(output); |
| 488 | |
| 489 | Object.assign(this, defaults, options); |
| 490 | |
| 491 | // backward compatibility |
| 492 | if (options.hiddenSizes) { |
| 493 | this.hiddenLayers = options.hiddenSizes; |
| 494 | } |
| 495 | |
| 496 | if (options.hasOwnProperty('dataFormatter') && options.dataFormatter !== null) { |
| 497 | this.dataFormatter = DataFormatter.fromJSON(options.dataFormatter); |
| 498 | } |
| 499 | |
| 500 | this.model = { |
| 501 | input, |
| 502 | hiddenLayers, |
| 503 | output, |
| 504 | allMatrices, |
| 505 | outputConnector, |
| 506 | equations: [], |
| 507 | equationConnections: [], |
| 508 | }; |
| 509 | this.initialLayerInputs = this.hiddenLayers.map((size) => new Matrix(size, 1)); |
| 510 | this.bindEquation(); |
| 511 | } |
| 512 | |
| 513 | /** |
| 514 | * |
no test coverage detected