Compute Similarity Matrix for a Clustering and vice versa
A similarity matrix is a symmetric matrix whose entry is 1 if observation i
and j
are in the same cluster and 0 otherwise.
cltoSim(cl) Simtocl(Sim)
cl
: vector of cluster membershipsSim
: similarity matrixSimtocl
does not check whether Sim
is a valid similarity matrix, e.g. that Sim[i,j]==1
if Sim[i,k]==1
and Sim[j,k]==1.
Arno Fritsch, arno.fritsch@tu-dortmund.de
comp.psm
for an average similarity matrix.
cl <- c(3,3,1,2,2) (Sim <- cltoSim(cl)) Simtocl(Sim) # not a valid similarity matrix (Sim2 <- matrix(c(1,0,1,0,1,1,1,1,1), ncol=3)) Simtocl(Sim2) # no warning
Useful links