From 1056c60bd2b7f82d274c73cdb561dc25c91eea5b Mon Sep 17 00:00:00 2001 From: JustGlowing Date: Tue, 28 Feb 2023 10:54:19 +0000 Subject: [PATCH] pca order fix --- minisom.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/minisom.py b/minisom.py index 99a1c7e..d62dd32 100644 --- a/minisom.py +++ b/minisom.py @@ -381,7 +381,8 @@ def pca_weights_init(self, data): pc_order = argsort(-pc_length) for i, c1 in enumerate(linspace(-1, 1, len(self._neigx))): for j, c2 in enumerate(linspace(-1, 1, len(self._neigy))): - self._weights[i, j] = c1*pc[pc_order[0]] + c2*pc[pc_order[1]] + self._weights[i, j] = c1*pc[:, pc_order[0]] + \ + c2*pc[:, pc_order[1]] def train(self, data, num_iteration, random_order=False, verbose=False, use_epochs=False): @@ -862,8 +863,10 @@ def test_random_weights_init(self): def test_pca_weights_init(self): som = MiniSom(2, 2, 2) som.pca_weights_init(array([[1., 0.], [0., 1.], [1., 0.], [0., 1.]])) - expected = array([[[0., -1.41421356], [-1.41421356, 0.]], - [[1.41421356, 0.], [0., 1.41421356]]]) + expected = array([[[-1.41421356, 0.], + [0., 1.41421356]], + [[0., -1.41421356], + [1.41421356, 0.]]]) assert_array_almost_equal(som._weights, expected) def test_distance_map(self):