-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotResultDist.R
53 lines (48 loc) · 1.67 KB
/
plotResultDist.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env Rscript
library(tidyr)
library(dplyr)
library(ggplot2)
library(jsonlite)
library(data.table)
# args = c('testExperiment', '0')
args = commandArgs(trailingOnly = TRUE)
if (length(args) != 2) {
stop("Must supply 2 arguments")
}
experimentName = args[1]
runId = args[2]
# Construct paths
runDir = paste('qaExperiments/', experimentName, '/run', runId, sep = '')
for (queryDir in list.dirs(runDir, recursive = FALSE)) {
queryId = regmatches(queryDir, gregexpr("[0-9]+$", queryDir))
baseFilename = paste(experimentName, '-', runId, '-', queryId, '-', sep = '')
basePath = paste(queryDir, '/', baseFilename, sep = '')
queryPath = paste(basePath, 'query.json', sep = '')
resultPath = paste(basePath, 'results.json', sep = '')
plotFilename = paste(baseFilename, 'plot.pdf', sep = '')
if (file.exists(resultPath)) {
# Read in JSON and make data frame
resultJSON = fromJSON(readLines(resultPath))
queryJSON = fromJSON(readLines(queryPath))
dataFrame = bind_rows(
"Learned result" = data.frame(
utterance = resultJSON$learnedResult$support,
probability = resultJSON$learnedResult$probs
),
"True result" = data.frame(
utterance = resultJSON$trueResult$support,
probability = resultJSON$trueResult$probs
),
.id = "id"
)
KL = resultJSON$KLDivergence
ggplot(dataFrame, aes(y=probability, x=utterance)) +
geom_bar(stat='identity', fill='blue') +
coord_flip() +
ggtitle(paste(queryJSON, collapse = '\n')) +
facet_wrap(~id) +
theme(plot.title = element_text(hjust = 0.5), text = element_text(size = 13)) +
ggsave(plotFilename,
path=queryDir)
}
}