Skip to content

Commit

Permalink
Merge pull request JustGlowing#33 from Sourmpis/master
Browse files Browse the repository at this point in the history
speed up in update method
  • Loading branch information
JustGlowing committed May 30, 2019
2 parents fe81163 + 3940f0f commit 48e40cc
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions minisom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from numpy import (array, unravel_index, nditer, linalg, random, subtract,
power, exp, pi, zeros, arange, outer, meshgrid, dot,
logical_and, mean, std, cov, argsort, linspace, transpose)
logical_and, mean, std, cov, argsort, linspace, transpose,
einsum
)
from collections import defaultdict, Counter
from warnings import warn
from sys import stdout
Expand Down Expand Up @@ -240,13 +242,8 @@ def update(self, x, win, t, max_iteration):
sig = self._decay_function(self._sigma, t, max_iteration)
# improves the performances
g = self.neighborhood(win, sig)*eta
it = nditer(g, flags=['multi_index'])

while not it.finished:
# eta * neighborhood_function * (x-w)
x_w = (x - self._weights[it.multi_index])
self._weights[it.multi_index] += g[it.multi_index] * x_w
it.iternext()
self._weights += einsum('ij, ijk->ijk', g, x-self._weights)

def quantization(self, data):
"""Assigns a code book (weights vector of the winning neuron)
Expand Down

0 comments on commit 48e40cc

Please sign in to comment.