% what do the simple approaches give?
load cellssimplevar;
gaborvar_train = a; gaborvar_test = b;
load cellssimplemax;
gabormax_train = a; gabormax_test = b;
load cellssimplemean;
gabormean_train = a; gabormean_test = b;
gabor_data=[gabor_train;gabor_test];
load cells_lbp_mask; gencellsimple
lbp_train = a; lbp_test = b;
load cells_lbp_gauss3; gencellsimple
lbpold_train = a; lbpold_test = b;


% param:
%dim_gabor = size(gabor_train,2);
%dim_lbp = size(lbp_train,2);
%dim = dim_gabor+dim_lbp;
%u = [featsel(dim,1:dim_gabor)*ldc featsel(dim,dim_gabor+(1:dim_lbp))*ldc]*meanc;
%u = fisherm([],4)*knnc;
%u = combinerm(ldc([],0,1e-5),gaborvar_train,gabormax_train,gabormean_train,lbp_train,lbpold_train)*ldc([],0,1e-5);
u = combinerm(loglc2,gaborvar_train,gabormax_train,gabormean_train,lbp_train,lbpold_train)*maxc;
%u = knnc;
u = loglc2;
u = scalem([],'variance')*libsvc;



% train and test:
w = [gaborvar_train gabormax_train gabormean_train lbp_train lbpold_train]*u;
error_on_testset = [gaborvar_test gabormax_test gabormean_test lbp_test lbpold_test]*w*testc


% crossval on all data a:
a = [[gaborvar_train;gaborvar_test] [gabormax_train;gabormax_test] ...
  [gabormean_train;gabormean_test] [lbp_train;lbp_test] ...
  [lbpold_train;lbpold_test]];

imlab = getident(a,'image');
[nlab,baglab] = renumlab(imlab);
nrfolds = length(baglab); % leave one image out

e = zeros(nrfolds,1);
Iall = (1:size(nlab,1))';

for i=1:nrfolds
   Jtst = find(nlab==i);
   Jtrn = Iall; Jtrn(Jtst)=[];

   i
   x = a(Jtrn,:);
   z = a(Jtst,:);
   %f(i) = find(classsizes(z)>0)

   w = x*u;
   e(i,1) = z*w*testd;
   %e(i,1)
end
e
mean(e)
error_on_testset


