'non_face')

# 元のデータとそのラベルを作成
samples = np.concatenate([np_face_data, np_non_face_data])
label = np.concatenate([face_labels, non_face_labels])

# 先頭に1を挿入
length = samples.shape[0]
samples = np.hstack([np.array([np.ones(length)]).T, samples])

use_test_data_size = 1000
# テストデータとそのラベルを作成
face_test_data_size = len(face_files[train_face_data_size:])
non_test_face_data_size = len(non_face_files[train_non_face_data_size:])
np_test_data = np.array(
    getTestData(face_files[train_face_data_size:train_face_data_size +
                           use_test_data_size]) +
    getTestData(
        non_face_files[train_non_face_data_size:train_non_face_data_size +
                       use_test_data_size]))
ans = [1 for _ in range(use_test_data_size)
       ] + [-1 for _ in range(use_test_data_size)]

# b(教師ベクトル) を作成
face = np.array([-1 for _ in range(length)])
face[0] = 1
non_face = np.array([-1 for _ in range(length)])
non_face[1] = 1

# W(重みベクトル) を作成
vector = np.linalg.inv(samples.T @ samples) @ samples.T
w_face = vector @ face
Beispiel #2
0
# 元のデータとラベルをセット
samples = np.concatenate([np_face_data, np_non_face_data])
label = np.concatenate([face_labels, non_face_labels])

# 先頭に1を挿入
length = samples.shape[0]
samples = np.hstack([np.array([np.ones(length)]).T, samples])

# テストデータを作成
face_test_data_size = len(face_files[train_face_data_size:])
non_test_face_data_size = len(non_face_files[train_non_face_data_size:])

ans = [1 for _ in range(1000)] + [-1 for _ in range(1000)]
np_test_data = np.array(
    getTestData(face_files[train_face_data_size:train_face_data_size + 1000]) +
    getTestData(
        non_face_files[train_non_face_data_size:train_non_face_data_size +
                       1000]))

rho = 10**(-3)
print("学習率: {}".format(rho))

# b(教師ベクトル) を作成
batch_size = 10
face = np.array([-1 for _ in range(batch_size)])
face[0] = 1
non_face = np.array([-1 for _ in range(batch_size)])
non_face[1] = 1

# W(重みベクトル) を作成
# 元のデータとラベルをセット
samples = np.concatenate([np_face_data, np_non_face_data])
label = np.concatenate([face_labels, non_face_labels])

# 先頭に1を挿入
length = samples.shape[0]
samples = np.hstack([np.array([np.ones(length)]).T, samples])

# テストデータを作成
face_test_data_size = len(face_files[train_face_data_size:])
non_test_face_data_size = len(non_face_files[train_non_face_data_size:])

ans_length = 1000
ans = [1 for _ in range(ans_length)] + [-1 for _ in range(ans_length)]
np_test_data = np.array(
    getTestData(face_files[train_face_data_size:train_face_data_size +
                           ans_length]) +
    getTestData(
        non_face_files[train_non_face_data_size:train_non_face_data_size +
                       ans_length]))

rho = 10**(-4)

# b(教師ベクトル) を作成
face = np.array([-1 for _ in range(train_face_data_size)])
face[0] = 1
non_face = np.array([-1 for _ in range(train_non_face_data_size)])
non_face[1] = 1
b = np.concatenate([face, non_face])

# W(重みベクトル) を作成
w_face = np.random.normal(loc=0, scale=0.01, size=1025)