addpath('./helper/'); % --- Generate some toy values ------------------------------------------------ numclasses = 2; numclassinst = 50; Mv=50; Nd = numclasses*numclassinst; maxdoclength = 100; theta = normalizeRows(rand(numclasses,Mv))'; X = zeros(Mv,Nd); z = zeros(numclasses,Nd); for ii=1:numclasses for jj=1:numclassinst iter = (ii-1)*numclassinst+jj; z(ii,iter) = 1; %X(:,iter) = multinomial_sample(ceil(maxdoclength*rand),Mv,theta(:,ii),randseed); X(:,iter) = multsamp(ceil(maxdoclength*rand),theta(:,ii)); end end I = randperm(Nd); % not really necessary to randperm z = [-1 1]*z(:,I); % convert cannonical labeling schema for SVM binary classification X = X(:,I); % --- Create and save Kernel -------------------------------------------------- c = 1; t = 0.96; T = translation(X,c,t); [ED2 A] = transD2(X,T); % --- Classification ---------------------------------------------------------- % TODO: CV junk here; in the interim X = normalizeRows(X')'; I = 1:75; J = 76:100; % jvd: the kth column of X corresponds to the kth row and the kth col of K trn_vects = X(:,I); trn_labels = z(I); trn_ids=I; tst_vects = X(:,J); tst_labels = z(J); tst_ids=J; %rbf kernel under translated distances fprintf('(translated) RBF Kernel (c=%f, t=%f)\n',c,t); floatfmt = '%.16g'; K_file = mktemp('/noback/lowbow/translation/tmp/K.XXXXX.mtx'); svmflags = [' -t 4 -u "' K_file '" ']; trbfgamma = [.125 .25 .5 1 2]; for ii=1:length(trbfgamma) K = exp(-trbfgamma(ii) * ED2); nulldocK = exp(-trbfgamma(ii) * A); svmWriteKernel(K,nulldocK,K_file,floatfmt); tacc(ii) = svmWrapper( trn_vects, trn_labels, trn_ids,... tst_vects, tst_labels, tst_ids, svmflags, 0 ); fprintf('\ttrbfgamma=%f\ttacc=%f\n',trbfgamma(ii),tacc(ii)/length(tst_ids)); end system(['rm ' K_file]); % (standard) rbf kernel fprintf('(standard) RBF Kernel\n'); rbfgamma = [.05 .08 .125 .25 .375 .5 .625 .75 .875 1 2]; for ii=1:length(rbfgamma) svmflags = ['-t 2 -g ' num2str(rbfgamma(ii)) ' ']; acc(ii) = svmWrapper( trn_vects, trn_labels, trn_ids,... tst_vects, tst_labels, tst_ids, svmflags, 0 ); fprintf('\trbfgamma=%f\tacc=%f\n',rbfgamma(ii),acc(ii)/length(tst_ids)); end