Skip to content

Commit

Permalink
update self.weights_ after deleting neurons
Browse files Browse the repository at this point in the history
  • Loading branch information
SandroMartens committed Feb 22, 2024
1 parent e9594a2 commit 5e4aee8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions dbgsom/BaseSom.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,15 @@ def _write_node_statistics(self, X: npt.ArrayLike) -> None:
def _remove_dead_neurons(self, X: npt.ArrayLike) -> None:
"""Delete all neurons which represent zero samples from the training set."""
som_copy = copy.deepcopy(self.som_)
for node in self.som_.nodes:
if self.som_.nodes[node]["hit_count"] == 0:
som_copy.remove_node(node)
dead_neurons = [
node for node in self.som_.nodes if self.som_.nodes[node]["hit_count"] == 0
]
for node in dead_neurons:
som_copy.remove_node(node)
self.som_ = som_copy

self.neurons_ = list(self.som_.nodes)
self.weights_ = self._extract_values_from_graph("weight")

def _extract_values_from_graph(self, attribute: str) -> np.ndarray:
"""Return an array of shape (n_nodes, 1) with some given attribute of the
Expand Down

0 comments on commit 5e4aee8

Please sign in to comment.