Skip to content

Commit 3424902

Browse files
committed
updated post scripts
1 parent 2337e9d commit 3424902

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

src/post/description/_all_post.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ source("src/post/description/comp_vs_edges.R")
2222
source("src/post/description/comp_vs_vertices.R")
2323
source("src/post/description/deg_plots.R")
2424
source("src/post/description/diameters.R")
25-
#source("src/post/description/nei_vs_deg.R")
26-
#source("src/post/description/partial_extr.R")
27-
#source("src/post/description/pref_attach.R")
25+
source("src/post/description/nei_vs_deg.R")
26+
source("src/post/description/partial_extr.R")
27+
source("src/post/description/pref_attach.R")
2828
#source("src/post/description/robustness.R")
2929
#source("src/post/description/sex_stats.R")
3030
#source("src/post/description/trans_vs_deg.R")

src/post/description/nei_vs_deg.R

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,29 @@ start.rec.log(text="NeighVsDeg")
2121

2222
# read the graph
2323
graph.file <- get.path.data.graph(mode="scenes", net.type="static", filtered=FALSE, pref="graph", ext=".graphml")
24+
tlog(0,"Read the graph file: \"",graph.file,"\"")
2425
g <- read.graphml.file(file=graph.file)
2526

2627
# compute values
28+
tlog(2,"Compute the graph degree")
2729
deg.vals <- degree(graph=g, mode="all")
2830
tmp <- igraph::knn(graph=g, weights=NULL)#, mode="all", neighbor.degree.mode="all")
2931

3032
# filter out zero degree and NaN
33+
tlog(2,"Filter out zero degree nodes")
3134
idx <- which(!is.nan(tmp$knn) & tmp$knn>0)
3235
filt.nei <- tmp$knn[idx]
3336
filt.deg <- deg.vals[idx]
3437

3538
# keep tail
39+
tlog(2,"Keep tail")
3640
thresholds <- quantile(filt.deg, probs=c(0,0.25,0.50,0.75,0.85,0.90,0.95))
3741
threshold <- thresholds[4] # exp=0.48
3842
cut.nei <- filt.nei[filt.deg>=threshold]
3943
cut.deg <- filt.deg[filt.deg>=threshold]
4044

4145
# init parameters using a linear regression
46+
tlog(2,"Perform regression")
4247
fit <- lm(log(cut.nei) ~ log(cut.deg))
4348
summary(fit)
4449
params <- fit$coefficients
@@ -49,9 +54,9 @@ val3 <- 0
4954
# perform NL regression
5055
df <- data.frame(cut.deg, cut.nei)
5156
fit <- nlsLM(cut.nei ~ c1*cut.deg^c2,
52-
start=list(c1=val1, c2=val2),
53-
data = df,
54-
control=list(maxiter=200))
57+
start=list(c1=val1, c2=val2),
58+
data = df,
59+
control=list(maxiter=200))
5560
summary(fit)
5661

5762
# plot
@@ -61,7 +66,8 @@ col.sec <- combine.colors(col, "WHITE", transparency=20)
6166
xlab <- "Degree $k$"
6267
ylab <- "Neighbors' average Degree $<k_{nn}>$"
6368
exponent <- summary(fit)$coefficients["c2","Estimate"]
64-
plot.file <- get.path.stats.topo(net.type="static", mode="scenes", meas.name=MEAS_DEGREE, filtered="both", suf="nei.deg_vs_degree")
69+
plot.file <- get.path.stats.topo(net.type="static", mode="scenes", meas.name=MEAS_MULTI_NODES, filtered="both", suf="nei-degree_vs_degree")
70+
tlog(2,"Plot in \"",plot.file,"\"")
6571
pdf(file=paste0(plot.file,PLOT_FORMAT_PDF), bg="white")
6672
par(
6773
mar=c(4,4,0,0)+0.1, # remove the title space Bottom Left Top Right
@@ -130,6 +136,7 @@ legend(
130136

131137
###############################################################################
132138
# add the plot for the filtered net, as an inset
139+
tlog(2,"Same thing for filtered net")
133140

134141
# filter the characters
135142
filt.names <- V(g)$name[V(g)$Filter=="Discard"]

src/post/description/partial_extr.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ start.rec.log(text="PartialExtr")
1818

1919

2020
###############################################################################
21-
# represents the narrative as two distinct networks
22-
tlog(0,"Extract two distinct networks for the narrative")
21+
# divides the narrative into two distinct networks
22+
tlog(0,"Extract two distinct networks from the narrative")
2323

2424
# load stats
2525
data <- read.corpus.data()

src/post/description/pref_attach.R

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ gsl[[2]] <- gs.filt
8181

8282

8383

84+
8485
################################################################################
8586
filts <- c(FALSE, TRUE)
8687
modes <- c("all", "external", "internal")
@@ -107,20 +108,20 @@ ylab["internal"] <- "Attachment probability $\\kappa(k_1 k_2)$"
107108

108109
tlog(2,"Looping over modes (all, external, internal")
109110
for(mode in modes)
110-
{ tlog(2,"Processing mode ",mode)
111+
{ tlog(2,"Processing mode \"",mode,"\"")
111112

112113
tlog(2,"Looping over unfiltered/filtered graphs")
113114
for(f in 1:length(filts))
114115
{ gs <- gsl[[f]]
115116
if(filts[f])
116-
{ filtered <- "filtered"
117+
{ filt.txt <- "filtered"
117118
col <- pal["Keep"]
118119
}
119120
else
120-
{ filtered <-"unfiltered"
121+
{ filt.txt <-"unfiltered"
121122
col <- pal["Discard"]
122123
}
123-
tlog(4,"Processing the ",filtered," graph")
124+
tlog(4,"Processing the ",filt.txt," graph")
124125

125126
# focus on the middle of the period
126127
t0 <- round(length(gs)*0.5)
@@ -261,9 +262,9 @@ for(mode in modes)
261262
# perform NL regression
262263
df <- data.frame(cut.deg, cut.cum)
263264
fit <-nlsLM(cut.cum ~ c1*cut.deg^c2,
264-
start=list(c1=val1, c2=val2),
265-
data=df,
266-
control=list(maxiter=200))
265+
start=list(c1=val1, c2=val2),
266+
data=df,
267+
control=list(maxiter=200))
267268
print(summary(fit))
268269

269270
####################################
@@ -272,7 +273,7 @@ for(mode in modes)
272273
# create/complete figure
273274
if(!filts[f])
274275
{ # open plot file
275-
plot.file <- get.path.stats.topo(net.type="static", mode="scenes", meas.name=MEAS_DEGREE, filtered="both", suf=paste0("pref.attach_",mode))
276+
plot.file <- get.path.stats.topo(net.type="static", mode="scenes", meas.name=MEAS_MULTI_NODES, filtered="both", suf=paste0("pref-attach-",mode,"_vs_degree"))
276277
tlog(2,"Plot in file ",plot.file)
277278
pdf(file=paste0(plot.file,PLOT_FORMAT_PDF), bg="white")
278279
# plot parameters

0 commit comments

Comments
 (0)