
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%  Title: StatisCLAS: A Package of Classification Methods   %%%%
%%%%  Author: David Casado de Lucas                            %%%%
%%%%  Version: 29th May 2013                                   %%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% PURPOSE: This function implements distances between curves (functional data).

% INPUT VARIABLES:
%    numberFDdistance: Number of the distance to be applied.
%    X: Matrix with curves as rows.
%    y: Vector with a curve.

% OUTPUT VARIABLES:
%    output: Vector giving the value of the distance from each row of X to y.

% COMMENTS:
%   (1) To exploit the benefits of the matricial calculations, X can be a matrix.
%   (2) The user can add new distances.

function output = distancesFD(numberFDdistance, X, y)

switch numberFDdistance
  case 0  % Distance L_infinite or maximum distance
    output = max(abs(X-nncopy(y,size(X,1),1)),[],2);
  case 1  % Distance L1
    output = sum(abs(X-nncopy(y,size(X,1),1)),2)/size(X,2);
  case 2  % Distance L2
    output = sqrt(sum((X-nncopy(y,size(X,1),1)).^2,2)/size(X,2));
end

end
