Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

visualize_topic_decompostion #35

Merged
merged 8 commits into from
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added data/tmp/あっぷる_SOM_history.pickle
Binary file not shown.
Binary file added data/tmp/あっぷる_UKR_history.pickle
Binary file not shown.
Binary file removed data/tmp/ファッション_SOM.pickle
Binary file not shown.
Binary file added data/tmp/ファッション_SOM_history.pickle
Binary file not shown.
Binary file added data/tmp/ファッション_UKR_history.pickle
Binary file not shown.
Binary file added data/tmp/ペット_SOM_history.pickle
Binary file not shown.
Binary file added data/tmp/ペット_UKR_history.pickle
Binary file not shown.
Binary file added data/tmp/宮崎一希_SOM_history.pickle
Binary file not shown.
Binary file added data/tmp/宮崎一希_UKR_history.pickle
Binary file not shown.
Binary file added data/tmp/機械学習_SOM_history.pickle
Binary file not shown.
Binary file added data/tmp/機械学習_UKR_history.pickle
Binary file not shown.
2 changes: 1 addition & 1 deletion dev/Grad_norm.py → dev/Grad_norm_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class Grad_Norm:
def __init__(self, X=None, Z=None, sigma=None, resolution=None,
def __init__(self, X=None, Z=None, Y=None, sigma=None, resolution=None,
labels=None, fig_size=[6, 6], title_text='Grad_norm', cmap_type='jet',
interpolation_method='spline36', repeat=False, interval=5):
# インプットが無効だった時のエラー処理
Expand Down
File renamed without changes.
126 changes: 125 additions & 1 deletion dev/fetch_make_csv.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1346,10 +1346,134 @@
"print(\"count:\", len(divs))"
]
},
{
"cell_type": "markdown",
"id": "6b3ed84f-142e-42af-a8be-05b30e24c897",
"metadata": {},
"source": [
"こっから違う話"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "b2424a1a-45f3-41f3-b7c0-f729425b2e03",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0, 1, 2, 3],\n",
" [ 4, 5, 6, 7],\n",
" [ 8, 9, 10, 11]])"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import numpy as np\n",
"\n",
"X = np.arange(12).reshape(3,4)\n",
"mask_std = np.zeros(X.shape)\n",
"X"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "57eaab59-0d09-4197-be0a-ff7af634d692",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[3 3 3]\n"
]
}
],
"source": [
"print(np.argmax(X, axis=1))\n",
"mask = np.argmax(X, axis=1)\n",
"k_max = np.max(X, axis=0)"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "411d5d54-d642-41fe-8f5d-a7991a68db67",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0. , 0. , 0. , 0.27272727],\n",
" [0. , 0. , 0. , 0.63636364],\n",
" [0. , 0. , 0. , 1. ]])"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# For mask and normalization(min:0, max->1)\n",
"for i, max_k in enumerate(mask):\n",
" mask_std[i, max_k] = 1 / k_max[max_k]\n",
"X_mask_std = X * mask_std\n",
"\n",
"\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "c194345f-857c-42de-b648-0ccd4fa5b1c5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['rgb(31, 119, 180, 0.1)',\n",
" 'rgb(255, 127, 14, 0.1)',\n",
" 'rgb(44, 160, 44, 0.1)',\n",
" 'rgb(214, 39, 40, 0.1)',\n",
" 'rgb(148, 103, 189, 0.1)',\n",
" 'rgb(140, 86, 75, 0.1)',\n",
" 'rgb(227, 119, 194, 0.1)',\n",
" 'rgb(127, 127, 127, 0.1)',\n",
" 'rgb(188, 189, 34, 0.1)',\n",
" 'rgb(23, 190, 207, 0.1)']"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"DEFAULT_PLOTLY_COLORS=['rgb(31, 119, 180)', 'rgb(255, 127, 14)',\n",
" 'rgb(44, 160, 44)', 'rgb(214, 39, 40)',\n",
" 'rgb(148, 103, 189)', 'rgb(140, 86, 75)',\n",
" 'rgb(227, 119, 194)', 'rgb(127, 127, 127)',\n",
" 'rgb(188, 189, 34)', 'rgb(23, 190, 207)']\n",
"alpha = 0.1\n",
"# for k in DEFAULT_PLOTLY_COLORS:\n",
"# print(\")\n",
"DPC_with_Alpha = [k[:-1]+', '+str(alpha)+k[-1:] for k in DEFAULT_PLOTLY_COLORS]\n",
"DPC_with_Alpha"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cea8906c-059b-4514-a61a-878f5796fa11",
"id": "0a096ee8-2033-4b65-97f5-c777067c3a76",
"metadata": {},
"outputs": [],
"source": []
Expand Down
99 changes: 0 additions & 99 deletions dev/ファッション.csv

This file was deleted.

25 changes: 20 additions & 5 deletions fit.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# import sys
# sys.path.append('../')
from som import ManifoldModeling as MM
import matplotlib.pyplot as plt
import matplotlib.animation as ani
import numpy as np
import pickle
from sklearn.decomposition import NMF

def update(i, fig_title, Z):
if i != 0:
Expand All @@ -12,7 +15,7 @@ def update(i, fig_title, Z):


if __name__ == '__main__':
from dev.Grad_norm import Grad_Norm
from dev.Grad_norm_dev import Grad_Norm

keyword = "ファッション"
model = "SOM"
Expand All @@ -36,7 +39,7 @@ def update(i, fig_title, Z):

np.random.seed(seed)

mm = MM(X, latent_dim=latent_dim, resolution=resolution, sigma_max=sigma_max, sigma_min=sigma_min, tau=tau, init='PCA')
mm = MM(X, model_name='SOM', latent_dim=latent_dim, resolution=resolution, sigma_max=sigma_max, sigma_min=sigma_min, tau=tau, init='PCA')
mm.fit(nb_epoch=nb_epoch)

mm_umatrix = Grad_Norm(X=X,
Expand All @@ -45,11 +48,23 @@ def update(i, fig_title, Z):
labels=labels,
resolution=umat_resolution,
title_text=title_text)
mm_umatrix.draw_umatrix()
# mm_umatrix.draw_umatrix()
Z = mm.history['z'][-1]
Y = mm.history['y'][-1]
model_t3 = NMF(n_components=5, init='random', random_state=2, max_iter=300,
solver='cd')
Wt3 = model_t3.fit_transform(Y)
Ht3 = model_t3.components_

fig = plt.figure(figsize=(16, 9))
two = plt.imshow(Wt3[:, 1].reshape(resolution, resolution),
extent=[Z[:, 0].min(), Z[:, 0].max(), Z[:, 1].min(),
Z[:, 1].max()],
interpolation=None, alpha=0.8)
plt.show()


Fig = plt.figure(figsize=(16, 9))
# animation = ani.FuncAnimation(Fig, update, fargs=(np.zeros(10, 10, 2)))
fig = plt.figure(figsize = (10, 6))
# ani = ani.FuncAnimation(fig, update, fargs = ('Initial Animation! ', mm.history['z']), \
# interval = 1, frames = 500)
# plt.show()
Expand Down
2 changes: 0 additions & 2 deletions som.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,3 @@ def fit(self, nb_epoch=100, verbose=True):
self.history['z'][epoch] = self.Z
self.history['y'][epoch] = self.Y
self.history['sigma'][epoch] = self.sigma


Loading