function [Wx, Wy, r] = cca(X,Y)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- 计算协方差矩阵 ---
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
z = [X;Y];
C = cov(z.');%求协方差矩阵
sx = size(X,1);%X的纬度
sy = size(Y,1);%Y的纬度
Cxx = C(1:sx, 1:sx) + 10^(-8)*eye(sx);%x的类内协方差矩阵
Cxy = C(1:sx, sx+1:sx+sy);%x和y的类间协方差矩阵
Cyx = Cxy';
Cyy = C(sx+1:sx+sy, sx+1:sx+sy) + 10^(-8)*eye(sy);%y的类内协方差矩阵
invCyy = inv(Cyy);
% --- 计算 Wx 和 r ---
[Wx,r] = eig(inv(Cxx)*Cxy*invCyy*Cyx); % 计算x的Wx
r = sqrt(real(r)); %计算出 Canonical correlations
% Wv = Wx;
% --- Sort correlations ---
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%fliplr如下
% xr =
%
% 1 2 3 4 5
% 6 7 8 9 10
%
% >> fliplr(xr)
%
% ans =
%
% 5 4 3 2 1
% 10 9 8 7 6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
V = fliplr(Wx); % reverse order of eigenvectors
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%flipud计算如下
% X = 1 4 becomes 3 6
% 2 5 2 5
% 3 6 1 4
%flipud(X) 变为
% 3 6
% 2 5
% 1 4
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
r = flipud(diag(r)); % extract eigenvalues anr reverse their orrer
[r,I]= sort((real(r))); % sort reversed eigenvalues in ascending order
r = flipud(r); % restore sorted eigenvalues into descending order
for j = 1:length(I)
Wx(:,j) = V(:,I(j)); % sort reversed eigenvectors in ascending order
end
Wx = fliplr(Wx); % restore sorted eigenvectors into descending order
% --- 计算 Wy ---
% Wx = Wv;
Wy = invCyy*Cyx*Wx; % 计算Y的Wy
% Wy = Wy./repmat(sqrt(sum(abs(Wy).^2)),sy,1); % Normalize Wy
cca.rar_CCA_CCA matlab_cca人脸识别_cca识别代码_人脸识别
版权申诉
5星 · 超过95%的资源 144 浏览量
2022-07-14
20:41:38
上传
评论
收藏 1KB RAR 举报
周楷雯
- 粉丝: 80
- 资源: 1万+
最新资源
- 基于Java的本科探索学习项目设计源码 - 本科探索
- 基于Javascript和Python的微商城项目设计源码 - MicroMall
- 基于Java的网上订餐系统设计源码 - online ordering system
- 基于Javascript的超级美眉网络资源管理应用模块设计源码
- 基于Typescript和PHP的编程知识储备库设计源码 - study-php
- Screenshot_2024-05-28-11-40-58-177_com.tencent.mm.jpg
- 基于Dart的Flutter小提琴调音器APP设计源码 - violinhelper
- 基于JavaScript和CSS的随寻订购网页设计源码 - web-order
- 基于MATLAB的声纹识别系统设计源码 - VoiceprintRecognition
- 基于Java的微服务插件集合设计源码 - wsy-plugins
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论1