maxsparsecovariance.m
来自「a function inside machine learning」· M 代码 · 共 29 行
M
29 行
function u = maxSparseCovariance(X, y)
%A function to compute the maximum sparse covariance 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 covariance between X and Y
%We just use the example with the highest absolute covariance
numExamples = size(X, 1);
maxCovariance = -1;
Xy = X'*y;
for i=1:numExamples
v = X(i, :)';
covariance = abs(v'*Xy);
if covariance > maxCovariance
maxCovariance = covariance;
u = v;
end
end
u = u/norm(u);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?