function X = svdatanorm(X,ker,isotropic)
%SVDATANORM normalises the data X for the kernel ker 
%
%  Usage: svdatanorm(X,ker)
%
%  Parameters: X         - training data
%              ker       - kernel type
%              isotropic - isotropic (1:default) or anisotropic (0) scaling
%              
%  Author: Steve Gunn (srg@ecs.soton.ac.uk)

  if (nargin <2 | nargin>3) % check correct number of arguments
     help svdatanorm
  else
    if (nargin < 3) isotropic = 1;, end
 
    switch lower(ker)
      case {'spline'}
        lb = 0;, ub = 2;
      case {'fourier'}
        lb = -pi/2;, ub = pi/2;
      otherwise
        lb = -1;, ub = 1;
    end
    
    n = size(X,2); % input dimension 
    sca = zeros(n,1);
    mina = zeros(n,1);
    maxa = zeros(n,1);
    for i=1:n
       mina(i) = min(X(:,i));
       maxa(i) = max(X(:,i));
       sca(i) = maxa(i) - mina(i);
    end
    
    if (isotropic)
       scamax = max(sca);
       for i=1:n
          if scamax
            X(:,i) = (ub - lb)*( X(:,i) - mina(i) )/scamax + lb;
          end
       end
    else
       for i=1:n
          if sca(i)
             X(:,i) = (ub - lb)*( X(:,i) - mina(i) )/sca(i) + lb;
          end
       end
    end
           
  end
