Hi Arkram,
When using Kernel PCA (KPCA) for face recognition or any other application, the testing phase involves projecting new data (test images) into the same feature space that was used for training. Here's how you can organize and process your test data using Kernel PCA:
- Understand the Structure of Your Data
- Center and Normalize Test Data
- Apply Kernel PCA to Test Data
% Assume 'trainData' is your 400x120 training data matrix
% 'testData' is your 400x30 test data matrix
% Calculate the mean of the training data
meanTrainData = mean(trainData, 2);
% Center the test data
centeredTestData = testData - meanTrainData;
% Choose kernel parameters
sigma = 1.0; % Example value for Gaussian kernel
% Compute the kernel matrix between test and training data
K_test_train = exp(-pdist2(centeredTestData', trainData').^2 / (2 * sigma^2));
% Assume 'alpha' contains the eigenvectors obtained during training
% 'K_train' is the kernel matrix for training data
% 'eigenvalues' are the eigenvalues for the KPCA
% Project the test data into the KPCA feature space
projectedTestData = K_test_train * alpha ./ sqrt(eigenvalues');