%
% The SVM.1 approach in the paper:
%
% David D. Lewis, Yiming Yang, Tony G. Rose, and Fan Li.
% RCV1: A new benchmark collection for text categorization research.
% Journal of Machine Learning Research, 5:361-397, 2004.
%
% We use liblinear as the classifier. 
% The classification algorithm can be either l2-loss, l1-loss SVM or logistic regression

function rcv1_lineart_col(dataset, algorithm, swap_option)

  switch algorithm
    case 'lr'
      options = ['-s 0 -c 20 -B 1 -e 0.5'];
    case 'l2svm_dual'
      options = ['-s 1 -c 1 -B 1 -e 0.5'];
    case 'l2svm'
      options = ['-s 2 -c 1 -B 1 -e 0.5'];
    case 'l1svm_dual'
      options = ['-s 3 -c 1 -B 1 -e 0.5'];
    otherwise
      disp('INFO: Unkown option');
      return
  end

  % shall we swap training/testing set?
  swap = 0;
  if nargin == 3 && strcmp(swap_option, 'swap')
    swap = 1;
  end

  disp('INFO: loading training data')
  load rcv1_train.mat
  disp('INFO: loading testing data')
  load rcv1_test.mat

  d = struct;
  td = struct;
  d.x = rcv1_x;
  td.x = rcv1_tx;

  switch dataset
    case 'topics'
      d.y = rcv1_topics_y;
      d.map = rcv1_topics_map;
      td.y = rcv1_topics_ty;
      td.map = rcv1_topics_tmap;
    case 'regions'
      d.y = rcv1_regions_y;
      d.map = rcv1_regions_map;
      td.y = rcv1_regions_ty;
      td.map = rcv1_regions_tmap;
    case 'industries'
      d.y = rcv1_industries_y;
      d.map = rcv1_industries_map;
      td.y = rcv1_industries_ty;
      td.map = rcv1_industries_tmap;
    otherwise
      disp('INFO: Unkown dataset')
      return
  end

  if swap
    newbinary(td, d, options);
  else
    newbinary(d, td, options);
  end