Skip to content

Commit b3578a0

Browse files
committed
fixed minor bugs in post
1 parent f267bfa commit b3578a0

14 files changed

Lines changed: 41 additions & 38 deletions

src/dynamic/narr_smooth.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ ns.graph.extraction <- function(char.stats, scene.chars, scene.stats, volume.sta
301301
}
302302
tlog.end.loop(4,"Finished the second character loop")
303303
}
304-
tlog.end.loop(6,"Finished the first character loop")
304+
tlog.end.loop(2,"Finished the first character loop")
305305

306306
return(res)
307307
}

src/post/description/avgdist_evol.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ dist.vals[[2]] <- future_sapply(gs.filt, function(g) mean_distance(graph=g, dire
6565
# loop over unfiltered/filtered
6666
tlog(0, "Loop over unfiltered/filtered graphs")
6767
natures <- c("unfiltered", "filtered")
68-
pal <- ATT_COLORS_FILT
68+
pal <- ATT_COLORS_FILT[c("Discard","Keep")]
6969
for(i in 1:2)
7070
{ if(i==1)
7171
{ filt.txt <- "unfiltered"
@@ -165,7 +165,7 @@ for(fformat in PLOT_FORMAT)
165165
x=x, y=y,
166166
xlab=TeX(paste0("Number of vertices $n$")),
167167
ylab=TeX("Average distance $<d>$"),
168-
las=1, col=pal[1],
168+
las=1, col=pal["Discard"],
169169
type="l"
170170
)
171171
# plot fitted line
@@ -201,7 +201,7 @@ for(fformat in PLOT_FORMAT)
201201
plot(
202202
x=x, y=y,
203203
xlab=NA, ylab=NA,
204-
las=1, col=pal[2],
204+
las=1, col=pal["Keep"],
205205
type="l",
206206
cex.lab=0.75, cex.axis=0.75, cex=0.75
207207
)

src/post/description/centr_vs_centr.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ start.rec.log(text="CentrVsCentr")
1919
tlog(0, "Plotting centrality vs. centrality")
2020

2121
# plot parameters
22-
pal <- ATT_COLORS_FILT
22+
pal <- ATT_COLORS_FILT[c("Discard","Keep")]
2323

2424
# measure names
2525
centr.names <- c(MEAS_DEGREE, MEAS_BETWEENNESS, MEAS_CLOSENESS, MEAS_EIGENCNTR)

src/post/description/centr_vs_occ.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ tlog(0, "Plotting centrality vs. occurrences")
2222
data <- read.corpus.data()
2323

2424
# plot parameters
25-
pal <- get.palette(2)
25+
pal <- ATT_COLORS_FILT
2626

2727
# measure names
2828
centr.names <- c(MEAS_DEGREE, MEAS_BETWEENNESS, MEAS_CLOSENESS, MEAS_EIGENCNTR)
@@ -110,7 +110,7 @@ for(centr.name in centr.names)
110110
# summary(fit)
111111

112112
# plot unfiltered data
113-
col <- pal[1]
113+
col <- pal["Discard"]
114114
col.sec <- combine.colors(col, "WHITE", transparency=20)
115115
xlab <- paste0("Number of ",occ.proper.names[occ.name],"s")
116116
ylab <- NODE_MEASURES[[centr.name]]$cname
@@ -183,7 +183,7 @@ for(centr.name in centr.names)
183183
# summary(fit)
184184

185185
# plot as an inset
186-
col <- pal[2]
186+
col <- pal["Keep"]
187187
col.sec <- combine.colors(col, "WHITE", transparency=20)
188188
par(
189189
fig=inlay.coords[paste0(centr.name,"_",occ.name),],

src/post/description/char_distr.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ laws["Filtered-characters-arc"] <- "moderate"
4848
# distribution plots
4949
tlog(0,"Producing distribution plots")
5050

51+
pal <- ATT_COLORS_FILT[c("Discard","Keep")]
52+
5153
# loop params
5254
object <- "characters"
5355
counts <- c("panel","page","scene","volume","arc")
@@ -72,7 +74,6 @@ for(count in counts)
7274
# set params
7375
file <- get.path.stats.corpus(object=object, subfold="both", pref=paste0("distrib_",count,"s-by-char"))
7476
tlog(4,"Producing files ",file)
75-
pal <- get.palette(length(data))
7677
ml <- paste0("Distribution of ",count," number over characters")
7778
xl <- paste0("Number of ",count,"s by character")
7879

src/post/description/char_sim.R

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ start.rec.log(text="CharSim")
1818
################################################################################
1919
# main parameters
2020
wide <- TRUE # wide plots showing volumes as rectangles
21-
narr.smooth <- TRUE # whether to use narrative smoothing or cumulative scene-based networks
21+
narr.smooth <- FALSE # whether to use narrative smoothing or cumulative scene-based networks
2222
weighted <- TRUE # whether to use the graph weights
2323
sc.lim <- NA # limit on the considered scenes (NA for no limit)
2424
pub.order <- TRUE # whether to use the volume publication vs. story order
@@ -50,17 +50,17 @@ kept <- which(V(g)$Filter=="Keep")
5050

5151
# compute the sequence of scene-based graphs (possibly one for each scene)
5252
gs <- list()
53-
w.name <- NA
53+
w.name <- "none"
5454
if(narr.smooth)
5555
{ net.type <- "narr_smooth"
56-
gs[["FALSE"]] <- ns.read.graph(filtered=FALSE, remove.isolates=TRUE, pub.order=pub.order)
57-
gs[["TRUE"]] <- ns.read.graph(filtered=TRUE, remove.isolates=TRUE, pub.order=pub.order)
56+
gs[["unfiltered"]] <- ns.read.graph(filtered=FALSE, remove.isolates=TRUE, pub.order=pub.order)
57+
gs[["filtered"]] <- ns.read.graph(filtered=TRUE, remove.isolates=TRUE, pub.order=pub.order)
5858
if(weighted)
5959
w.name <- "normalized"
6060
}else
6161
{ net.type <- "cumulative"
6262
tlog(2,"Extracting the sequence of graphs")
63-
gs[["FALSE"]] <- extract.static.graph.scenes(
63+
gs[["unfiltered"]] <- extract.static.graph.scenes(
6464
inter.df=data$inter.df,
6565
char.stats=char.stats,
6666
volume.stats=volume.stats,
@@ -69,13 +69,13 @@ if(narr.smooth)
6969
)
7070
# possibly set weights
7171
if(weighted)
72-
{ gs[["FALSE"]] <- future_lapply(gs[["FALSE"]], function(g) E(g)$weight <- E(g)$Occurrences)
72+
{ gs[["unfiltered"]] <- future_lapply(gs[["unfiltered"]], function(g) {E(g)$weight <- E(g)$Occurrences;return(g)})
7373
w.name <- "occurrences"
7474
}
7575

7676
# compute the filtered version
7777
tlog(2,"Same thing for filtered graphs")
78-
gs[["TRUE"]] <- future_lapply(gs[["FALSE"]], function(g) delete_vertices(g, v=intersect(filt.names,V(g)$name)))
78+
gs[["filtered"]] <- future_lapply(gs[["unfiltered"]], function(g) delete_vertices(g, v=intersect(filt.names,V(g)$name)))
7979
}
8080

8181
# scene range
@@ -99,29 +99,29 @@ tlog(0,"Evolution of similarity between pairs of characters")
9999

100100
# similarity measures
101101
sim.meas <- list()
102-
sim.meas[["cosine"]] <- list(
102+
sim.meas[["sim-cosine"]] <- list(
103103
bounds=c(0,1),
104104
cname="Cosine Similarity",
105105
foo=function(a,idx) {sapply(1:nrow(idx), function(r) sum(a[idx[r,1],]*a[idx[r,2],])/sqrt(sum(a[idx[r,1],]^2)*sum(a[idx[r,2],]^2)))}
106106
)
107-
sim.meas[["pearson"]] <- list(
107+
sim.meas[["sim-pearson"]] <- list(
108108
bounds=c(-1,1),
109109
cname="Pearson Coefficient",
110110
foo=function(a,idx) {sapply(1:nrow(idx), function(r) cor(x=a[idx[r,1],], y=a[idx[r,2],]))}
111111
)
112-
sim.meas[["euclidean"]] <- list(
112+
sim.meas[["sim-euclidean"]] <- list(
113113
bounds=c(0,NA),
114114
cname="Euclidean Distance",
115115
foo=function(a,idx) {sapply(1:nrow(idx), function(r) sqrt(sum((a[idx[r,1],]-a[idx[r,2],])^2)))}
116116
)
117-
#sim.meas[["regequiv"]] <- list(
117+
#sim.meas[["sim-regular"]] <- list( # BEWARE: this one is extremely slow
118118
# bounds=c(0,NA),
119119
# cname="Regular Equivalence",
120120
# foo=function(a,idx) {tmp <- REGE.for(M=a,E=0)$E; sapply(1:nrow(idx), function(r) tmp[idx[r,1],idx[r,2]])}
121121
#)
122122

123123
# plot parameters
124-
pal <- ATT_COLORS_FILT
124+
pal <- ATT_COLORS_FILT[c("Discard","Keep")]
125125
if(wide)
126126
{ pw.pdf <- 15; ph.pdf <- 5
127127
pw.png <- 2400; ph.png <- 800
@@ -236,18 +236,20 @@ for(m in 1:length(sim.meas))
236236

237237
#####
238238
# plot unfiltered and filtered values on the same plot
239-
tlog(4,"Looping over the pairs of vertices")
239+
tlog(4,"Plotting both unfiltered and filtered networks at once")
240+
241+
tlog(5,"Looping over the pairs of vertices")
240242
for(p in 1:nrow(pairs))
241-
{ tlog(5,"Processing pair ",pairs[p,1],"--",pairs[p,2]," (",p,"/",nrow(pairs),")")
243+
{ tlog(6,"Processing pair ",pairs[p,1],"--",pairs[p,2]," (",p,"/",nrow(pairs),")")
242244

243245
# set file name
244246
pt <- paste0(names(sim.meas)[m],"_pair=", paste0(pairs[p,],collapse="--"), if(wide) "_wide" else "")
245247
plot.file <- get.path.stats.topo(net.type=net.type, order=ord.fold, mode="scenes", weights=w.name, meas.name=MEAS_MULTI_NODEPAIRS, filtered="both", suf=pt)
246-
tlog(6,"Creating file \"",plot.file,"\"")
248+
tlog(7,"Creating file \"",plot.file,"\"")
247249

248250
# compute data ranges
249251
xlim <- range(sc.rg)
250-
ylim <- range(c(sim.vals[[as.character(FALSE)]][,p], sim.vals[[as.character(TRUE)]][,p]), na.rm=TRUE)
252+
ylim <- range(c(sim.vals[["unfiltered"]][,p], sim.vals[["filtered"]][,p]), na.rm=TRUE)
251253
ylim[2] <- ylim[2]*1.1 # add some space for volume names
252254

253255
# produce file
@@ -269,7 +271,7 @@ for(m in 1:length(sim.meas))
269271
draw.volume.rects(ylim, volume.stats)
270272
# add line
271273
for(filt in c("unfiltered","filtered"))
272-
{ if(filt="unfiltered")
274+
{ if(filt=="unfiltered")
273275
col <- pal["Discard"]
274276
else
275277
col <- pal["Keep"]
@@ -285,7 +287,7 @@ for(m in 1:length(sim.meas))
285287
legend(
286288
title="Characters",
287289
x="bottomright",
288-
fill=pal["Discard","Keep"],
290+
fill=pal[c("Discard","Keep")],
289291
legend=c("Unfiltered","Filtered")
290292
)
291293
# close file

src/post/description/comp_vs_edges.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ylab <- "Largest component size (proportion of vertices)"
4040

4141
# compute both types of weights
4242
tlog(0, "Compute values and plot basic figures")
43-
pal <- ATT_COLORS_FILT
43+
pal <- ATT_COLORS_FILT[c("Discard","Keep")]
4444
wts <- c("Duration","Occurrences")
4545
res <- list()
4646
for(wt in wts)

src/post/description/comp_vs_vertices.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ xlab <- "Number of vertices removed"
3535

3636
# compute and plot
3737
tlog(0, "Compute values and plot basic figures")
38-
pal <- ATT_COLORS_FILT
38+
pal <- ATT_COLORS_FILT[c("Discard","Keep")]
3939
res <- list()
4040
# remove each vertex iteratively
4141
tlog(4, "Removing vertices iteratively for the unfiltered graph")
@@ -230,7 +230,7 @@ for(fformat in PLOT_FORMAT)
230230
legend(
231231
title="Characters",
232232
x="topright",
233-
fill=pal["Discard","Keep"],
233+
fill=pal[c("Discard","Keep")],
234234
legend=c("Unfiltered","Filtered")
235235
)
236236
dev.off()
@@ -261,7 +261,7 @@ for(fformat in PLOT_FORMAT)
261261
legend(
262262
title="Characters",
263263
x="topleft",
264-
fill=pal["Discard","Keep"],
264+
fill=pal[c("Discard","Keep")],
265265
legend=c("Unfiltered","Filtered")
266266
)
267267
dev.off()

src/post/description/deg_plots.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ idx.keep <- which(data$char.stats[,COL_FILTER]=="Keep")
4444

4545
# loop params
4646
meass <- c(MEAS_DEGREE,MEAS_STRENGTH)
47+
pal <- ATT_COLORS_FILT[c("Discard","Keep")]
4748

4849
# load numbers of occurrences of characters
4950
file <- get.path.stats.corpus(object="characters", subfold="unfiltered", pref="_char_stats.csv")
@@ -82,7 +83,6 @@ for(meas in meass)
8283

8384
# set params
8485
file <- get.path.stats.topo(net.type="static", mode="scenes", meas.name=meas, weights=if(is.na(wt)) "none" else wt, filtered="both", suf="distrib")
85-
pal <- get.palette(length(data))
8686
ml <- paste0(ALL_MEASURES[[meas]]$cname, " distribution")
8787
if(!is.na(wt))
8888
ml <- paste0(ml," (",wt,")")

src/post/description/nei_vs_deg.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fit <- nlsLM(cut.nei ~ c1*cut.deg^c2,
5555
summary(fit)
5656

5757
# plot
58-
pal <- ATT_COLORS_FILT
58+
pal <- ATT_COLORS_FILT[c("Discard","Keep")]
5959
col <- pal["Discard"]
6060
col.sec <- combine.colors(col, "WHITE", transparency=20)
6161
xlab <- "Degree $k$"

0 commit comments

Comments
 (0)