maxsparsetargetalignment.m

来自「a function inside machine learning」· M 代码 · 共 31 行

M
31
字号
function u = maxSparseTargetAlignment(X, y)
%A function to compute the maximum sparse target alignment vector between matrix X
%and vector y
%
%inputs 
%X data matrix with examples as rows 
%y labels column vector 
%
%outputs 
%u the vector which maximises the sparse empirical target alignment between X and Y 

%We just use the example with the highest kernel target alignment 

numExamples = size(X, 1); 
maxAlignment = -1; 

Xy = X'*y; 
varX = X'*X; 

for i=1:numExamples
    v = X(i, :)'; 
    alignment = (v'*Xy)^2/(numExamples*(v'*varX*v)); 
    
    if alignment > maxAlignment 
        maxAlignment = alignment; 
        u = v;  
    end
end 

%u = u/norm(u); 
u = u/sqrt(u'*varX*u);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?