function [cT,iT,C]=FLNNclass(X,y,T)

%
% FLNN for Classification
%
% [classT,incT,C]=FLNNclass(X,y,T)
%
% INPUTS
% Training:
%   X=[x1,x2,x3,...,xn] is a (m x n) matrix. 
%   y=[y1,y2,y3,...,yn] is a n-dimensional vector with the class of X. 
% Test:
%   T=[t1,t2,t3,...,tq] is a (m x q) matrix for test.
%      
% OUTPUT
%  cT=[ct1,ct2,...,ctq] is a q-dimensional vector with the estimated class of T.
%  iT=[it1,it2,...,itq] is a q-dimensional vector wiht the degree of inclusion 
%                       of T in the class in the estimated class.
%   C=[C1,C2,C3,...,Cc] is a (2 m x c) matrix with the class sets as columns.
%

% Standardizing the data;
mu=mean(X,2);
sigma=std(X,[],2);
for i=1:size(X,1)
   if sigma(i)<1.e-6
      sigma(i)=1;
   end
	X(i,:)=(X(i,:)-mu(i))/sigma(i);
	T(i,:)=(T(i,:)-mu(i))/sigma(i);
end

% Data in the Unit Hypercube;
X=(1+tanh(X))/2;
T=(1+tanh(T))/2;

%
% Training
%
for c=1:max(y)
   % Patterns of class c;
   ind=find(y==c);
   % Patterns not in class c;
   indN=find(y~=c);
   C(:,c)=[inf*ones(size(X(:,1)));-inf*ones(size(X(:,1)))];
   for i=1:length(ind)
      Caux=join(C(:,c),[X(:,ind(i));X(:,ind(i))]);
      sigma=0;
      for j=1:length(indN)
         sigma=max(sigma,flim([X(:,indN(j));X(:,indN(j))],Caux));
      end
      if sigma<1
         C(:,c)=Caux;
      end
   end
end
clear sigma;

% Test
for i=1:size(T,2)
   for c=1:size(C,2)
      sigma(c)=flim([T(:,i);T(:,i)],C(:,c));
   end
   [iT(i),cT(i)]=max(sigma);
end