
addpath(spiderpath);
use_spider;

% Written by Jason Weston
res=[]; res50=[]; 
global K; global X; global Y;
rand('seed',1); randn('seed',1);

if restart==1
load spec51_matrix.txt
K=spec51_matrix;  clear spec51_matrix;
k2=sqrt(diag(K))+1e-12; k2=k2*k2'; K=K ./ k2; clear k2; % Normalize matrix
Ys=load('allseq_membership-noheaders.table'); % load data splits
name='mismatch_homologs.mat'; % name of file to save
end

for i=1:size(Ys,2) %% loop over data splits

Y=Ys(:,i);  %% allocate correct train and test set labels for this data split
l=sum(Y==1)+sum(2==Y); lt=sum(Y==3)+sum(4==Y); % test & test set sizes
[trn]=find(Y==1 | Y==2); [tst]=find(Y==3 | Y==4);
Y(trn(1:l))=sign((Y(trn(1:l))==1)-0.5); Y(tst(1:lt))=sign((Y(tst(1:lt))==3)-0.5);
%%--------------- pull in domain homologs -----------
load blast_homologs addpts; f=addpts{i};  % already cached these computations
trn=[trn ;f']; trn=unique(trn); Y(f)=1;
%% ------------------------------------------------

 
X=Y; d=data_global; dtrn=get(d,trn); dtst=get(d,tst);  % now train svm
a=svm; a.optimizer='svmlight'; a.child=kernel('custom_fast');
a.verbosity=2; a.use_signed_output=0;
a.balanced_ridge=0.02*median(diag(K));
[tr a]=train(a,dtrn); r=test(a,dtst);


rr=loss(r,'roc'); res=[res rr.Y];         % & measure roc score
rr=loss(r,'roc50'); res50=[res50 rr.Y]

end

save(name,'res','res50');







