()
| 261 | } |
| 262 | |
| 263 | function refreshNetworkState() { |
| 264 | const rawInput = digitCanvas.getPixels(); |
| 265 | const propagation = neuralModel.propagate(rawInput); |
| 266 | const displayActivations = propagation.activations.slice(); |
| 267 | if (displayActivations.length > 0) { |
| 268 | displayActivations[0] = rawInput; |
| 269 | } |
| 270 | |
| 271 | const logitsTyped = |
| 272 | propagation.preActivations.length > 0 |
| 273 | ? propagation.preActivations[propagation.preActivations.length - 1] |
| 274 | : new Float32Array(0); |
| 275 | const probabilities = |
| 276 | logitsTyped.length > 0 ? Float32Array.from(softmax(Array.from(logitsTyped))) : new Float32Array(0); |
| 277 | |
| 278 | if (probabilities.length && displayActivations.length > 1) { |
| 279 | displayActivations[displayActivations.length - 1] = probabilities; |
| 280 | } |
| 281 | |
| 282 | let networkActivations = propagation.activations; |
| 283 | if (probabilities.length) { |
| 284 | networkActivations = propagation.activations.slice(); |
| 285 | if (networkActivations.length > 1) { |
| 286 | networkActivations[networkActivations.length - 1] = probabilities; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | neuralScene.update(displayActivations, networkActivations, propagation.preActivations); |
| 291 | const probabilitiesForPanel = probabilities.length ? probabilities : logitsTyped; |
| 292 | probabilityPanel.update(probabilitiesForPanel.length ? Array.from(probabilitiesForPanel) : []); |
| 293 | |
| 294 | // No noisy debug logs; visual updates are visible in-scene |
| 295 | } |
| 296 | |
| 297 | await setupMnistSampleButtons({ |
| 298 | digitCanvas, |
no test coverage detected