Skip to content

Commit

Permalink
❇️ #145
Browse files Browse the repository at this point in the history
  • Loading branch information
xgdgsc committed Oct 25, 2019
1 parent b31dfbe commit 76a777b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Python/somoclu/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ def _check_parameters(self):
raise Exception("Invalid parameter for verbose: " +
self._kernel_type)


def _pca_init(self):
try:
from sklearn.decomposition import PCA
Expand Down Expand Up @@ -571,30 +570,37 @@ def get_surface_state(self, data=None):
else:
d = data

codebookReshaped = self.codebook.reshape(self.codebook.shape[0] * self.codebook.shape[1], self.codebook.shape[2])
codebookReshaped = self.codebook.reshape(
self.codebook.shape[0] * self.codebook.shape[1], self.codebook.shape[2])
parts = np.array_split(d, 200, axis=0)
am = np.empty((0, (self._n_columns * self._n_rows)), dtype="float64")
for part in parts:
am = np.concatenate((am, (cdist((part), codebookReshaped, 'euclidean'))), axis=0)
am = np.concatenate(
(am, (cdist((part), codebookReshaped, 'euclidean'))), axis=0)

if data is None:
self.activation_map = am
return am

def get_bmus(self, activation_map):
def get_bmus(self, activation_map, order='F'):
"""Returns Best Matching Units indexes of the activation map.
:param activation_map: Activation map computed with self.get_surface_state()
:type activation_map: 2D numpy.array
:param order: order of returned numpy array, 'F' or 'C'
:returns: The bmus indexes corresponding to this activation map
(same as self.bmus for the training samples).
:rtype: 2D numpy.array
"""

Y, X = np.unravel_index(activation_map.argmin(axis=1),
(self._n_rows, self._n_columns))
return np.vstack((X, Y)).T
if order == 'F':
return np.vstack((X, Y)).T
elif order == 'C':
return np.vstack((X, Y))

def view_similarity_matrix(self, data=None, labels=None, figsize=None,
filename=None):
Expand Down

0 comments on commit 76a777b

Please sign in to comment.