2
0
Fork 0
CVE/simulations/plots.R

70 lines
2.9 KiB
R

### Method Compair plots.
for (file in list.files('results', pattern = 'method_compair_[0-9T-]+\\.csv')) {
# Read simulation result data set.
ds <- read.csv(file.path('results', file), stringsAsFactors = FALSE)
# Get dataset groups
datasets <- unlist(unique(ds["dataset"]))
# All seperate dataset plots into one file.
pdf(file.path('results', sub('.csv', '.pdf', file, fixed = TRUE)))
for (ds.name in datasets) {
boxplot(ds[ds["dataset"] == ds.name, colnames(ds) != "dataset"],
main = ds.name, ylab = 'Error', las = 2)
}
dev.off()
# Plot each dataset seperately.
for (ds.name in datasets) {
pdf(file.path('results', sub('.csv',
paste0('_', ds.name, '.pdf'),
file, fixed = TRUE)))
boxplot(ds[ds["dataset"] == ds.name, colnames(ds) != "dataset"],
main = ds.name, ylab = 'Error', las = 2)
dev.off()
}
}
### Method Compair plots for parameterized M2.
for (file in list.files('results', 'method_compair_M2_[0-9T-]+\\.csv')) {
# Read simulation results.
ds <- read.csv(file.path('results', file), stringsAsFactors = FALSE)
# Extract M2 dataset parameters.
pmix <- unique(ds$pmix)
lambda <- unique(ds$lambda)
# setup pdf file and plot layout.
pdf(file.path('results', sub('.csv', '.pdf', file, fixed = TRUE)),
width = 15, height = 10)
layout(matrix(seq(length(pmix) * length(lambda)),
ncol = length(lambda), byrow = TRUE))
for (p in pmix) {
for (l in lambda) {
boxplot(ds[ds$pmix == p & ds$lambda == l,
!(colnames(ds) %in% c("pmix", "lambda"))],
main = substitute(expression(paste(
lambda, ' = ', l, ', ', p[mix], ' = ', q
)), list(l = l, q = p)))
}
}
dev.off()
}
### Analyse predict dimension simulation.
for (file in list.files('results', 'predict_dim_compair_[0-9T-]+\\.csv')) {
# Read simulation result data set.
ds <- read.csv(file.path('results', file), stringsAsFactors = FALSE)
# Over all datasets (including M2 with default parameters)
true.dim <- ds$true.dim
dataset <- ds$dataset
df <- ds[!(colnames(ds) %in% c("true.dim", "dataset"))]
accuracy <- data.frame(
all = colMeans(df == true.dim),
M1 = colMeans(df[dataset == "M1", ] == true.dim[dataset == "M1"]),
M2 = colMeans(df[dataset == "M2", ] == true.dim[dataset == "M2"]),
M3 = colMeans(df[dataset == "M3", ] == true.dim[dataset == "M3"]),
M4 = colMeans(df[dataset == "M4", ] == true.dim[dataset == "M4"]),
M5 = colMeans(df[dataset == "M5", ] == true.dim[dataset == "M5"]),
M6 = colMeans(df[dataset == "M6", ] == true.dim[dataset == "M6"]),
M7 = colMeans(df[dataset == "M7", ] == true.dim[dataset == "M7"])
)
cat("Accuracy of simulation:", file, '\n')
print(accuracy)
}