% data splitting
load tutorial_data.mat XT LT

rand('seed', 8947584375) ;
p=randperm(size(XT,2)) ;
XTE=XT(:,p(1:20000)) ;
LTE=LT(:,p(1:20000)) ;
XT=XT(:,p(20001:30000)) ;
LT=LT(:,p(20001:30000)) ;
%XT=XT(:,p(1:10000)) ;
%LT=LT(:,p(1:10000)) ;

cache_size = 100 ;
for order    = 1:8 % length of strings
  C        = 1000 ;     % regularization paramter
  
  sg( 'send_command', 'clean_features TRAIN' );
  sg( 'send_command', 'clean_preproc' );
  sg( 'send_command', 'clean_kernel');

  sg( 'send_command', 'svm_epsilon 1e-6');
  sg( 'send_command', 'loglevel ALL') ; % for debugging
  if order>2, 
    % faster training & testing
    sg( 'send_command', 'use_linadd 1');
    sg( 'send_command', 'use_batch_computation 1');
  else
    % avoid numerical difficulties
    sg( 'send_command', 'use_linadd 0');
    sg( 'send_command', 'use_batch_computation 0');
  end ;
  
  sg( 'set_labels', 'TRAIN', LT) ;
  sg( 'set_features', 'TRAIN', XT, 'DNA') ;
  sg('send_command', sprintf('set_kernel WEIGHTEDDEGREE CHAR %i %i %i', cache_size, order, 0)) ;
  sg( 'send_command', 'init_kernel TRAIN' );

  %sg( 'send_command', 'new_svm LIBSVM') ;
  sg( 'send_command', 'new_svm LIGHT') ;
  sg( 'send_command', sprintf( 'c %1.2e', C ) );
  sg( 'send_command', 'svm_train' );

  sg('send_command', 'clean_features TEST' );
  sg('set_features', 'TEST', XTE, 'DNA') ;
  sg('send_command', 'init_kernel TEST' );
  
  O = sg( 'svm_classify' );
  ROC(order)=calcrocscore(O, LTE)
end ;
