Skip to content

Commit

Permalink
pca order fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JustGlowing committed Feb 28, 2023
1 parent c12cbdd commit 1056c60
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions minisom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 1056c60

Please sign in to comment.