QLF? (2)

この方が、それらしいですか?

時間軸上でシフトを加えると、うまくいきません。

import matplotlib.pyplot as plt
import numpy as np
from sklearn.manifold import TSNE

alphabet = list("abcdefghijklmnopqrstuvwxyz")

values = ['111000111111111000', '111111111000111000111000111000', '111111111000111000111111111000111000', '111111111000111000111000', '111000',
          '111000111000111111111000111000', '111111111000111111111000111000', '111000111000111000111000', '111000111000', '111000111111111000111111111000111111111000',
          '111111111000111000111111111000', '111000111111111000111000111000', '111111111000111111111000', '111111111000111000', '111111111000111111111000111111111000',
          '111000111111111000111111111000111000', '111111111000111111111000111000111111111000', '111000111111111000111000', '111000111000111000', '111111111000',
          '111000111000111111111000', '111000111000111000111111111000', '111000111111111000111111111000', '111111111000111000111000111111111000', '111111111000111000111111111000111111111000',
          '111111111000111111111000111000111000']


morse_dict = dict(zip(alphabet, values))

nrepeat = 100
n = len(values)
word_len = 50

code_len_max = 0
for v in values:
    code_len_max = max(code_len_max, len(v))
print("code_len_max = ", code_len_max)

X = np.zeros((n * nrepeat, word_len))
Y = np.zeros(n * nrepeat, dtype=np.int)

for rep in range(nrepeat):
    for i, letter in enumerate(alphabet):
        joffset = int(np.random.uniform(1, word_len - code_len_max))
        for j in range(word_len):
            X[i + rep * n][j] = np.random.normal(0.0, 0.2)
        for j, char in enumerate(morse_dict[letter]):
            X[i+rep * n][j+joffset] = X[i+rep * n][j+joffset] + (ord(char) - ord('0'))
        Y[i+rep * n] = i

X_reduced = TSNE(n_components=2, random_state=0, perplexity=50).fit_transform(X)

plt.figure(figsize=(8, 12))

plt.subplot(3, 1, 1)
x = np.arange(word_len)
for i in range(3):
    y = X[i, :] + 2.0 * i
    plt.plot(x, y)
plt.grid()
plt.title('Waveform')

plt.subplot(3, 1, 2)
plt.scatter(X_reduced[:, 0], X_reduced[:, 1],
            c=Y, edgecolors='black', alpha=0.5)
plt.colorbar()
plt.title('t-SNE')

plt.subplot(3, 1, 3)
for rep in range(min(3, nrepeat)):
    for i, letter in enumerate(alphabet):
        s = chr(Y[i] + ord('a'))
        plt.text(X_reduced[i+rep*n, 0], X_reduced[i+rep*n, 1], s)
plt.xlim([min(X_reduced[:, 0]), max(X_reduced[:, 0])])
plt.ylim([min(X_reduced[:, 1]), max(X_reduced[:, 1])])
plt.title('t-SNE')

plt.show()

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.