sparsecovariancestest2.m

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

M
29
字号
%A script to test the efficiency of sparse covariances 

clear;
rand('state',22); 

numExamples = 1000;
numFeatures = 500;
numLabels = 100;
tol = 10^-5;

%X = rand(numExamples, numFeatures);
X = sprand(numExamples, numFeatures, 0.1); 
Y = sparse(sign(rand(numExamples, numLabels)-0.5));

X = centerData(X);

Y = full(Y); 
KX = full(X*X');

%If KX is full and Y is sparse computaion is slow 
%If both are sparse computation is faster 
%If both are full, computation is much faster

for i= 1:20
    fprintf('Iteration %d\n', i); 
    [covariances, bs] = sparseCovariances(KX, KX, Y, Y, (1:numExamples)');
    %[alignments, bs] = sparseAlignments(KX, KX, Y, Y, (1:numExamples)');
end

⌨️ 快捷键说明

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