====== Corrected network measures ====== London, 11-12. Dec 2015 Ercim 15: [[http://vlado.fmf.uni-lj.si/pub/slides/ercim15.pdf|Slides]] >>> import sys; wdir = 'c:/users/batagelj/work/python/graph/graph' >>> sys.path = [wdir]+sys.path; import Graph >>> import os; os.chdir(wdir) >>> gdir = 'C:/Users/batagelj/Documents/papers/2015/CRoNoS/london/nets/' >>> T = "UsAirTri.net" >>> D = "deg.clu" >>> N = Graph.Graph.loadPajek(gdir+T) >>> N.loadPajekVec('deg',gdir+D) >>> len(N) 332 >>> n = len(N) >>> d = [0]*n >>> for i in range(n): d[i] = N.getNode(i+1,'deg')-1 >>> from copy import copy, deepcopy >>> P = deepcopy(N) >>> len(P) 332 >>> # --- Overlap weight >>> Tmed = 0 >>> for e in N.links(): (u,v,k) = e Te = N.getLink(e,'w') if Te > 0: Tmed = max(Tmed,min(d[u-1],d[v-1])) Td = d[u-1]+d[v-1]-Te if Td <= 0: over = 0; print(u,v,d[u-1],d[v-1],Te) else: over = Te/Td P.setLink(e,'w',over) >>> P.savePajek(gdir+'Overlap.net') >>> # --- Corrected Overlap weight >>> print(Tmed) >>> for e in N.links(): (u,v,k) = e Te = N.getLink(e,'w') if Te > 0: Td = Tmed + max(d[u-1],d[v-1]) - Te over = Te/Td P.setLink(e,'w',over) >>> P.savePajek(gdir+'CorrOverlap.net') >>> # --- Clustering Coefficient >>> E = [0]*n >>> for v in N.nodes(): s = 0 for e in N.edgeStar(v): s = s + N.getLink(e,'w') E[v-1] = s/2 >>> for i in range(n): d[i] = N.getNode(i+1,'deg') >>> Cc = [0]*n >>> for i in range(n): if d[i] <= 1: Cc[i] = 0 else: Cc[i] = 2*E[i]/d[i]/(d[i]-1) P.setNode(i+1,'Cc',Cc[i]) >>> # --- Corrected Clustering Coefficient >>> cCc = [0]*n >>> for i in range(n): if d[i] <= 0: cCc[i] = 0 else: cCc[i] = 2*E[i]/d[i]/Tmed P.setNode(i+1,'cCc',cCc[i]) >>> P.savePajekVec('cCc',gdir+'CorrClusC.vec') >>> P.savePajekVec('Cc',gdir+'ClusC.vec') ------------------------------------------------------------ >>> P = deepcopy(N) >>> d = [0]*n >>> for i in range(n): d[i] = N.getNode(i+1,'deg')-1 >>> # --- Overlap weight >>> Tmed = 0 >>> for e in N.links(): (u,v,k) = e Te = N.getLink(e,'w') if Te > 0: Tmed = max(Tmed,min(d[u-1],d[v-1])) Td = d[u-1]+d[v-1]-Te if Td <= 0: over = 0; print(u,v,d[u-1],d[v-1],Te) else: over = Te/Td P.setLink(e,'over',over) >>> # --- Corrected Overlap weight >>> print(Tmed) >>> for e in N.links(): (u,v,k) = e Te = N.getLink(e,'w') over = 0 if Te > 0: Td = Tmed + max(d[u-1],d[v-1]) - Te over = Te/Td P.setLink(e,'cOver',over) >>> dat = open(gdir+'overlap.csv','w') >>> for i in range(n): d[i] = N.getNode(i+1,'deg') >>> for e in P.links(): (u,v,k) = e; Te = N.getLink(e,'w') over = P.getLink(e,'over'); cOver = P.getLink(e,'cOver') m = min(d[u-1],d[v-1]); M = max(d[u-1],d[v-1]) dat.write(str(Te)+';'+str(over)+';'+str(cOver)+';'+str(m)+';'+str(M)+'\n') >>> dat.close() I changed to μ = Tmax = max{T(e): e in E}. I had to recompute the corrected measures. >>> Tmax = 0 >>> for e in N.links(): (u,v,k) = e; Te = N.getLink(e,'w') if Te > Tmax: Tmax = Te >>> print(Tmax) >>> # --- Corrected Overlap weight >>> for i in range(n): d[i] = N.getNode(i+1,'deg') - 1 >>> for e in N.links(): (u,v,k) = e Te = N.getLink(e,'w') over = 0 if Te > 0: Td = Tmax + max(d[u-1],d[v-1]) - Te over = Te/Td P.setLink(e,'w',over) >>> P.savePajek(gdir+'CorrOverlapMax.net') >>> dat = open(gdir+'overlapMax.csv','w') >>> for i in range(n): d[i] = N.getNode(i+1,'deg') >>> for e in P.links(): (u,v,k) = e; Te = N.getLink(e,'w') over = P.getLink(e,'over'); cOver = P.getLink(e,'w') m = min(d[u-1],d[v-1]); M = max(d[u-1],d[v-1]) dat.write(str(Te)+';'+str(over)+';'+str(cOver)+';'+str(m)+';'+str(M)+'\n') >>> dat.close() >>> # --- Clustering Coefficient >>> E = [0]*n >>> for v in N.nodes(): s = 0 for e in N.edgeStar(v): s = s + N.getLink(e,'w') E[v-1] = s/2 >>> for i in range(n): d[i] = N.getNode(i+1,'deg') >>> Cc = [0]*n >>> for i in range(n): if d[i] <= 1: Cc[i] = 0 else: Cc[i] = 2*E[i]/d[i]/(d[i]-1) P.setNode(i+1,'Cc',Cc[i]) >>> # --- Corrected Clustering Coefficient >>> cCc = [0]*n >>> for i in range(n): if d[i] <= 0: cCc[i] = 0 else: cCc[i] = 2*E[i]/d[i]/Tmax P.setNode(i+1,'cCc',cCc[i]) >>> P.savePajekVec('cCc',gdir+'CorrClusC.vec') >>> P.savePajekVec('Cc',gdir+'ClusC.vec') >>> csv = open(gdir+'ccMax.csv','w') >>> for i in range(n): csv.write(str(d[i])+';'+str(E[i])+';'+str(Cc[i])+';'+str(cCc[i])+'\n') >>> csv.close() > setwd("C:/Users/batagelj/Documents/papers/2015/CRoNoS/london/nets") > t <- read.table("overlap.csv",header=TRUE,dec=".",sep=";", colClasses=list("integer","numeric","numeric","integer","integer")) > head(t) Te over cOver m M 1 8 0.47058824 0.06557377 13 14 2 4 0.08695652 0.02515723 5 47 3 30 0.47619048 0.20408163 34 61 4 42 0.60869565 0.29787234 46 67 5 49 0.34027778 0.23786408 56 139 6 33 0.57894737 0.24812030 42 50 > > plot(t$over,t$cOver,pch=16,cex=0.7,main="Overlap weights",xlab="overlap",ylab="corrOverlap") > plot(t$Te,t$over,pch=16,cex=0.7,main="Overlap weights",xlab="#triangles",ylab="overlap") > plot(t$Te,t$cOver,pch=16,cex=0.7,main="Overlap weights",xlab="#triangles",ylab="corrOverlap") > plot(t$m/t$M,t$over,pch=16,cex=0.7,main="Overlap weights",xlab="minDeg/maxDeg",ylab="overlap") > plot(t$m/t$M,t$cOver,pch=16,cex=0.7,main="Overlap weights",xlab="minDeg/maxDeg",ylab="corrOverlap") > plot(t$M,t$over,pch=16,cex=0.7,main="Overlap weights",xlab="maxDeg",ylab="overlap") > plot(t$M,t$cOver,pch=16,cex=0.7,main="Overlap weights",xlab="maxDeg",ylab="corrOverlap") > plot(t$m,t$over,pch=16,cex=0.7,main="Overlap weights",xlab="minDeg",ylab="overlap") > plot(t$m,t$cOver,pch=16,cex=0.7,main="Overlap weights",xlab="minDeg",ylab="corrOverlap") > # Clustering coefficient > t <- read.table("ccMax.csv",header=TRUE,dec=".",sep=";", colClasses=list("integer","numeric","numeric","numeric")) > head(t) deg E Cc cCc 1 3 3 1.0 0.0250 2 3 3 1.0 0.0250 3 2 1 1.0 0.0125 4 5 6 0.6 0.0300 5 2 1 1.0 0.0125 6 3 3 1.0 0.0250 > plot(t$Cc,t$cCc,pch=16,cex=0.7,main="Clustering coefficients",xlab="clusCoef",ylab="corrClusCoef") > plot(t$deg,t$Cc,pch=16,cex=0.7,main="Clustering coefficients",xlab="deg",ylab="clusCoef") > plot(t$deg,t$cCc,pch=16,cex=0.7,main="Clustering coefficients",xlab="deg",ylab="corrClusCoef") > plot(t$deg,t$E,pch=16,cex=0.7,main="Clustering coefficients",xlab="deg",ylab="#edges")