MCPcopy Create free account
hub / github.com/DFin/Neural-Network-Visualisation / propagate

Method propagate

assets/main.js:1331–1374  ·  view source on GitHub ↗
(pixels)

Source from the content-addressed store, hash-verified

1329 }
1330
1331 propagate(pixels) {
1332 const { mean, std } = this.normalization;
1333 const input = new Float32Array(pixels.length);
1334 for (let i = 0; i < pixels.length; i += 1) {
1335 input[i] = (pixels[i] - mean) / std;
1336 }
1337
1338 const activations = [input];
1339 const preActivations = [];
1340 let current = input;
1341
1342 for (const layer of this.layers) {
1343 const outSize = layer.biases.length;
1344 const linear = new Float32Array(outSize);
1345
1346 for (let neuron = 0; neuron < outSize; neuron += 1) {
1347 let sum = layer.biases[neuron];
1348 const weights = layer.weights[neuron];
1349 for (let source = 0; source < weights.length; source += 1) {
1350 sum += weights[source] * current[source];
1351 }
1352 linear[neuron] = sum;
1353 }
1354
1355 preActivations.push(linear);
1356 let activated;
1357 if (layer.activation === "relu") {
1358 activated = new Float32Array(outSize);
1359 for (let i = 0; i < outSize; i += 1) {
1360 activated[i] = linear[i] > 0 ? linear[i] : 0;
1361 }
1362 } else {
1363 activated = linear.slice();
1364 }
1365 activations.push(activated);
1366 current = activated;
1367 }
1368
1369 return {
1370 normalizedInput: activations[0],
1371 activations,
1372 preActivations,
1373 };
1374 }
1375}
1376
1377class ProbabilityPanel {

Callers 1

refreshNetworkStateFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected