From cc6e323040198624a9b03d3ee1698a2147af40fc Mon Sep 17 00:00:00 2001 From: Ryuji Watanabe Date: Tue, 12 Nov 2019 16:13:16 +0900 Subject: [PATCH 01/10] =?UTF-8?q?=E3=82=B0=E3=83=AB=E3=83=BC=E3=83=97?= =?UTF-8?q?=E3=81=AE=E6=A7=8B=E6=88=90=E3=83=A1=E3=83=B3=E3=83=90=E3=83=BC?= =?UTF-8?q?=E3=82=92bag=20of=20words=E7=9A=84=E3=81=AA=E8=A1=A8=E7=8F=BE?= =?UTF-8?q?=E3=81=A7=E4=B8=8E=E3=81=88=E3=82=89=E3=82=8C=E3=81=9F=E6=99=82?= =?UTF-8?q?=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E4=BD=9C=E6=88=90=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=81=9F=E3=82=81=E3=81=AB=5Ffit=5FKDE=E5=86=85?= =?UTF-8?q?=E3=81=A7if=E6=96=87=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/models/tsom_plus_som.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/libs/models/tsom_plus_som.py b/libs/models/tsom_plus_som.py index 10e0609..0540805 100644 --- a/libs/models/tsom_plus_som.py +++ b/libs/models/tsom_plus_som.py @@ -25,14 +25,17 @@ def _fit_1st_TSOM(self, tsom_epoch_num): def _fit_KDE(self, kernel_width): # 学習した後の潜在空間からKDEで確率分布を作る prob_data = np.zeros((self.group_num, self.tsom.K1)) # group数*ノード数 # グループごとにKDEを適用 - for i in range(self.group_num): - Dist = dist.cdist(self.tsom.Zeta1, self.tsom.Z1[self.index_members_of_group[i], :], - 'sqeuclidean') # KxNの距離行列を計算 - H = np.exp(-Dist / (2 * kernel_width * kernel_width)) # KxNの学習量行列を計算 - prob = np.sum(H, axis=1) - prob_sum = np.sum(prob) - prob = prob / prob_sum - prob_data[i, :] = prob + if isinstance(self.index_members_of_group, np.ndarray) and self.index_members_of_group.ndim == 2: + pass + else: + for i in range(self.group_num): + Dist = dist.cdist(self.tsom.Zeta1, self.tsom.Z1[self.index_members_of_group[i], :], + 'sqeuclidean') # KxNの距離行列を計算 + H = np.exp(-Dist / (2 * kernel_width * kernel_width)) # KxNの学習量行列を計算 + prob = np.sum(H, axis=1) + prob_sum = np.sum(prob) + prob = prob / prob_sum + prob_data[i, :] = prob self.params_som['X'] = prob_data self.params_som['metric'] = "KLdivergence" From e311e08d635e17d5eb5e5419160109c632d33eca Mon Sep 17 00:00:00 2001 From: Ryuji Watanabe Date: Tue, 12 Nov 2019 16:21:15 +0900 Subject: [PATCH 02/10] =?UTF-8?q?bag=20of=20words=E7=9A=84=E3=81=AA?= =?UTF-8?q?=E8=A1=A8=E7=8F=BE=E3=81=A7=E3=82=B0=E3=83=AB=E3=83=BC=E3=83=97?= =?UTF-8?q?=E3=81=AE=E6=A7=8B=E6=88=90=E3=83=A1=E3=83=B3=E3=83=90=E3=83=BC?= =?UTF-8?q?=E3=82=92=E8=A1=A8=E7=8F=BE=E3=81=97=E3=81=9F=E6=99=82=E3=81=AE?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/models/tsom_plus_som.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/models/tsom_plus_som.py b/libs/models/tsom_plus_som.py index 0540805..549a8eb 100644 --- a/libs/models/tsom_plus_som.py +++ b/libs/models/tsom_plus_som.py @@ -26,7 +26,10 @@ def _fit_KDE(self, kernel_width): # 学習した後の潜在空間からKDEで prob_data = np.zeros((self.group_num, self.tsom.K1)) # group数*ノード数 # グループごとにKDEを適用 if isinstance(self.index_members_of_group, np.ndarray) and self.index_members_of_group.ndim == 2: - pass + distance = dist.cdist(self.tsom.Zeta1, self.tsom.Z1,'sqeuclidean') #K1 x num_members + H = np.exp(-0.5*distance/(kernel_width*kernel_width))#KxN + prob_data = self.index_members_of_group @ H.T #num_group x K1 + prob_data = prob_data / prob_data.sum(axis=1)[:,None] else: for i in range(self.group_num): Dist = dist.cdist(self.tsom.Zeta1, self.tsom.Z1[self.index_members_of_group[i], :], From e6863b36aede3ab016b00a8b8cf744b9887c371f Mon Sep 17 00:00:00 2001 From: Ryuji Watanabe Date: Sat, 16 Nov 2019 17:58:41 +0900 Subject: [PATCH 03/10] Reformat --- libs/models/tsom_plus_som.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libs/models/tsom_plus_som.py b/libs/models/tsom_plus_som.py index 549a8eb..6eaad38 100644 --- a/libs/models/tsom_plus_som.py +++ b/libs/models/tsom_plus_som.py @@ -26,13 +26,14 @@ def _fit_KDE(self, kernel_width): # 学習した後の潜在空間からKDEで prob_data = np.zeros((self.group_num, self.tsom.K1)) # group数*ノード数 # グループごとにKDEを適用 if isinstance(self.index_members_of_group, np.ndarray) and self.index_members_of_group.ndim == 2: - distance = dist.cdist(self.tsom.Zeta1, self.tsom.Z1,'sqeuclidean') #K1 x num_members - H = np.exp(-0.5*distance/(kernel_width*kernel_width))#KxN - prob_data = self.index_members_of_group @ H.T #num_group x K1 - prob_data = prob_data / prob_data.sum(axis=1)[:,None] + distance = dist.cdist(self.tsom.Zeta1, self.tsom.Z1, 'sqeuclidean') # K1 x num_members + H = np.exp(-0.5 * distance / (kernel_width * kernel_width)) # KxN + prob_data = self.index_members_of_group @ H.T # num_group x K1 + prob_data = prob_data / prob_data.sum(axis=1)[:, None] else: for i in range(self.group_num): - Dist = dist.cdist(self.tsom.Zeta1, self.tsom.Z1[self.index_members_of_group[i], :], + Dist = dist.cdist(self.tsom.Zeta1, + self.tsom.Z1[self.index_members_of_group[i], :], 'sqeuclidean') # KxNの距離行列を計算 H = np.exp(-Dist / (2 * kernel_width * kernel_width)) # KxNの学習量行列を計算 prob = np.sum(H, axis=1) From 7805eddf6e92df8961bcc38b811ce33412bff28e Mon Sep 17 00:00:00 2001 From: Ryuji Watanabe Date: Sat, 16 Nov 2019 18:20:23 +0900 Subject: [PATCH 04/10] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E4=BD=9C=E6=88=90=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/plus_TSOM/allclose_plusTSOM.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/plus_TSOM/allclose_plusTSOM.py b/tests/plus_TSOM/allclose_plusTSOM.py index 9a8ee1d..b15dd31 100644 --- a/tests/plus_TSOM/allclose_plusTSOM.py +++ b/tests/plus_TSOM/allclose_plusTSOM.py @@ -74,5 +74,27 @@ def test_plusTSOM_ishida_vs_test_plusTSOM_watanabe(self): np.testing.assert_allclose(htsom_ishida.som.history['y'], htsom_watanabe.som.history['y']) np.testing.assert_allclose(htsom_ishida.som.history['z'], htsom_watanabe.som.history['z']) + def _transform_list_to_bag(self,list_of_indexes): + for indexes in list_of_indexes: + + def test_matching_index_member_as_list_or_bag(self): + seed = 100 + np.random.seed(seed) + n_samples = 1000 + n_groups = 10 # group数 + n_features = 3 # 各メンバーの特徴数 + n_samples_per_group = 30 # 各グループにメンバーに何人いるのか + member_features,index_members_of_group = self.create_artficial_data(n_samples, + n_features, + n_groups, + n_samples_per_group) + + + Z1 = np.random.rand(n_samples, 2) * 2.0 - 1.0 + Z2 = np.random.rand(n_features, 2) * 2.0 - 1.0 + init_TSOM = [Z1, Z2] + init_SOM = np.random.rand(n_groups, 2) * 2.0 - 1.0 + + if __name__ == "__main__": unittest.main() From e83648d14b702ae096ec29f9afbd7706d512f01b Mon Sep 17 00:00:00 2001 From: Ryuji Watanabe Date: Mon, 18 Nov 2019 14:50:04 +0900 Subject: [PATCH 05/10] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E6=9B=B8=E3=81=84=E3=81=A6=E5=AE=9F=E8=A1=8C=E3=81=97=E3=81=A6?= =?UTF-8?q?=E3=81=BF=E3=81=9F=E3=81=8C=E3=82=A8=E3=83=A9=E3=83=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/plus_TSOM/allclose_plusTSOM.py | 53 ++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/tests/plus_TSOM/allclose_plusTSOM.py b/tests/plus_TSOM/allclose_plusTSOM.py index b15dd31..2ecb221 100644 --- a/tests/plus_TSOM/allclose_plusTSOM.py +++ b/tests/plus_TSOM/allclose_plusTSOM.py @@ -74,27 +74,68 @@ def test_plusTSOM_ishida_vs_test_plusTSOM_watanabe(self): np.testing.assert_allclose(htsom_ishida.som.history['y'], htsom_watanabe.som.history['y']) np.testing.assert_allclose(htsom_ishida.som.history['z'], htsom_watanabe.som.history['z']) - def _transform_list_to_bag(self,list_of_indexes): + def _transform_list_to_bag(self,list_of_indexes,num_members): + bag_of_members = np.empty((0,num_members)) for indexes in list_of_indexes: - + one_hot_vectors = np.eye(num_members)[indexes] + one_bag = one_hot_vectors.sum(axis=0)[None,:] + bag_of_members=np.append(bag_of_members,one_bag,axis=0) + return bag_of_members def test_matching_index_member_as_list_or_bag(self): seed = 100 np.random.seed(seed) - n_samples = 1000 + n_members = 100 n_groups = 10 # group数 n_features = 3 # 各メンバーの特徴数 n_samples_per_group = 30 # 各グループにメンバーに何人いるのか - member_features,index_members_of_group = self.create_artficial_data(n_samples, + member_features,index_members_of_group = self.create_artficial_data(n_members, n_features, n_groups, n_samples_per_group) + bag_of_members = self._transform_list_to_bag(index_members_of_group, n_members) - - Z1 = np.random.rand(n_samples, 2) * 2.0 - 1.0 + Z1 = np.random.rand(n_members, 2) * 2.0 - 1.0 Z2 = np.random.rand(n_features, 2) * 2.0 - 1.0 init_TSOM = [Z1, Z2] init_SOM = np.random.rand(n_groups, 2) * 2.0 - 1.0 + params_tsom = {'latent_dim': [2, 2], + 'resolution': [10, 10], + 'SIGMA_MAX': [1.0, 1.0], + 'SIGMA_MIN': [0.1, 0.1], + 'TAU': [50, 50], + 'init': init_TSOM} + params_som = {'latent_dim': 2, + 'resolution': 10, + 'sigma_max': 2.0, + 'sigma_min': 0.5, + 'tau': 50, + 'init': init_SOM} + tsom_epoch_num = 50 + som_epoch_num = 50 + kernel_width = 0.3 + + tsom_plus_som_input_list = TSOMPlusSOM(member_features=member_features, + index_members_of_group=index_members_of_group, + params_tsom=params_tsom, + params_som=params_som) + tsom_plus_som_input_bag = TSOMPlusSOM(member_features=member_features, + index_members_of_group=bag_of_members, + params_tsom=params_tsom, + params_som=params_som) + + tsom_plus_som_input_list.fit(tsom_epoch_num=tsom_epoch_num, + kernel_width=kernel_width, + som_epoch_num=som_epoch_num) + tsom_plus_som_input_bag.fit(tsom_epoch_num=tsom_epoch_num, + kernel_width=kernel_width, + som_epoch_num=som_epoch_num) + np.testing.assert_allclose(tsom_plus_som_input_list.tsom.history['y'], tsom_plus_som_input_bag.tsom.history['y']) + np.testing.assert_allclose(tsom_plus_som_input_list.tsom.history['z1'], tsom_plus_som_input_bag.tsom.history['z1']) + np.testing.assert_allclose(tsom_plus_som_input_list.tsom.history['z2'], tsom_plus_som_input_bag.tsom.history['z2']) + np.testing.assert_allclose(tsom_plus_som_input_list.params_som['X'], tsom_plus_som_input_bag.params_som['X']) + np.testing.assert_allclose(tsom_plus_som_input_list.som.history['y'], tsom_plus_som_input_bag.som.history['y']) + np.testing.assert_allclose(tsom_plus_som_input_list.som.history['z'], tsom_plus_som_input_bag.som.history['z']) if __name__ == "__main__": unittest.main() From 89109e2096abc3bb5f9bd663aac76731ebe09f97 Mon Sep 17 00:00:00 2001 From: Ryuji Watanabe Date: Tue, 3 Dec 2019 15:36:15 +0900 Subject: [PATCH 06/10] =?UTF-8?q?=E5=A4=89=E6=95=B0=E3=81=AErefactor?= =?UTF-8?q?=E3=81=A8=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E3=81=AE=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/models/tsom_plus_som.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libs/models/tsom_plus_som.py b/libs/models/tsom_plus_som.py index 6eaad38..bd3276a 100644 --- a/libs/models/tsom_plus_som.py +++ b/libs/models/tsom_plus_som.py @@ -5,13 +5,13 @@ class TSOMPlusSOM: - def __init__(self, member_features, index_members_of_group, params_tsom, params_som): + def __init__(self, member_features, group_features, params_tsom, params_som): self.params_tsom = params_tsom self.params_som = params_som self.params_tsom['X'] = member_features - self.index_members_of_group = index_members_of_group # グループ数の確認 - self.group_num = len(self.index_members_of_group) + self.group_features = group_features # グループ数の確認 + self.group_num = len(self.group_features) def fit(self, tsom_epoch_num, kernel_width, som_epoch_num): self._fit_1st_TSOM(tsom_epoch_num) @@ -25,15 +25,17 @@ def _fit_1st_TSOM(self, tsom_epoch_num): def _fit_KDE(self, kernel_width): # 学習した後の潜在空間からKDEで確率分布を作る prob_data = np.zeros((self.group_num, self.tsom.K1)) # group数*ノード数 # グループごとにKDEを適用 - if isinstance(self.index_members_of_group, np.ndarray) and self.index_members_of_group.ndim == 2: + if isinstance(self.group_features, np.ndarray) and self.group_features.ndim == 2: + # group_featuresがbag of membersで与えられた時の処理 distance = dist.cdist(self.tsom.Zeta1, self.tsom.Z1, 'sqeuclidean') # K1 x num_members H = np.exp(-0.5 * distance / (kernel_width * kernel_width)) # KxN - prob_data = self.index_members_of_group @ H.T # num_group x K1 + prob_data = self.group_features @ H.T # num_group x K1 prob_data = prob_data / prob_data.sum(axis=1)[:, None] else: + # group_featuresがlist of listsもしくはlist of arraysで与えられた時の処理 for i in range(self.group_num): Dist = dist.cdist(self.tsom.Zeta1, - self.tsom.Z1[self.index_members_of_group[i], :], + self.tsom.Z1[self.group_features[i], :], 'sqeuclidean') # KxNの距離行列を計算 H = np.exp(-Dist / (2 * kernel_width * kernel_width)) # KxNの学習量行列を計算 prob = np.sum(H, axis=1) From 9f0f30f54aa343b12a3b47e40c5b407064521a07 Mon Sep 17 00:00:00 2001 From: Ryuji Watanabe Date: Tue, 3 Dec 2019 16:01:03 +0900 Subject: [PATCH 07/10] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=82=92=E4=BF=AE=E6=AD=A3=E3=81=97=E5=AE=9F?= =?UTF-8?q?=E8=A1=8C=E3=80=81pass=E3=82=92=E7=A2=BA=E8=AA=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/plus_TSOM/allclose_plusTSOM.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/plus_TSOM/allclose_plusTSOM.py b/tests/plus_TSOM/allclose_plusTSOM.py index 2ecb221..d18c58a 100644 --- a/tests/plus_TSOM/allclose_plusTSOM.py +++ b/tests/plus_TSOM/allclose_plusTSOM.py @@ -10,11 +10,10 @@ class TestTSOMPlusSOM(unittest.TestCase): def create_artficial_data(self,n_samples,n_features,n_groups,n_samples_per_group): x = np.random.normal(0.0,1.0,(n_samples,n_features)) if isinstance(n_samples_per_group,int): - index_members_of_group = np.random.randint(0,n_samples,(n_groups,n_samples_per_group)) - elif isinstance(n_samples_per_group,np.ndarray): - index_members_of_group = [] - for n_samples_in_the_group in n_samples_per_group: - index_members_of_group.append(np.random.randint(0,n_samples,n_samples_in_the_group)) + n_samples_per_group = np.ones(n_groups,int) * n_samples_per_group + index_members_of_group = [] + for n_samples_in_the_group in n_samples_per_group: + index_members_of_group.append(np.random.randint(0,n_samples,n_samples_in_the_group)) return x, index_members_of_group def test_plusTSOM_ishida_vs_test_plusTSOM_watanabe(self): @@ -23,7 +22,7 @@ def test_plusTSOM_ishida_vs_test_plusTSOM_watanabe(self): n_samples = 1000 n_groups = 10 # group数 n_features = 3 # 各メンバーの特徴数 - n_samples_per_group = 30 # 各グループにメンバーに何人いるのか + n_samples_per_group = np.random.randint(1,30,n_groups) # 各グループにメンバーに何人いるのか member_features,index_members_of_group = self.create_artficial_data(n_samples, n_features, n_groups, @@ -52,7 +51,7 @@ def test_plusTSOM_ishida_vs_test_plusTSOM_watanabe(self): kernel_width = 0.3 htsom_ishida = TSOMPlusSOM(member_features=member_features, - index_members_of_group=index_members_of_group, + group_features=index_members_of_group, params_tsom=params_tsom, params_som=params_som) htsom_watanabe = TSOMPlusSOMWatanabe(member_features=member_features, @@ -87,7 +86,7 @@ def test_matching_index_member_as_list_or_bag(self): n_members = 100 n_groups = 10 # group数 n_features = 3 # 各メンバーの特徴数 - n_samples_per_group = 30 # 各グループにメンバーに何人いるのか + n_samples_per_group = np.random.randint(1,50,n_groups) # 各グループにメンバーに何人いるのか member_features,index_members_of_group = self.create_artficial_data(n_members, n_features, n_groups, @@ -115,13 +114,13 @@ def test_matching_index_member_as_list_or_bag(self): kernel_width = 0.3 tsom_plus_som_input_list = TSOMPlusSOM(member_features=member_features, - index_members_of_group=index_members_of_group, + group_features=index_members_of_group, params_tsom=params_tsom, params_som=params_som) tsom_plus_som_input_bag = TSOMPlusSOM(member_features=member_features, - index_members_of_group=bag_of_members, - params_tsom=params_tsom, - params_som=params_som) + group_features=bag_of_members, + params_tsom=params_tsom, + params_som=params_som) tsom_plus_som_input_list.fit(tsom_epoch_num=tsom_epoch_num, kernel_width=kernel_width, From 778a384070e7be53beba35f4a066a7c0a2df8370 Mon Sep 17 00:00:00 2001 From: Ryuji Watanabe Date: Wed, 29 Jan 2020 11:51:57 +0900 Subject: [PATCH 08/10] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=81=AE=E5=90=8D=E7=A7=B0=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/plus_TSOM/{allclose_plusTSOM.py => test_plusTSOM.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/plus_TSOM/{allclose_plusTSOM.py => test_plusTSOM.py} (100%) diff --git a/tests/plus_TSOM/allclose_plusTSOM.py b/tests/plus_TSOM/test_plusTSOM.py similarity index 100% rename from tests/plus_TSOM/allclose_plusTSOM.py rename to tests/plus_TSOM/test_plusTSOM.py From 8d03f4947edf8ecdb3e214e61f61356ad7ce1970 Mon Sep 17 00:00:00 2001 From: Ishida Takuro Date: Thu, 2 Apr 2020 22:51:43 +0900 Subject: [PATCH 09/10] =?UTF-8?q?=E5=AE=9F=E8=A1=8C=E3=81=AE=E3=83=90?= =?UTF-8?q?=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tutorials/TSOM_plus_SOM/fit_TSOM_plus_SOM.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tutorials/TSOM_plus_SOM/fit_TSOM_plus_SOM.py b/tutorials/TSOM_plus_SOM/fit_TSOM_plus_SOM.py index 5bfbe65..98ad266 100644 --- a/tutorials/TSOM_plus_SOM/fit_TSOM_plus_SOM.py +++ b/tutorials/TSOM_plus_SOM/fit_TSOM_plus_SOM.py @@ -2,7 +2,7 @@ import numpy as np from libs.datasets.artificial.kura_tsom import load_kura_tsom import matplotlib.pyplot as plt -from libs.models.TSOMPlusSOM import TSOMPlusSOM +from libs.models.tsom_plus_som import TSOMPlusSOM from mpl_toolkits.mplot3d import Axes3D from libs.visualization.som.Grad_norm import Grad_Norm @@ -27,11 +27,11 @@ input_data[int(2 * i), :, :] = group1 input_data[int(2 * i + 1), :, :] = group2 -# fig = plt.figure() -# ax = fig.add_subplot(1, 1, 1, projection="3d") -# for i in range(group_num): -# ax.scatter(input_data[i, :, 0], input_data[i, :, 1], input_data[i, :, 2]) -# plt.show() +fig = plt.figure() +ax = fig.add_subplot(1, 1, 1, projection="3d") +for i in range(group_num): + ax.scatter(input_data[i, :, 0], input_data[i, :, 1], input_data[i, :, 2]) +plt.show() input_data = input_data.reshape(-1, 3) # グループラベルの作成 @@ -55,7 +55,7 @@ # +型階層TSOMのclass読み込み # group_label以降の変数ははlatent_dim,resolution,sigma_max,sigma_min,tauでSOMとTSOMでまとめている tsom_plus_som = TSOMPlusSOM(member_features=input_data, - index_members_of_group=group_label, + group_features=group_label, params_tsom=params_tsom, params_som=params_som) From 03cd1cdfa084c1eb2bc50ddddaf044a3f58ca042 Mon Sep 17 00:00:00 2001 From: Ishida Takuro Date: Thu, 2 Apr 2020 23:05:38 +0900 Subject: [PATCH 10/10] =?UTF-8?q?=E8=A6=B3=E6=B8=AC=E3=83=87=E3=83=BC?= =?UTF-8?q?=E3=82=BF=E3=82=92=E8=A1=A8=E7=A4=BA=E3=81=99=E3=82=8B=E9=9A=9B?= =?UTF-8?q?=E3=81=AE=E3=83=A9=E3=83=99=E3=83=AB=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tutorials/TSOM_plus_SOM/fit_TSOM_plus_SOM.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tutorials/TSOM_plus_SOM/fit_TSOM_plus_SOM.py b/tutorials/TSOM_plus_SOM/fit_TSOM_plus_SOM.py index 98ad266..20a01ba 100644 --- a/tutorials/TSOM_plus_SOM/fit_TSOM_plus_SOM.py +++ b/tutorials/TSOM_plus_SOM/fit_TSOM_plus_SOM.py @@ -27,10 +27,12 @@ input_data[int(2 * i), :, :] = group1 input_data[int(2 * i + 1), :, :] = group2 +#観測データの描画 fig = plt.figure() ax = fig.add_subplot(1, 1, 1, projection="3d") for i in range(group_num): - ax.scatter(input_data[i, :, 0], input_data[i, :, 1], input_data[i, :, 2]) + ax.scatter(input_data[i, :, 0], input_data[i, :, 1], input_data[i, :, 2],label="group"+str(i+1)) + plt.legend(bbox_to_anchor=(1, 1), loc='upper right', borderaxespad=0, fontsize=10) plt.show() input_data = input_data.reshape(-1, 3)