开始运行程序没问题,后面在今天用的时候突然提示“索引超出矩阵维度。”我代码和数据集都没换过。。。不知道原因,求大神解一下
function [acc,G,Cls] = GFK(X_src,Y_src,X_tar,Y_tar,dim)
Ps = pca(X_src);
Pt = pca(X_tar);
G = GFK_core([Ps,null(Ps')], Pt(:,1:dim));
[Cls, acc] = my_kernel_knn(G, X_src, Y_src, X_tar, Y_tar);
end
function G = GFK_core(Q,Pt)
N = size(Q,2); %
dim = size(Pt,2);
% compute the principal angles
QPt = Q' * Pt;
[V1,V2,V,Gam,Sig] = gsvd(QPt(1:dim,:), QPt(dim+1:end,:));
V2 = -V2;
theta = real(acos(diag(Gam))); % theta is real in theory. Imaginary part is due to the computation issue.
% compute the geodesic flow kernel
eps = 1e-20;
B1 = 0.5.*diag(1+sin(2*theta)./2./max(theta,eps));
B2 = 0.5.*diag((-1+cos(2*theta))./2./max(theta,eps));
B3 = B2;
B4 = 0.5.*diag(1-sin(2*theta)./2./max(theta,eps));
G = Q * [V1, zeros(dim,N-dim); zeros(N-dim,dim), V2] ...
* [B1,B2,zeros(dim,N-2*dim);B3,B4,zeros(dim,N-2*dim);zeros(N-2*dim,N)]...
* [V1, zeros(dim,N-dim); zeros(N-dim,dim), V2]' * Q';
end