THE MATLAB CODE OF CANONICAL CORRELATION ANALYSIS (CCA)
2016-10-08 21:46
1581 查看
THE MATLAB CODE OF CANONICAL CORRELATION ANALYSIS (CCA)
转自:http://www.cppblog.com/guijie/archive/2015/06/02/210807.html%Reference: the matlab code of "CVPR 2011 Iterative Quantization". I have checked the correctness of the corresponding derivation and matlab code. No need to check again. Just use it
function [Wx, r] = cca(X,Y,reg)
%
% X is input data for the 1st view (image), n*d, n images, d dim
% Y is input data for the 2nd view (Tag), n*D, D dim
% reg is regularization parameter, usually set by validation
% in our work, reg = 0.0001 which works well
%
% Wx is the embedding function for image
% r is the eigenvalue
%
%
% to run the code, you need visual data X and tag data Y
%
% bit = 32, 64, 128 ...
% [eigenvector,r] = cca(X, Y, 0.0001); % this computes CCA projections
% eigenvector = eigenvector(:,1:bit)*diag(r(1:bit)); % this performs a scaling using eigenvalues
% E = X*eigenvector; % final projection to obtain embedding E
%
z = [X, Y];
C = cov(z);
sx = size(X,2);
sy = size(Y,2);
Cxx = C(1:sx, 1:sx) + reg*eye(sx);
Cxy = C(1:sx, sx+1:sx+sy);
Cyx = Cxy';
Cyy = C(sx+1:sx+sy,sx+1:sx+sy) + reg*eye(sy);
Rx = chol(Cxx);
invRx = inv(Rx);
Z = invRx'*Cxy*(Cyy\Cyx)*invRx;
Z = 0.5*(Z' + Z);
[Wx,r] = eig(Z); % basis in h (X)
r = sqrt(real(r)); % as the original r we get is lamda^2
Wx = invRx * Wx; % actual Wx values
r = diag(r);
[r index] = sort(r,'descend');
Wx = Wx(:,index);
相关文章推荐
- Canonical Correlation Analysis(CCA) 典型相关分析
- C#也能写病毒,源代码分析 the analysis of C# virus source code
- get the code of function in matlab
- The Ultimate List of Open Source Static Code Analysis Security Tools
- the design principles and code analysis of hibernate lazy loading
- C#也能写病毒,源代码分析 the analysis of C# virus source code
- The Logbook of Qt Source Code Reading(1)
- 企业财务报表的分析方法(The analysis of financial statements)
- The analysis of project robot rat
- how to compile source code of "Data Structures & Algorithm Analysis in Java" writen by Mark Allen Weiss
- 20 issues of porting C++ code on the 64-bit platform
- Effective C# Item 10: Understand the Pitfalls of GetHashCode()
- Code snippet of the day : Get Chinese Spell in C#
- What's the effect of hashCode() & equals() when adding object to List/Set/Map
- 代码的规范化:《Refactoring: Improving the Design of Existing Code》
- The Analysis of My Own Procrastination
- How to find the source code of the special command?
- BUG: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
- Code snippet of the day : persist the scroll position of an ASP.NET page
- The tow way of Debugging Scripting Code(郁闷了好久,终于找到了解决办法)