NumSilToClusterSil {parallelpam} | R Documentation |
NumSilToClusterSil
Description
Takes a silhouette in the form of a NumericVector, as returned by CalculateSilhouette, and returns it as a numeric matrix appropriate to be plotted by the package 'cluster'
Usage
NumSilToClusterSil(cl, s)
Arguments
cl |
The array of classification with the number of the class to which each point belongs to. This number must be in 1..number_of_classes. |
s |
The numeric value of the silhouette for each point, with points in the same order as they appear in cl. |
Value
sp A silhouette in the format of the cluster package which is a NumericMatrix with as many rows as points and three columns: cluster, neighbor and sil_width.
Its structure and dimension names are as in package 'cluster', which allows to use it with the silhouette plotting functions of such package
This means you can do library(cluster) followed by plot(NumSilToClusterSil(cl,s)) to get a beatiful plot.
Examples
# Synthetic problem: 10 random seeds with coordinates in [0..20]
# to which random values in [-0.1..0.1] are added
M<-matrix(0,100,500)
rownames(M)<-paste0("rn",c(1:100))
for (i in (1:10))
{
p<-20*runif(500)
Rf <- matrix(0.2*(runif(5000)-0.5),nrow=10)
for (k in (1:10))
{
M[10*(i-1)+k,]=p+Rf[k,]
}
}
tmpfile1=paste0(tempdir(),"/pamtest.bin")
JWriteBin(M,tmpfile1,dtype="float",dmtype="full")
tmpdisfile1=paste0(tempdir(),"/pamDL2.bin")
CalcAndWriteDissimilarityMatrix(tmpfile1,tmpdisfile1,distype="L2",restype="float",nthreads=0)
L <- ApplyPAM(tmpdisfile1,10,init_method="BUILD")
sil <- CalculateSilhouette(L$clasif,tmpdisfile1)
sp <- NumSilToClusterSil(L$clasif,sil)
library(cluster)
plot(sp)