Re: [R] clustering fuzzy
After ordering the table of membership degrees , i must get the difference between the first and second coloumns , between the first and second largest membership degree of object i. This for K=2,K=3,to K.max=6. This difference is multiplyed by the Crisp silhouette index vector (si). Too it dependending on K=2,...,K.max=6; the result divided by the sum of these differences I need a final vector composed of the indexes for each clustering (K=2,...,K.max=6). There is a method, i think that is classe.memb, but i can't to solve problem because trasformation of the membership degrees matrix( (ris$membership) and of list object (ris$silinfo), does not permitme to use classe.memb propertyes. . Σí(uί1-uí2)sí/Σí(uí1-uí2) head(t(A.sort)) membership degrees table ordering by max to min value [,1] [,2] [,3] [,4] 1 0.66 0.30 0.04 0.01 2 0.89 0.09 0.02 0.00 3 0.92 0.06 0.01 0.01 4 0.71 0.21 0.07 0.01 5 0.85 0.10 0.04 0.01 6 0.91 0.04 0.02 0.02 head(t(A.sort)) [,1] [,2] [,3] [,4] 1 0.66 0.30 0.04 0.01 2 0.89 0.09 0.02 0.00 3 0.92 0.06 0.01 0.01 4 0.71 0.21 0.07 0.01 5 0.85 0.10 0.04 0.01 6 0.91 0.04 0.02 0.02 H.Asort=head(t(A.sort)) H.Asort[,1]-H.Asort[,2] 123456 0.36 0.80 0.86 0.50 0.75 0.87 H.Asort=t(H.Asort[,1]-H.Asort[,2]) This is the differences vector by multiplying trasformed table ris$silinfo. ris$silinfo $widths cluster neighbor sil_width 72 13 0.43820207 54 13 0.43427773 29 16 0.41729079 62 16 0.40550562 64 16 0.32686757 32 13 0.30544722 45 13 0.30428723 79 13 0.30192624 12 13 0.30034472 60 16 0.29642495 41 13 0.29282778 113 0.28000788 85 13 0.24709237 74 13 0.239 P=ris$silinfo P=P[1] P=as.data.frame(P) V4=rownames(P) mode(V4)=numeric P[,4]=V4 P[order(P$V4),] widths.cluster widths.neighbor widths.sil_width V4 1 1 3 0.28000788 1 2 2 4 0.07614849 2 3 2 3 -0.11676440 3 4 2 4 0.15436648 4 5 2 3 0.14693927 5 6 3 1 0.57083836 6 7 4 5 0.36391826 7 8 5 4 0.63491118 8 9 4 2 0.54458733 9 10 5 4 0.51059626 10 11 2 5 0.03908952 11 12 1 3 0.30034472 12 13 1 3 -0.04928562 13 14 4 3 0.20337180 14 15 3 4 0.46164324 15 18 5 4 0.52066782 18 20 4 3 0.45517287 20 21 3 4 0.39405507 21 22 4 5 0.05574547 22 23 6 1 -0.06750403 23 P= P[order(P$V4),] P=P[,3] This is trasformed vector ris$silinfo =P. I can't to use this vector object in the classe.memb. K=2 K.max=6 while (K=K.max) { ris=fanny(frj,K,memb.exp=m,metric=SqEuclidean,stand=TRUE,maxit=1000,tol=1e-6) ris$centroid=matrix(0,nrow=K,ncol=J) for (k in 1:K) { ris$centroid[k,]=(t(ris$membership[,k]^m)%*%as.matrix(frj))/sum(ris$membership[,k]^m) } rownames(ris$centroid)=1:K colnames(ris$centroid)=colnames(frj) print(K) print(round(ris$centroid,2)) print(classe.memb(ris$membership)$table.U) print(ris$silinfo$avg.width) K=K+1 } this should be scheme clearly are determined centroid based on classe.memb. classe.memb=function(U) { info.U=cbind(max.col(U),apply(U,1,max)) i=1 while (i = nrow(U)) { if (apply(U,1,max)[i]0.5) info.U[i,1]=0 i=i+1 } K=ncol(U) table.U=matrix(0,nrow=K,ncol=4) cl=1 while (cl = K) { table.U[cl,1] = length(which(info.U[info.U[,1]==cl,2]=.90)) table.U[cl,2] = length(which(info.U[info.U[,1]==cl,2]=.70)) - table.U[cl,1] table.U[cl,3] = length(which(info.U[info.U[,1]==cl,2]=.50)) - table.U[cl,1] - table.U[cl,2] table.U[cl,4] = sum(table.U[cl,]) cl = cl+1 } rownames(table.U) = c(1:K) colnames(table.U) = c(Alto, Medio, Basso, Totale) out=list() out$info.U=round(info.U,2) out$table.U=table.U return(out) } -- View this message in context: http://r.789695.n4.nabble.com/clustering-fuzzy-tp3229853p3261837.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] clustering fuzzy
After ordering the table of membership degrees , i must get the difference between the first and second coloumns , between the first and second largest membership degree of object i. This for K=2,K=3,to K.max=6. This difference is multiplyed by the Crisp silhouette index vector (si). Too it dependending on K=2,...,K.max=6; the result divided by the sum of these differences I need a final vector composed of the indexes for each clustering (K=2,...,K.max=6). There is a method, i think that is classe.memb, but i can't to solve problem because trasformation of the membership degrees matrix( (ris$membership) and of list object (ris$silinfo), does not permitme to use classe.memb propertyes. . Σí(uί1-uí2)sí/Σí(uí1-uí2) head(t(A.sort)) membership degrees table ordering by max to min value [,1] [,2] [,3] [,4] 1 0.66 0.30 0.04 0.01 2 0.89 0.09 0.02 0.00 3 0.92 0.06 0.01 0.01 4 0.71 0.21 0.07 0.01 5 0.85 0.10 0.04 0.01 6 0.91 0.04 0.02 0.02 head(t(A.sort)) [,1] [,2] [,3] [,4] 1 0.66 0.30 0.04 0.01 2 0.89 0.09 0.02 0.00 3 0.92 0.06 0.01 0.01 4 0.71 0.21 0.07 0.01 5 0.85 0.10 0.04 0.01 6 0.91 0.04 0.02 0.02 H.Asort=head(t(A.sort)) H.Asort[,1]-H.Asort[,2] 123456 0.36 0.80 0.86 0.50 0.75 0.87 H.Asort=t(H.Asort[,1]-H.Asort[,2]) This is the differences vector by multiplying trasformed table ris$silinfo. ris$silinfo $widths cluster neighbor sil_width 72 13 0.43820207 54 13 0.43427773 29 16 0.41729079 62 16 0.40550562 64 16 0.32686757 32 13 0.30544722 45 13 0.30428723 79 13 0.30192624 12 13 0.30034472 60 16 0.29642495 41 13 0.29282778 113 0.28000788 85 13 0.24709237 74 13 0.239 P=ris$silinfo P=P[1] P=as.data.frame(P) V4=rownames(P) mode(V4)=numeric P[,4]=V4 P[order(P$V4),] widths.cluster widths.neighbor widths.sil_width V4 1 1 3 0.28000788 1 2 2 4 0.07614849 2 3 2 3 -0.11676440 3 4 2 4 0.15436648 4 5 2 3 0.14693927 5 6 3 1 0.57083836 6 7 4 5 0.36391826 7 8 5 4 0.63491118 8 9 4 2 0.54458733 9 10 5 4 0.51059626 10 11 2 5 0.03908952 11 12 1 3 0.30034472 12 13 1 3 -0.04928562 13 14 4 3 0.20337180 14 15 3 4 0.46164324 15 18 5 4 0.52066782 18 20 4 3 0.45517287 20 21 3 4 0.39405507 21 22 4 5 0.05574547 22 23 6 1 -0.06750403 23 P= P[order(P$V4),] P=P[,3] This is trasformed vector ris$silinfo =P. I can't to use this vector object in the classe.memb. K=2 K.max=6 while (K=K.max) { ris=fanny(frj,K,memb.exp=m,metric=SqEuclidean,stand=TRUE,maxit=1000,tol=1e-6) ris$centroid=matrix(0,nrow=K,ncol=J) for (k in 1:K) { ris$centroid[k,]=(t(ris$membership[,k]^m)%*%as.matrix(frj))/sum(ris$membership[,k]^m) } rownames(ris$centroid)=1:K colnames(ris$centroid)=colnames(frj) print(K) print(round(ris$centroid,2)) print(classe.memb(ris$membership)$table.U) print(ris$silinfo$avg.width) K=K+1 } this should be scheme clearly are determined centroid based on classe.memb. classe.memb=function(U) { info.U=cbind(max.col(U),apply(U,1,max)) i=1 while (i = nrow(U)) { if (apply(U,1,max)[i]0.5) info.U[i,1]=0 i=i+1 } K=ncol(U) table.U=matrix(0,nrow=K,ncol=4) cl=1 while (cl = K) { table.U[cl,1] = length(which(info.U[info.U[,1]==cl,2]=.90)) table.U[cl,2] = length(which(info.U[info.U[,1]==cl,2]=.70)) - table.U[cl,1] table.U[cl,3] = length(which(info.U[info.U[,1]==cl,2]=.50)) - table.U[cl,1] - table.U[cl,2] table.U[cl,4] = sum(table.U[cl,]) cl = cl+1 } rownames(table.U) = c(1:K) colnames(table.U) = c(Alto, Medio, Basso, Totale) out=list() out$info.U=round(info.U,2) out$table.U=table.U return(out) } -- View this message in context: http://r.789695.n4.nabble.com/clustering-fuzzy-tp3229853p3255223.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] clustering fuzzy
I must get an index (fuzzy silhouette), a weighted average. A average the crisp silhouette for every row (i) s and the weight of each term is determined by the difference between the membership degrees of corrisponding object to its first and second best matching fuzzy clusters. i need the difference between values the first and second coloumns for every row (i) to be multiplied with a index(Crisp silhouette) s on each unit (row) and then divide by the sum of all these differences jholtman wrote: use 'apply': head(x.m) V2 V3 V4 V5 [1,] 0.66 0.04 0.01 0.30 [2,] 0.02 0.89 0.09 0.00 [3,] 0.06 0.92 0.01 0.01 [4,] 0.07 0.71 0.21 0.01 [5,] 0.10 0.85 0.04 0.01 [6,] 0.91 0.04 0.02 0.02 x.m.sort - apply(x.m, 1, sort, decreasing = TRUE) head(t(x.m.sort)) [,1] [,2] [,3] [,4] [1,] 0.66 0.30 0.04 0.01 [2,] 0.89 0.09 0.02 0.00 [3,] 0.92 0.06 0.01 0.01 [4,] 0.71 0.21 0.07 0.01 [5,] 0.85 0.10 0.04 0.01 [6,] 0.91 0.04 0.02 0.02 On Fri, Jan 21, 2011 at 10:07 AM, pete pierole...@hotmail.it wrote: hello, i'm pete ,how can i order rows of matrix by max to min value? I have a matrix of membership degrees, with 82 (i) rows and K coloumns, K are clusters. I need first and second largest elements of the i-th row. for example 1 0.66 0.04 0.01 0.30 2 0.02 0.89 0.09 0.00 3 0.06 0.92 0.01 0.01 4 0.07 0.71 0.21 0.01 5 0.10 0.85 0.04 0.01 6 0.91 0.04 0.02 0.02 7 0.00 0.01 0.98 0.00 8 0.02 0.05 0.92 0.01 9 0.05 0.54 0.40 0.01 10 0.02 0.06 0.92 0.00 11 0.05 0.55 0.39 0.01 12 0.77 0.02 0.01 0.20 13 0.95 0.01 0.00 0.04 14 0.43 0.33 0.18 0.06 15 0.79 0.10 0.08 0.03 18 0.02 0.04 0.94 0.00 20 0.09 0.15 0.76 0.01 21 0.80 0.10 0.07 0.03 22 0.06 0.15 0.79 0.01 23 0.05 0.01 0.00 0.94 24 0.83 0.02 0.01 0.15 25 0.87 0.05 0.03 0.04 27 0.76 0.10 0.11 0.03 28 0.17 0.68 0.10 0.05 29 0.10 0.01 0.00 0.90 30 0.09 0.29 0.60 0.01 31 0.05 0.01 0.00 0.94 32 0.53 0.04 0.01 0.43 33 0.85 0.04 0.02 0.09 34 0.82 0.06 0.02 0.10 35 0.76 0.07 0.02 0.14 37 0.36 0.31 0.30 0.02 38 0.01 0.02 0.97 0.00 39 0.12 0.04 0.02 0.82 40 0.02 0.00 0.00 0.97 41 0.57 0.15 0.02 0.25 42 0.14 0.03 0.02 0.82 43 0.89 0.06 0.01 0.03 44 0.02 0.00 0.00 0.98 45 0.61 0.02 0.01 0.36 46 0.03 0.00 0.00 0.97 47 0.88 0.07 0.02 0.03 48 0.06 0.60 0.32 0.02 49 0.01 0.98 0.01 0.00 50 0.06 0.88 0.05 0.01 51 0.01 0.05 0.93 0.00 52 0.02 0.08 0.90 0.00 53 0.11 0.01 0.01 0.87 54 0.27 0.01 0.00 0.72 55 0.94 0.03 0.01 0.02 58 0.45 0.41 0.05 0.09 59 0.12 0.61 0.22 0.05 60 0.26 0.07 0.02 0.64 61 0.17 0.19 0.62 0.02 62 0.08 0.00 0.00 0.92 63 0.02 0.94 0.03 0.00 64 0.08 0.01 0.00 0.91 65 0.98 0.01 0.00 0.01 67 0.22 0.69 0.08 0.01 68 0.96 0.02 0.00 0.02 69 0.96 0.02 0.01 0.01 71 0.00 0.01 0.98 0.00 72 0.56 0.05 0.01 0.37 73 0.10 0.01 0.01 0.88 74 0.91 0.01 0.00 0.08 75 0.36 0.38 0.21 0.05 76 0.15 0.40 0.44 0.01 77 0.02 0.06 0.91 0.00 78 0.48 0.43 0.03 0.06 79 0.51 0.02 0.01 0.45 80 0.04 0.01 0.00 0.95 81 0.47 0.03 0.01 0.49 82 0.98 0.01 0.00 0.01 83 0.05 0.01 0.01 0.93 84 0.03 0.00 0.00 0.96 85 0.76 0.07 0.01 0.15 86 0.95 0.03 0.01 0.01 88 0.03 0.00 0.00 0.96 90 0.79 0.13 0.02 0.06 91 0.37 0.50 0.05 0.09 92 0.86 0.10 0.02 0.02 93 0.13 0.82 0.03 0.01 A[1,][order(A[1,],decreasing=TRUE)] [1] 0.66 0.30 0.04 0.01 I want this for every row thank you -- View this message in context: http://r.789695.n4.nabble.com/clustering-fuzzy-tp3229853p3229853.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://r.789695.n4.nabble.com/clustering-fuzzy-tp3229853p3231477.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] clustering fuzzy
use 'apply': head(x.m) V2 V3 V4 V5 [1,] 0.66 0.04 0.01 0.30 [2,] 0.02 0.89 0.09 0.00 [3,] 0.06 0.92 0.01 0.01 [4,] 0.07 0.71 0.21 0.01 [5,] 0.10 0.85 0.04 0.01 [6,] 0.91 0.04 0.02 0.02 x.m.sort - apply(x.m, 1, sort, decreasing = TRUE) head(t(x.m.sort)) [,1] [,2] [,3] [,4] [1,] 0.66 0.30 0.04 0.01 [2,] 0.89 0.09 0.02 0.00 [3,] 0.92 0.06 0.01 0.01 [4,] 0.71 0.21 0.07 0.01 [5,] 0.85 0.10 0.04 0.01 [6,] 0.91 0.04 0.02 0.02 On Fri, Jan 21, 2011 at 10:07 AM, pete pierole...@hotmail.it wrote: hello, i'm pete ,how can i order rows of matrix by max to min value? I have a matrix of membership degrees, with 82 (i) rows and K coloumns, K are clusters. I need first and second largest elements of the i-th row. for example 1 0.66 0.04 0.01 0.30 2 0.02 0.89 0.09 0.00 3 0.06 0.92 0.01 0.01 4 0.07 0.71 0.21 0.01 5 0.10 0.85 0.04 0.01 6 0.91 0.04 0.02 0.02 7 0.00 0.01 0.98 0.00 8 0.02 0.05 0.92 0.01 9 0.05 0.54 0.40 0.01 10 0.02 0.06 0.92 0.00 11 0.05 0.55 0.39 0.01 12 0.77 0.02 0.01 0.20 13 0.95 0.01 0.00 0.04 14 0.43 0.33 0.18 0.06 15 0.79 0.10 0.08 0.03 18 0.02 0.04 0.94 0.00 20 0.09 0.15 0.76 0.01 21 0.80 0.10 0.07 0.03 22 0.06 0.15 0.79 0.01 23 0.05 0.01 0.00 0.94 24 0.83 0.02 0.01 0.15 25 0.87 0.05 0.03 0.04 27 0.76 0.10 0.11 0.03 28 0.17 0.68 0.10 0.05 29 0.10 0.01 0.00 0.90 30 0.09 0.29 0.60 0.01 31 0.05 0.01 0.00 0.94 32 0.53 0.04 0.01 0.43 33 0.85 0.04 0.02 0.09 34 0.82 0.06 0.02 0.10 35 0.76 0.07 0.02 0.14 37 0.36 0.31 0.30 0.02 38 0.01 0.02 0.97 0.00 39 0.12 0.04 0.02 0.82 40 0.02 0.00 0.00 0.97 41 0.57 0.15 0.02 0.25 42 0.14 0.03 0.02 0.82 43 0.89 0.06 0.01 0.03 44 0.02 0.00 0.00 0.98 45 0.61 0.02 0.01 0.36 46 0.03 0.00 0.00 0.97 47 0.88 0.07 0.02 0.03 48 0.06 0.60 0.32 0.02 49 0.01 0.98 0.01 0.00 50 0.06 0.88 0.05 0.01 51 0.01 0.05 0.93 0.00 52 0.02 0.08 0.90 0.00 53 0.11 0.01 0.01 0.87 54 0.27 0.01 0.00 0.72 55 0.94 0.03 0.01 0.02 58 0.45 0.41 0.05 0.09 59 0.12 0.61 0.22 0.05 60 0.26 0.07 0.02 0.64 61 0.17 0.19 0.62 0.02 62 0.08 0.00 0.00 0.92 63 0.02 0.94 0.03 0.00 64 0.08 0.01 0.00 0.91 65 0.98 0.01 0.00 0.01 67 0.22 0.69 0.08 0.01 68 0.96 0.02 0.00 0.02 69 0.96 0.02 0.01 0.01 71 0.00 0.01 0.98 0.00 72 0.56 0.05 0.01 0.37 73 0.10 0.01 0.01 0.88 74 0.91 0.01 0.00 0.08 75 0.36 0.38 0.21 0.05 76 0.15 0.40 0.44 0.01 77 0.02 0.06 0.91 0.00 78 0.48 0.43 0.03 0.06 79 0.51 0.02 0.01 0.45 80 0.04 0.01 0.00 0.95 81 0.47 0.03 0.01 0.49 82 0.98 0.01 0.00 0.01 83 0.05 0.01 0.01 0.93 84 0.03 0.00 0.00 0.96 85 0.76 0.07 0.01 0.15 86 0.95 0.03 0.01 0.01 88 0.03 0.00 0.00 0.96 90 0.79 0.13 0.02 0.06 91 0.37 0.50 0.05 0.09 92 0.86 0.10 0.02 0.02 93 0.13 0.82 0.03 0.01 A[1,][order(A[1,],decreasing=TRUE)] [1] 0.66 0.30 0.04 0.01 I want this for every row thank you -- View this message in context: http://r.789695.n4.nabble.com/clustering-fuzzy-tp3229853p3229853.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] clustering fuzzy
thank you ,you have been very kind -- View this message in context: http://r.789695.n4.nabble.com/clustering-fuzzy-tp3229853p3230228.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.