Skip to content

Commit 30425d0

Browse files
committed
fixed path issue in stat cmpt
1 parent 2788752 commit 30425d0

6 files changed

Lines changed: 54 additions & 33 deletions

File tree

src/Labatut2022.R

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,32 @@ start.rec.log(text=SERIES)
3434

3535
###############################################################################
3636
# read raw data
37-
data <- read.raw.data()
37+
#data <- read.raw.data()
38+
# OR, if already computed, read from file
39+
data <- read.corpus.data()
3840

3941
# compute corpus stats
40-
data <- compute.corpus.stats(data)
42+
#data <- compute.corpus.stats(data)
4143

4244
# plot corpus stats
43-
plot.corpus.stats(data)
45+
#plot.corpus.stats(data)
4446

4547

4648

4749

4850
###############################################################################
4951
# extract static networks
50-
data <- extract.static.graphs.base(data)
52+
#data <- extract.static.graphs.base(data)
5153

5254
# plot these graphs
53-
plot.static.graphs(data)
55+
#plot.static.graphs(data)
5456

5557

5658

5759

5860
###############################################################################
5961
# compute scene-based graph stats
60-
#compute.static.statistics.base(data)
62+
compute.static.statistics.base(data)
6163

6264
# plot these stats
6365
#generate.static.plots(data)
@@ -74,4 +76,4 @@ end.rec.log()
7476

7577
###############################################################################
7678
# additional plots
77-
source("src/post/description/_all_post.R")
79+
#source("src/post/description/_all_post.R")

src/post/description/avgdist_evol.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# source("src/post/description/avgdist_evol.R")
1010
###############################################################################
1111
source("src/common/include.R")
12+
start.rec.log(text="AvgDistEvol")
1213

1314

1415

@@ -17,20 +18,24 @@ source("src/common/include.R")
1718
# publication order vs. story order
1819
pub.order <- TRUE
1920

21+
tlog(0, "Evolution of the average distance over scenes: pub.order=",pub.order)
22+
2023

2124

2225

2326
###############################################################################
2427
# plots unfiltered and filtered figures as separate files
2528

2629
# load corpus stats
30+
tlog(0, "Read corpus stats")
2731
data <- read.corpus.data()
2832

2933
# get filtered characters
3034
filt.names <- data$char.stats[data$char.stats[,COL_FILTER]=="Discard",COL_NAME]
3135
if(length(filt.names)==0) stop("Empty list of filtered characters")
3236

3337
# compute the sequence of scene-based graphs (possibly one for each scene)
38+
tlog(0, "Extract graph sequence")
3439
gs <- extract.static.graph.scenes(
3540
inter.df=data$inter.df,
3641
char.stats=data$char.stats,
@@ -54,6 +59,7 @@ g.orders[[2]] <- future_sapply(gs.filt, gorder)
5459
dist.vals[[2]] <- future_sapply(gs.filt, function(g) mean_distance(graph=g, directed=FALSE, unconnected=TRUE))
5560

5661
# loop over unfiltered/filtered
62+
tlog(0, "Loop over unfiltered/filtered")
5763
natures <- c("unfiltered", "filtered")
5864
pal <- ATT_COLORS_FILT
5965
for(i in 1:2)
@@ -65,6 +71,7 @@ for(i in 1:2)
6571
{ filt.txt <- "filtered"
6672
col <- pal["Keep"]
6773
}
74+
tlog(2, "Processing ",filt.txt," net (",i,"/",2,")")
6875

6976
# setup series
7077
x <- g.orders[[i]]
@@ -87,6 +94,7 @@ for(i in 1:2)
8794

8895
# plot distance as a function of graph order
8996
plot.file <- get.path.stats.topo(net.type="static", mode="scenes", meas.name=paste0(MEAS_DISTANCE,SFX_AVG), filtered=filt.txt, suf=paste0("evolution_",order.txt,"_lines"))
97+
tlog(2, "Plotting in file ",plot.file)
9098
for(fformat in PLOT_FORMAT)
9199
{ if(fformat==PLOT_FORMAT_PDF)
92100
pdf(file=paste0(plot.file,PLOT_FORMAT_PDF), bg="white")
@@ -108,13 +116,15 @@ for(i in 1:2)
108116
dev.off()
109117
}
110118
}
119+
tlog(0, "Unfiltered/filtered loop complete")
111120

112121

113122

114123

115124
###############################################################################
116125
# same thing, but plots both unfiltered and filtered figures in the same file
117126
plot.file <- get.path.stats.topo(net.type="static", mode="scenes", meas.name=paste0(MEAS_DISTANCE,SFX_AVG), filtered="both", suf=paste0("evolution_",order.txt,"_lines"))
127+
tlog(0, "Plotting both unfiltered and filtered results in file ",plot.file)
118128

119129
# process all formats
120130
for(fformat in PLOT_FORMAT)
@@ -200,3 +210,10 @@ for(fformat in PLOT_FORMAT)
200210
dev.off()
201211
}
202212

213+
214+
215+
216+
###############################################################################
217+
# end logging
218+
tlog(0,"Process complete")
219+
end.rec.log()

src/post/description/deg_plots.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ for(meas in meass)
6262
# load precomputed data
6363
data <- list()
6464
# unfiltered
65-
file <- get.path.stat.table(object="nodes", mode="scenes", net.type="static", weights=if(is.na(wt)) "occurrences" else wt, filtered=FALSE)
65+
file <- get.path.stat.table(object="nodes", mode="scenes", net.type="static", weights=if(is.na(wt)) "occurrences" else wt, filtered="unfiltered")
6666
tab <- as.matrix(read.csv(file, header=TRUE, check.names=FALSE, row.names=1))
6767
data[[1]] <- tab[,meas]
6868
unfilt.idx <- data[[1]] > 0
6969
data[[1]] <- data[[1]][unfilt.idx] # remove isolates
7070
# file <- get.path.stats.comp(object="nodes", mode="scenes", meas.name=meas, weights=if(is.na(wt)) "none" else wt, filtered=FALSE, suf="disttest_noisolates")
7171
# test.disc.distr(data[[1]], xlab=paste0("Unfiltered ",ALL_MEASURES[[meas]]$cname," (no isolates)"), return_stats=FALSE, sims=100, plot.file=file)
7272
# filtered
73-
file <- get.path.stat.table(object="nodes", mode="scenes", net.type="static", weights=if(is.na(wt)) "occurrences" else wt, filtered=TRUE)
73+
file <- get.path.stat.table(object="nodes", mode="scenes", net.type="static", weights=if(is.na(wt)) "occurrences" else wt, filtered="filtered")
7474
tab <- as.matrix(read.csv(file, header=TRUE, check.names=FALSE, row.names=1))
7575
data[[2]] <- tab[,meas]
7676
filt.idx <- data[[2]] > 1

src/post/description/weight_plots.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ for(wt in wts)
4141
# load precomputed data
4242
data <- list()
4343
# unfiltered
44-
file <- get.path.stat.table(object="links", mode="scenes", net.type="static", weights=wt, filtered=FALSE)
44+
file <- get.path.stat.table(object="links", mode="scenes", net.type="static", weights=wt, filtered="unfiltered")
4545
tab <- as.matrix(read.csv(file, header=TRUE, check.names=FALSE, row.names=1))
4646
data[[1]] <- tab[,meas]
4747
# filtered
48-
file <- get.path.stat.table(object="links", mode="scenes", net.type="static", weights=wt, filtered=TRUE)
48+
file <- get.path.stat.table(object="links", mode="scenes", net.type="static", weights=wt, filtered="filtered")
4949
tab <- as.matrix(read.csv(file, header=TRUE, check.names=FALSE, row.names=1))
5050
data[[2]] <- tab[,meas]
5151
names(data) <- c("Unfiltered","Filtered")

src/static/compute_stats.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ FORCE <- TRUE
3131
compute.static.node.statistics <- function(g, mode, window.size=NA, overlap=NA, weights=NA, arc=NA, vol=NA, filtered=FALSE)
3232
{ object <- "nodes"
3333
filt.txt <- if(filtered) "filtered" else "unfiltered"
34-
table.file <- get.path.stat.table(object=object, mode=mode, net.type="static", window.size=window.size, overlap=overlap, weights=weights, arc=arc, vol=vol, filtered=filtered)
34+
table.file <- get.path.stat.table(object=object, mode=mode, net.type="static", window.size=window.size, overlap=overlap, weights=weights, arc=arc, vol=vol, filtered=filt.txt)
3535
tlog(4,"Computing nodal topological measures for \"",table.file,"\"")
3636

3737
# read or create the table containing the computed values
@@ -281,7 +281,7 @@ compute.static.nodecomp.statistics <- function(g, mode, window.size=NA, overlap=
281281
compute.static.nodepair.statistics <- function(g, mode, window.size=NA, overlap=NA, weights=NA, arc=NA, vol=NA, filtered=FALSE)
282282
{ object <- "nodepairs"
283283
filt.txt <- if(filtered) "filtered" else "unfiltered"
284-
table.file <- get.path.stat.table(object=object, mode=mode, net.type="static", window.size=window.size, overlap=overlap, weights=weights, arc=arc, vol=vol, filtered=filtered)
284+
table.file <- get.path.stat.table(object=object, mode=mode, net.type="static", window.size=window.size, overlap=overlap, weights=weights, arc=arc, vol=vol, filtered=filt.txt)
285285
tlog(4,"Computing node-pair topological measures for \"",table.file,"\"")
286286

287287
# read or create the table containing the computed values
@@ -374,7 +374,7 @@ compute.static.nodepair.statistics <- function(g, mode, window.size=NA, overlap=
374374
compute.static.link.statistics <- function(g, mode, window.size=NA, overlap=NA, weights=NA, arc=NA, vol=NA, filtered=FALSE)
375375
{ object <- "links"
376376
filt.txt <- if(filtered) "filtered" else "unfiltered"
377-
table.file <- get.path.stat.table(object=object, mode=mode, net.type="static", window.size=window.size, overlap=overlap, weights=weights, arc=arc, vol=vol, filtered=filtered)
377+
table.file <- get.path.stat.table(object=object, mode=mode, net.type="static", window.size=window.size, overlap=overlap, weights=weights, arc=arc, vol=vol, filtered=filt.txt)
378378
tlog(4,"Computing link topological measures for \"",table.file,"\"")
379379

380380
# read or create the table containing the computed values
@@ -461,7 +461,8 @@ compute.static.link.statistics <- function(g, mode, window.size=NA, overlap=NA,
461461
###############################################################################
462462
compute.static.graph.statistics <- function(g, mode, window.size=NA, overlap=NA, weights=NA, arc=NA, vol=NA, filtered=FALSE)
463463
{ object <- "graph"
464-
table.file <- get.path.stat.table(object=object, mode=mode, net.type="static", window.size=window.size, overlap=overlap, weights=weights, arc=arc, vol=vol, filtered=filtered)
464+
filt.txt <- if(filtered) "filtered" else "unfiltered"
465+
table.file <- get.path.stat.table(object=object, mode=mode, net.type="static", window.size=window.size, overlap=overlap, weights=weights, arc=arc, vol=vol, filtered=filt.txt)
465466
tlog(4,"Computing graph topological measures")
466467

467468
# read or create the table containing the computed values
@@ -651,8 +652,8 @@ compute.static.correlations <- function(mode, window.size=NA, overlap=NA, weight
651652
object <- "links"
652653

653654
# retrieve reference values
654-
vals.dur <- load.static.nodelink.stats.scenes(object=object, weights="duration", measure=meas.name, arc=arc, vol=vol, filtered=FALSE)
655-
vals.occ <- load.static.nodelink.stats.scenes(object=object, weights="occurrences", measure=meas.name, arc=arc, vol=vol, filtered=FALSE)
655+
vals.dur <- load.static.nodelink.stats.scenes(object=object, weights="duration", measure=meas.name, arc=arc, vol=vol, filtered="unfiltered")
656+
vals.occ <- load.static.nodelink.stats.scenes(object=object, weights="occurrences", measure=meas.name, arc=arc, vol=vol, filtered="unfiltered")
656657

657658
# retrieve tested values
658659
tab.file <- get.path.stat.table(object=object, mode=mode, net.type="static", window.size=window.size, overlap=overlap, weights=weights, arc=arc, vol=vol)

src/static/plot_stats.R

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ load.static.corr.by.overlap <- function(mode, window.sizes, overlap, measure, we
154154
#
155155
# returns: a vector of values representing the desired series.
156156
###############################################################################
157-
load.static.corr.scenes <- function(weights, measure, arc=NA, vol=NA)
158-
{ table.file <- get.path.stat.table(object="corr", mode="scenes", net.type="static", weights=weights, arc=arc, vol=vol)
157+
load.static.corr.scenes <- function(weights, measure, arc=NA, vol=NA, filtered)
158+
{ table.file <- get.path.stat.table(object="corr", mode="scenes", net.type="static", weights=weights, arc=arc, vol=vol, filtered=filtered)
159159
# TODO adjust object in above call
160160
tmp.tab <- as.matrix(read.csv(table.file, header=TRUE, check.names=FALSE, row.names=1))
161161
res <- tmp.tab[measure,]
@@ -236,7 +236,7 @@ load.static.nodelink.stats.by.overlap <- function(object, mode, window.sizes, ov
236236
#
237237
# returns: a vector representing the link/node values for the specified measure.
238238
###############################################################################
239-
load.static.nodelink.stats.scenes <- function(object, weights, measure, arc=NA, vol=NA, filtered=FALSE)
239+
load.static.nodelink.stats.scenes <- function(object, weights, measure, arc=NA, vol=NA, filtered)
240240
{ table.file <- get.path.stat.table(object=object, mode="scenes", net.type="static", weights=weights, arc=arc, vol=vol, filtered=filtered)
241241
tmp.tab <- as.matrix(read.csv(table.file, header=TRUE, check.names=FALSE, row.names=1))
242242
res <- tmp.tab[,measure]
@@ -277,8 +277,8 @@ generate.static.plots.single <- function(mode, window.sizes, overlaps)
277277
object <- "nodescomp"
278278

279279
# load the reference values (scene-based graph)
280-
seg.occ.vals <- load.static.nodelink.stats.scenes(object=object, weights="occurrences", measure=meas.name, filtered=FALSE)
281-
seg.dur.vals <- load.static.nodelink.stats.scenes(object=object, weights="duration", measure=meas.name, filtered=FALSE)
280+
seg.occ.vals <- load.static.nodelink.stats.scenes(object=object, weights="occurrences", measure=meas.name, filtered="unfiltered")
281+
seg.dur.vals <- load.static.nodelink.stats.scenes(object=object, weights="duration", measure=meas.name, filtered="unfiltered")
282282
seg.vals <- list()
283283
seg.vals[[1]] <- seg.occ.vals[!is.na(seg.occ.vals)]
284284
seg.vals[[2]] <- seg.dur.vals[!is.na(seg.dur.vals)]
@@ -502,8 +502,8 @@ generate.static.plots.multiple <- function(mode, window.sizes, overlaps)
502502
object <- "graphcomp"
503503

504504
# load the reference values (scene-based graph)
505-
seg.occ.vals <- load.static.graph.stats.scenes(object=object, measure=meas.name, weights="occurrences")
506-
seg.dur.vals <- load.static.graph.stats.scenes(object=object, measure=meas.name, weights="duration")
505+
seg.occ.vals <- load.static.graph.stats.scenes(object=object, measure=meas.name, weights="occurrences", filtered="unfiltered")
506+
seg.dur.vals <- load.static.graph.stats.scenes(object=object, measure=meas.name, weights="duration", filtered="unfiltered")
507507

508508
# retrieve the window.size data series
509509
tlog(5,"Gathering and plotting data by window.size")
@@ -669,7 +669,7 @@ generate.static.plots.corr <- function(mode, window.sizes, overlaps)
669669
object <- "graph"
670670

671671
# load the reference values (scene-based graph)
672-
seg.vals <- load.static.corr.scenes(weights="occurrences", measure=meas.name)
672+
seg.vals <- load.static.corr.scenes(weights="occurrences", measure=meas.name, filtered="unfiltered")
673673

674674
for(weights in c("duration","occurrences"))
675675
{ if(weights=="duration")
@@ -828,9 +828,9 @@ generate.static.plots.ranks <- function(mode, window.sizes, overlaps)
828828
object <- "nodepairs"
829829

830830
# load the reference values (scene-based graph)
831-
seg.occ.vals <- load.static.nodelink.stats.scenes(object=object, weights="occurrences", measure=meas.name, filtered=FALSE)
831+
seg.occ.vals <- load.static.nodelink.stats.scenes(object=object, weights="occurrences", measure=meas.name, filtered="unfiltered")
832832
seg.occ.ranks <- rank(seg.occ.vals, ties.method="min")
833-
seg.dur.vals <- load.static.nodelink.stats.scenes(object=object, weights="duration", measure=meas.name, filtered=FALSE)
833+
seg.dur.vals <- load.static.nodelink.stats.scenes(object=object, weights="duration", measure=meas.name, filtered="unfiltered")
834834
seg.dur.ranks <- rank(seg.occ.vals, ties.method="min")
835835

836836
for(weights in c("duration","occurrences"))
@@ -929,8 +929,8 @@ generate.static.plots.tfpn <- function(mode, window.sizes=NA, overlaps=NA)
929929

930930
# load the reference values (scene-based graph)
931931
data0 <- cbind(
932-
sapply(1:ncol(ms), function(i) load.static.graph.stats.scenes(object=object, weights="occurrences", measure=ms[m,i])),
933-
sapply(1:ncol(ms), function(i) load.static.graph.stats.scenes(object=object, weights="duration", measure=ms[m,i]))
932+
sapply(1:ncol(ms), function(i) load.static.graph.stats.scenes(object=object, weights="occurrences", measure=ms[m,i], filtered="unfiltered")),
933+
sapply(1:ncol(ms), function(i) load.static.graph.stats.scenes(object=object, weights="duration", measure=ms[m,i], filtered="unfiltered"))
934934
)
935935

936936
# generate a plot for each window size value
@@ -1071,7 +1071,8 @@ generate.static.plots.all <- function(mode, window.sizes, overlaps)
10711071
# filtered: whether to use the filtered version of the graph.
10721072
###############################################################################
10731073
generate.static.plots.scene <- function(arc=NA, vol=NA, filtered=FALSE)
1074-
{ tlog(3,"Generating plots for the ",if(filtered) "filtered" else "unfiltered"," scene-based graphs")
1074+
{ filt.txt <- if(filtered) "filtered" else "unfiltered"
1075+
tlog(3,"Generating plots for the ",filt.txt," scene-based graphs")
10751076
mode <- "scenes"
10761077
wmodes <- c("occurrences","duration")
10771078
col <- ATT_COLORS_FILT[if(filtered) "Keep" else "Discard"]
@@ -1097,7 +1098,7 @@ generate.static.plots.scene <- function(arc=NA, vol=NA, filtered=FALSE)
10971098
{ tlog(4,"Dealing with weights=",wmode)
10981099

10991100
# load pre-computed values (scene-based graph)
1100-
vals <- load.static.nodelink.stats.scenes(object=object, weights=wmode, measure=meas.name, arc=arc, vol=vol, filtered=filtered)
1101+
vals <- load.static.nodelink.stats.scenes(object=object, weights=wmode, measure=meas.name, arc=arc, vol=vol, filtered=filt.txt)
11011102
# remove possible NAs
11021103
vals <- vals[!is.na(vals)]
11031104
#vals <- vals[vals>0] # remove the zeroes?
@@ -1212,7 +1213,7 @@ generate.static.plots.evol <- function(data, arcs, filtered)
12121213
}
12131214

12141215
# init other variables
1215-
tlog(3,"Generating ",emode,"-based evolution plots for the ",if(filtered) "filtered" else "unfiltered"," scene-based graphs")
1216+
tlog(3,"Generating ",emode,"-based evolution plots for the ",filt.txt," scene-based graphs")
12161217
mode <- "scenes"
12171218
wmodes <- c("occurrences","duration")
12181219
col <- ATT_COLORS_FILT[if(filtered) "Keep" else "Discard"]
@@ -1234,7 +1235,7 @@ generate.static.plots.evol <- function(data, arcs, filtered)
12341235
for(i in 1:length(items))
12351236
{ vals[i] <- load.static.graph.stats.scenes(object=object, weights=wmode, measure=meas.name,
12361237
arc=if(arcs) i else NA, vol=if(arcs) NA else items[i],
1237-
filtered=filtered)
1238+
filtered=filt.txt)
12381239
}
12391240

12401241
# generate barplots

0 commit comments

Comments
 (0)