示例#1
0
    classified_label = classified_label.reshape(len(classified_label), 1)
    return classified_label


def sum_rule(W, l_mean, test_image):
    means_project = W.T @ l_mean
    data_project = W.T @ test_image.T
    norm_x = np.linalg.norm(data_project, axis=0).reshape(
        1, len(np.linalg.norm(data_project, axis=0)))  #1*n
    norm_means = np.linalg.norm(means_project, axis=0).reshape(
        1, len(np.linalg.norm(means_project, axis=0)))  #1*52
    p = (1 + (data_project.T @ means_project) / (norm_x.T @ norm_means)) / 2
    return p


data = split_data()
train_im, train_l = data['train']
test_im, test_l = data['test']
train_im = train_im.T
test_im = test_im.T
train_l = train_l.T
test_l = test_l.T

height, width = (46, 56)
D = height * width
#architecture_flag = 1 # 0: Data Sampling 1: FeatureSpace Sampling
T = 60

# def rad_sum_classifier (T, train_im, train_l, test_im, test_l, D):
Num_sample, M0, M1 = 416, 150, 80
M_lda = 46
示例#2
0
import numpy as np
import matplotlib.pyplot as plt
import time

SHAPE = (46, 56)
# split data preprocessor
from Split import split_data

data = split_data('face', 0.8, 13)
X_train, Y_train = data['train']
X_test, Y_test = data['test']

print(data)

# mean face
mean_face = X_train.mean(axis=1).reshape(-1, 1)
# plt.imshow(mean_face.reshape(SHAPE).T,
#            cmap=plt.get_cmap('gray'), vmin=0, vmax=255)
# plt.title('Mean Face\n')
# plt.savefig('img/mean_face.png', dpi=1000, transparent=True)

D, N = X_train.shape
A = X_train - mean_face

t = time.time()
# high dimension
# S = (1 / N) * np.dot(A, A.T)
# low dimension
S = (1 / N) * np.dot(A.T, A)

# Calculate eigenvalues 'w' and eigenvectors 'v'