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

Method fromJSON

src/recurrent/rnn.js:464–511  ·  view source on GitHub ↗
(json)

Source from the content-addressed store, hash-verified

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 *

Callers 9

constructorMethod · 0.95
browser.min.jsFile · 0.45
tFunction · 0.45
browser.jsFile · 0.45
RNNFunction · 0.45
lstm.jsFile · 0.45
gru.jsFile · 0.45
rnn.jsFile · 0.45
json.jsFile · 0.45

Calls 1

bindEquationMethod · 0.95

Tested by

no test coverage detected