function [w, gamma, alpha, alphaHat, obj, iters, time] = ...
    asvr(A,y,epsilon,C,tol,maxIter,normalize);
% ASVR Active Set Support Vector Machine methodology
%   ASVR solves a support vector machine problem using an active set
%   methodology. Minimally, it takes the following arguments:
%
%   w = asvr(A,y)
%
%   where A is the data matrix, y is the vector of values to be
%   predicted,and w is the vector of coefficients for the regression
%   hyperplane.
%
%   The optional arguments are as follows:
%
%   epsilon is the size of the "insensitive tube". Default = 0.1.
%
%   C is the emphasis to be placed on minimizing regression error (as
%   opposed to regularization). Default C = 1/number of points.
%
%   tol is the value used in the stopping criterion. Default tol = 1e-3.
%
%   maxIter is the maximum number of iterations. Default maxIter = 100.
%
%   converge should be set to 0 if the optional convergence checking
%   should be ignored. This may lead to the algorithm getting 'stuck.'
%   Default value = 1.
%
%   normalize should be set to 1 if the data should be normalized before 
%   training. Default value = 0.
%
%   prompt should be set to 0 if ASVR should not prompt the user to stop
%   if the algorithm seems stuck. Default value = 1.
%
%   The value -1 can be used for any of the entries (except A and y) to
%   specify that default values should be used.
%
%   Copyright (C) 2002 David R. Musicant and Alexander Feinberg
%   Version 1.0 Beta
%   This software is free for academic use only.
%   For commercial use, contact dmusican@carleton.edu.

  m = size(A,1);
  e = ones(size(A,1),1);
  
  % Check that y is a vector of the appropriate size.
  if (size(y,2) ~= 1)
    y = y';
  end;
  if (size(y,1) ~= m)
    error('Number of points in A and y do not match.')
  end;

  if ~exist('C') | C==-1
    C = 1/m;
  end;
  if ~exist('epsilon') | epsilon==-1
    epsilon = 0.1;
  end;
  if ~exist('tol') | tol==-1
    tol = 1e-3;
  end;
  if ~exist('maxIter') | maxIter==-1
    maxIter = 100;
  end;
  if ~exist('converge') | converge==-1
    converge = 1;
  end;
  if ~exist('normalize') | normalize==-1
    normalize = 0;
  end;
  if ~exist('prompt') | prompt==-1
    prompt = 1;
  end;

  % D is the emphasis on minimizing gamma^2, which we just fix at 1
  % to keep the number of parameters to vary to a minimum
  D = 1;
  [w, gamma, obj, time, iters] = ...
      asvrmex(A,y,epsilon,C,D,tol,maxIter,converge,normalize,prompt);
  if all(w==0) & gamma==0
    disp(sprintf('Degenerate solution obtained. Perturbing and rerunning.'));
    perturb = 0.001;
    A = A + rand(size(A))*perturb;
    [w, gamma, obj, time, iters] = ...
	asvrmex(A,y,epsilon,C,D,tol,maxIter,converge,normalize,prompt);
  end;

  return;
