| 2742 | } |
| 2743 | |
| 2744 | findImportantConnections(layer) { |
| 2745 | const limit = this.options.maxConnectionsPerNeuron; |
| 2746 | const minMagnitude = Math.max(0, this.options.connectionWeightThreshold ?? 0); |
| 2747 | const selected = []; |
| 2748 | let maxAbsWeight = 0; |
| 2749 | for (let target = 0; target < layer.weights.length; target += 1) { |
| 2750 | const row = layer.weights[target]; |
| 2751 | const candidates = []; |
| 2752 | for (let source = 0; source < row.length; source += 1) { |
| 2753 | const weight = row[source]; |
| 2754 | if (!Number.isFinite(weight)) continue; |
| 2755 | const magnitude = Math.abs(weight); |
| 2756 | candidates.push({ sourceIndex: source, targetIndex: target, weight, magnitude }); |
| 2757 | if (magnitude > maxAbsWeight) maxAbsWeight = magnitude; |
| 2758 | } |
| 2759 | candidates.sort((a, b) => b.magnitude - a.magnitude); |
| 2760 | const take = Math.min(limit, candidates.length); |
| 2761 | for (let i = 0; i < take; i += 1) { |
| 2762 | const candidate = candidates[i]; |
| 2763 | if (candidate.magnitude < minMagnitude) break; |
| 2764 | selected.push({ |
| 2765 | sourceIndex: candidate.sourceIndex, |
| 2766 | targetIndex: candidate.targetIndex, |
| 2767 | weight: candidate.weight, |
| 2768 | }); |
| 2769 | } |
| 2770 | } |
| 2771 | return { selected, maxAbsWeight }; |
| 2772 | } |
| 2773 | |
| 2774 | update(displayActivations, networkActivations = displayActivations, preActivations = null) { |
| 2775 | this.lastDisplayActivations = displayActivations; |