function [C1,C2,C3] = ccm2(V,D,c)
% Modified Compatible Cluster Merging criteria as defined by Kaymak et al.
% These criteria are particularly suitable to fuzzy modelling
% applications.
%
% [C1,C2,C3] = CCM2(V,D,C)
%     Input:
%       V  ... eigenvectors of the covariance matrices, corresponding
%              to the smallest eigenvalues as supplied by the
%              Gustafson-Kessel clustering
%       D  ... eigenvalues of the covariance matrices (supplied by the
%              Gustafson-Kessel clustering)
%       C  ... cluster means matrix (centres) as supplied by the
%              Gustafson-Kessel clustering
%       
%     Output:
%       C1 ... Parallellity criterion, calculated for pairs of clusters
%       C2 ... Closeness criterion in the antecedent product space,
%              calculated for pairs of clusters
%       C3 ... Closeness criterion in the antecedent-consequent 
%              product space, calculated for pairs of clusters
%       
%       see also GKFAST, CCM
%

% (c) Uzay Kaymak, September 1995

[nc,nx] = size(V);                      % initialization
C1 = zeros(nc); C2 = C1; C3 = C1;       % initialize matrices

D = max(D');                            % calculate largest eigen value

for j = 1 : nc,                         % loop for all pairs
  for i = 1 : nc,
    if i ~= j,
      C1(i,j) = abs(V(i,:)*V(j,:)');
      C2(i,j) = norm(c(i,1:nx-1)-c(j,1:nx-1));
      C3(i,j) = norm(c(i,:)-c(j,:));
    end; 
  end; 
end;


