Skip to content

Commit

Permalink
unit test improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
JustGlowing committed Aug 28, 2024
1 parent b2e71c2 commit 336b4aa
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions minisom.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,8 @@ def test_quantization(self):

def test_divergence_measure(self):
test_data = array([[4], [2]])

# test that doesn't use vectorization
r = 0
for d in test_data:
for i in self.som._neigx:
Expand All @@ -921,6 +923,17 @@ def test_divergence_measure(self):
r += h * norm(d - w)
assert_array_almost_equal(r, self.som.divergence_measure(test_data))

# handwritten test
som = MiniSom(2, 1, 2, random_seed=1)
som._weights = array([[[0., 1.]], [[1., 0.]]])
test_data = array([[1., 0.], [0., 1.]])

h1 = som.neighborhood(som.winner(test_data[0]), som._sigma)
h2 = som.neighborhood(som.winner(test_data[1]), som._sigma)
r = h1[0][0] * sqrt(2) + h1[1][0] * 0
r += h2[0][0] * 0 + h2[1][0] * sqrt(2)
assert_array_almost_equal(r, som.divergence_measure(test_data))

def test_random_seed(self):
som1 = MiniSom(5, 5, 2, sigma=1.0, learning_rate=0.5, random_seed=1)
som2 = MiniSom(5, 5, 2, sigma=1.0, learning_rate=0.5, random_seed=1)
Expand Down

0 comments on commit 336b4aa

Please sign in to comment.