Code to make Figure 7
source("Functions for Simulations.R")
set.seed(123)
social <- read.csv("social.csv", header=FALSE)
ind_tw <- which(social[,3]=="tw")
ind_ff <- which(social[,3]=="ff")
ind_yt <- which(social[,3]=="yt")
social_tw <- social[ind_tw, c(1:2) ]
g_tw <- graph_from_edgelist(cbind(social_tw$V1,social_tw$V2) , directed=FALSE)
v_tw <- names(V(g_tw))
social_ff <- social[ind_ff, c(1:2) ]
g_ff <- graph_from_edgelist(cbind(social_ff$V1,social_ff$V2), directed=FALSE)
v_ff <- names(V(g_ff))
social_yt <- social[ind_yt, c(1:2) ]
g_yt <- graph_from_edgelist(cbind(social_yt$V1,social_yt$V2), directed=FALSE)
v_yt <- names(V(g_yt))
cv <- intersect(intersect(v_tw, v_ff), v_yt)
n <- length(cv)
ind1<-rep(0,n)
ind2<-rep(0,n)
ind3<-rep(0,n)
for(i in 1:n){
ind1[i] <- which(v_yt == cv[i])
ind2[i] <- which(v_ff == cv[i])
ind3[i] <- which(v_tw == cv[i])
}
A <- g_yt[]
A <- A[ind1,ind1]
B <- g_ff[]
B <- B[ind2,ind2]
C <- g_tw[]
C <- C[ind3,ind3]
diag(A) <- 0
diag(B) <- 0
diag(C) <- 0
a<-1
b<-1
c<-1
while((a+b+c) > 0){
zA <- which( as.numeric(rowSums(A)) == 0)
zB <- which( as.numeric(rowSums(B)) == 0)
zC <- which( as.numeric(rowSums(C)) == 0)
zt <- union(union(zA, zB), zC)
a<- sum(rowSums(A[-zt,-zt])==0)
b<- sum(rowSums(B[-zt,-zt])==0)
c<- sum(rowSums(C[-zt,-zt])==0)
A <- A[-zt,-zt]
B <- B[-zt,-zt]
C <- C[-zt,-zt]}
nn <- dim(C)[1]
dA <- sum(A)/(nn*(nn-1))
dB <- sum(B)/(nn*(nn-1))
dC <- sum(C)/(nn*(nn-1))
A1 <- A
ee<-irlba(A1,30)
da1<-getElbows(ee$d)[2]
A2 <- B
ee<-irlba(A2,30)
da2<-getElbows(ee$d)[2]
B1 <- C
ee<-irlba(B1,30)
db1<-getElbows(ee$d)[2]
d <- max(da1, da2, db1)
d <- max(da1, da2, db1)
X1 <- ase(A1,d)$X
X2 <- ase(A2,d)$X
Y1 <- ase(B1,d)$X
A <- X1 %*%t(X1) #YT
B <- X2 %*%t(X2) #FF
C <- Y1 %*%t(Y1) #TW
#--------- WITH THEMSELVES -----------------------
k <- c(0, 5, 10, 20, 30, 50, 75, 100, 150, 200, 250)
results <- matrix(0, 3, 11)
for(i in 1:11){
tresults <- matrix(0, 3, 200)
for(j in 1:200){
pp <- shuff_perm(nn,k[i])
pp <- pp[2,]
tresults[1,j] <- norm(A-A[pp,pp],"F")^2
tresults[2,j] <- norm(B-B[pp,pp],"F")^2
tresults[3,j] <- norm(C-C[pp,pp],"F")^2
}
results[1,i]<-mean(tresults[1,])
results[2,i]<-mean(tresults[2,])
results[3,i]<-mean(tresults[3,])
}
Graphs <- c(rep("YT-YT",11), rep("FF-FF",11), rep("TW-TW",11))
R<- as.vector(t(results))
R<-data.frame(R)
R<-cbind(R,Graphs)
Shuff <-rep(k,3)
R<-cbind(R,Shuff)
colnames(R) <- c("X1", "Graphs", "Shuff")
ggplot(R, aes(x = Shuff, y = X1)) + geom_line(aes(color = Graphs)) + geom_point(aes(shape=Graphs, color=Graphs), size = 4) + labs(title="Frobenius Norm Difference: Same Network", y="Shuffled Frobenius Norm with Phat", x="Shuffled Vertices") +
theme(plot.title = element_text(family="serif", face = "bold", size = 12, hjust=0.5),
panel.background = element_rect(fill = "#FFFFFF"),
legend.title = element_text(family="serif", face="bold", color = "#000000", size = 12),
legend.background = element_rect(fill = "#FFFFFF"),
text = element_text(size=20, family = "serif"),
axis.title = element_text(family = "serif", size = 15, colour = "#000000"),
plot.background = element_rect(fill = "#FFFFFF"),
axis.line = element_line(colour = "#000000", size = 1),
legend.text = element_text( family="serif", color = "#000000", size=15),
strip.text.y = element_text(color = "#FFFFFF"),
strip.background = element_rect(fill="#000000")) +
scale_color_manual(values=c("YT-YT" = "#abb065","FF-FF"="#e5b9a8", "TW-TW"="#e16a86"))+
scale_shape_manual(values=c("YT-YT" = 18, "FF-FF"= 10,"TW-TW"=15))
k <- c(0, 5, 10, 20, 30, 50, 75, 100, 150, 200, 250)
results <- matrix(0, 3, 11)
for(i in 1:11){
tresults <- matrix(0, 3, 200)
for(j in 1:200){
pp <- shuff_perm(nn,k[i])
pp <- pp[2,]
tresults[1,j] <- norm(A-B[pp,pp],"F")^2
tresults[2,j] <- norm(A-C[pp,pp],"F")^2
tresults[3,j] <- norm(B-C[pp,pp],"F")^2
}
results[1,i]<-mean(tresults[1,])
results[2,i]<-mean(tresults[2,])
results[3,i]<-mean(tresults[3,])
}
Graphs <- c(rep("YT-FF",11), rep("YT-TW",11), rep("FF-TW",11))#,rep("YT",11), rep("TW",11), rep("FF",11))
R<- as.vector(t(results))
R<-data.frame(R)
R<-cbind(R,Graphs)
Shuff <-rep(k,3)
R<-cbind(R,Shuff)
colnames(R) <- c("X1", "Graphs", "Shuff")
ggplot(R, aes(x = Shuff, y = X1)) + geom_line(aes(color = Graphs)) + geom_point(aes(shape=Graphs, color=Graphs), size = 4) + labs(title="Frobenius Norm Difference: Across Networks", y="Shuffled Frobenius Norm with Phat", x="Shuffled Vertices") +
theme(plot.title = element_text(family="serif", face = "bold", size = 12, hjust=0.5),
panel.background = element_rect(fill = "#FFFFFF"),
legend.title = element_text(family="serif", face="bold", color = "#000000", size = 12),
legend.background = element_rect(fill = "#FFFFFF"),
text = element_text(size=20, family = "serif"),
axis.title = element_text(family = "serif", size = 15, colour = "#000000"),
plot.background = element_rect(fill = "#FFFFFF"),
axis.line = element_line(colour = "#000000", size = 1),
legend.text = element_text( family="serif", color = "#000000", size=15),
strip.text.y = element_text(color = "#FFFFFF"),
strip.background = element_rect(fill="#000000")) +
scale_color_manual(values=c("YT-FF" = "#B675E0","YT-TW"="#00A6CA", "FF-TW"="#00AA5A"))+
scale_shape_manual(values=c("YT-FF" = 19, "YT-TW"= 17,"FF-TW"=8))