@@ -18,7 +18,7 @@ start.rec.log(text="CharSim")
1818# ###############################################################################
1919# main parameters
2020wide <- 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
2222weighted <- TRUE # whether to use the graph weights
2323sc.lim <- NA # limit on the considered scenes (NA for no limit)
2424pub.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)
5252gs <- list ()
53- w.name <- NA
53+ w.name <- " none "
5454if (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
101101sim.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 " )]
125125if (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
0 commit comments