读《零次学习(Zero-Shot Learning)入门》

知乎链接
https://zhuanlan.zhihu.com/p/34656727?spm=5176.9876270.0.0.399ce44aXsg7cN

基础算法介绍

文章里没有给出详细代码,自己东拼西凑了一个,精度只有43.5%。

% load data
load('awa_demo_data.mat')

% zsl
regression_lambda = 1.0;
W = ridgeRegression(X_tr, S_tr, regression_lambda);
S_test = X_te * W;
[zsl_accuracy]= zsl_el(S_test, S_te_gt, param); 
fprintf('AwA ZSL accuracy on test set: %.1f%%\n', zsl_accuracy*100);

function [ w ] = ridgeRegression(x, y, lam)
    xTx = x'*x;
    [m,n] = size(xTx);
    temp = xTx + eye(m,n)*lam;
    if det(temp) == 0
        disp('This matrix is singular, cannot do inverse');
    end
    w = temp^(-1)*x'*y;
end

function [ acc ] = zsl_el( S_test, S_te_gt, param)
    sim = S_te_gt*S_test';
    [~, id] = max(sim);
    pre = param.testclasses_id(id);
    acc = sum(pre==param.test_labels)/length(param.test_labels);
end

你可能感兴趣的:(coding)