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

Method normaliseLayer

assets/main.js:1294–1321  ·  view source on GitHub ↗
(layer, index)

Source from the content-addressed store, hash-verified

1292 }
1293
1294 normaliseLayer(layer, index) {
1295 if (!layer || !Array.isArray(layer.weights) || layer.weights.length === 0) {
1296 throw new Error(`Layer ${index} is missing valid weight matrices.`);
1297 }
1298 const weights = layer.weights.map((row) => {
1299 if (row instanceof Float32Array) {
1300 return new Float32Array(row);
1301 }
1302 if (Array.isArray(row)) {
1303 return Float32Array.from(row);
1304 }
1305 throw new Error(`Layer ${index} contains an invalid weight row.`);
1306 });
1307 let biases;
1308 if (layer.biases instanceof Float32Array) {
1309 biases = new Float32Array(layer.biases);
1310 } else if (Array.isArray(layer.biases)) {
1311 biases = Float32Array.from(layer.biases);
1312 } else {
1313 biases = new Float32Array(weights.length > 0 ? weights[0].length : 0);
1314 }
1315 return {
1316 name: typeof layer.name === "string" ? layer.name : `dense_${index}`,
1317 activation: typeof layer.activation === "string" ? layer.activation : "relu",
1318 weights,
1319 biases,
1320 };
1321 }
1322
1323 updateLayers(layerDefinitions) {
1324 if (!Array.isArray(layerDefinitions) || layerDefinitions.length === 0) {

Callers 2

constructorMethod · 0.95
updateLayersMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected