diff options
author | Samuel Fadel <samuelfadel@gmail.com> | 2016-08-22 02:47:38 -0300 |
---|---|---|
committer | Samuel Fadel <samuelfadel@gmail.com> | 2016-08-22 02:47:38 -0300 |
commit | 609f5a8bd986b043e5a41088e4ebb7ba8c4b059a (patch) | |
tree | b6f6136a8387bbaf26c4a2fbed0daf1a3dfb27f7 | |
parent | efa744c5840e8ea7521aa0955956411dfe30120f (diff) |
plot.R: added relative improvements boxplots.
-rw-r--r-- | plot.R | 52 |
1 files changed, 51 insertions, 1 deletions
@@ -5,8 +5,10 @@ require(cowplot) require(gridExtra) require(logging) +source("util.R") + # Plots results for experiments of all techniques for a given measure and -# datasset. +# dataset. plot.measure <- function(ds, techniques, output.dir, measure, n.iter=30) { measure.df <- data.frame() scale.labels <- c() @@ -54,6 +56,53 @@ plot.measures <- function(datasets, techniques, measures, output.dir, n.iter=30) } } +# Plots relative improvements for all techniques for a given measure and +# dataset. +plot.ri.measure <- function(ds, techniques, output.dir, measure, n.iter=30) { + df <- data.frame() + scale.labels <- c() + + #r.cp <- read.table(file.path(output.dir, ds$name, paste("r-cp-", measure$name, ".tbl", sep="")))$V1 + for (tech in techniques) { + r <- read.table(file.path(output.dir, ds$name, tech$name, paste("r-", measure$name, ".tbl", sep="")))$V1 + df <- rbind(df, data.frame(name=tech$name.pretty, + type=paste("Y", tech$name, ")", sep=""), + V1=r) + ) + + scale.labels <- c(scale.labels, tech$name.pretty) + } + + p <- ggplot(df) + + background_grid(major="xy", minor="none") + + theme(legend.position="none") + + labs(x="", y=measure$name.pretty) + + geom_boxplot(aes(type, V1, fill=name)) + + scale_fill_brewer(palette="Set1", guide=guide_legend(title="")) + + scale_y_continuous(limits=c(min(1, min(df$V1)), max(1, max(df$V1)))) + + scale_x_discrete(labels=scale.labels) + + fname <- file.path(output.dir, "plots", ds$name, paste("r-", measure$name, ".pdf", sep="")) + loginfo("Saving plot: %s", fname) + save_plot(fname, p, base_aspect_ratio=2) +} + +# Plot boxplots of all techniques measures per dataset. +plot.ri <- function(datasets, techniques, measures, output.dir, n.iter=30) { + dir.create.safe(file.path(output.dir, "plots")) + + for (ds in datasets) { + dir.create.safe(file.path(output.dir, "plots", ds$name)) + for (measure in measures) { + if (is.null(ds$labels.file) && measure$name == "silhouette") { + next + } + + plot.ri.measure(ds, techniques, output.dir, measure, n.iter) + } + } +} + # Same as above, but averages over all datasets. plot.averages <- function(datasets, techniques, measures, output.dir, n.iter=30) { dir.create.safe(file.path(output.dir, "plots")) @@ -158,3 +207,4 @@ addHandler(writeToFile, plot.measures(datasets, techniques, measures, output.dir) plot.averages(datasets, techniques, measures, output.dir) plot.scatter(datasets, techniques, measures, output.dir) +plot.ri(datasets, techniques, measures, output.dir) |