MCPcopy Index your code
hub / github.com/BrainJS/brain.js / finishStreamIteration

Method finishStreamIteration

src/train-stream.js:98–167  ·  view source on GitHub ↗

* * @returns {*}

()

Source from the content-addressed store, hash-verified

96 * @returns {*}
97 */
98 finishStreamIteration() {
99 if (this.dataFormatDetermined && this.size !== this.count) {
100 this.log('This iteration\'s data length was different from the first.');
101 }
102
103 if (!this.dataFormatDetermined) {
104 // create the lookup
105 this.neuralNetwork.inputLookup = lookup.lookupFromArray(this.inputKeys);
106 if(!Array.isArray(this.firstDatum.output)){
107 this.neuralNetwork.outputLookup = lookup.lookupFromArray(this.outputKeys);
108 }
109
110 let data = this.neuralNetwork._formatData(this.firstDatum);
111 let sizes = [];
112 let inputSize = data[0].input.length;
113 let outputSize = data[0].output.length;
114 let hiddenLayers = this.neuralNetwork.hiddenLayers;
115 if (!hiddenLayers) {
116 sizes.push(Math.max(3, Math.floor(inputSize / 2)));
117 } else {
118 hiddenLayers.forEach(size => {
119 sizes.push(size);
120 });
121 }
122
123 sizes.unshift(inputSize);
124 sizes.push(outputSize);
125
126 this.dataFormatDetermined = true;
127 this.neuralNetwork.sizes = sizes;
128 this.neuralNetwork._initialize();
129
130 if (typeof this.floodCallback === 'function') {
131 this.floodCallback();
132 }
133 return;
134 }
135
136 let error = this.sum / this.size;
137
138 if (this.log && (this.i % this.logPeriod === 0)) {
139 this.log('iterations:', this.i, 'training error:', error);
140 }
141 if (this.callback && (this.i % this.callbackPeriod === 0)) {
142 this.callback({
143 error: error,
144 iterations: this.i
145 });
146 }
147
148 this.sum = 0;
149 this.count = 0;
150 // update the iterations
151 this.i++;
152
153 // do a check here to see if we need the stream again
154 if (this.i < this.iterations && error > this.errorThresh) {
155 if (typeof this.floodCallback === 'function') {

Callers

nothing calls this directly

Calls 3

lookupFromArrayMethod · 0.80
_formatDataMethod · 0.80
_initializeMethod · 0.45

Tested by

no test coverage detected