tensor_predictors/sim/plots.R

89 lines
3.6 KiB
R

if (!endsWith(getwd(), "/sim")) {
setwd("sim")
}
file.prefix <- "sim-ising-small"
date <- "20221012" # yyyymmdd, to match all "[0-9]{6}"
time <- "[0-9]{4}" # HHMM, to match all "[0-9]{4}"
sim <- Reduce(rbind, Map(function(path) {
df <- read.csv(path)
df$n <- as.integer(tail(head(strsplit(path, "[-.]")[[1]], -1), 1))
df
}, list.files(".", pattern = paste0(
"^", file.prefix, "-", date, "T", time, "-[0-9]+[.]csv$", collapse = ""
))))
stats <- aggregate(. ~ n, sim, mean)
q75 <- aggregate(. ~ n, sim, function(x) quantile(x, 0.75))
q25 <- aggregate(. ~ n, sim, function(x) quantile(x, 0.25))
colors <- c(gmlm = "#247407", hopca = "#2a62b6", pca = "#a11414", tsir = "#9313b9")
line.width <- 1.75
margins <- c(5.1, 4.1, 4.1, 0.1)
layout(mat = matrix(c(
1, 2,
3, 3
), 2, 2, byrow = TRUE),
widths = c(1, 1),
heights = c(8, 1), respect = FALSE)
# layout.show(3)
with(stats, {
par(mar = margins)
plot(range(n), c(0, 1.05),
type = "n", bty = "n", main = "Subspace Distance",
xlab = "Sample Size", ylab = "Error")
lines(n, dist.subspace.gmlm, col = colors["gmlm"], lwd = line.width)
lines(n, dist.subspace.hopca, col = colors["hopca"], lwd = line.width)
lines(n, dist.subspace.pca, col = colors["pca"], lwd = line.width)
lines(n, dist.subspace.tsir, col = colors["tsir"], lwd = line.width)
xn <- c(q75$n, rev(q25$n))
polygon(x = xn, y = c(q75$dist.subspace.gmlm, rev(q25$dist.subspace.gmlm)),
col = adjustcolor(colors["gmlm"], alpha.f = 0.3), border = NA)
polygon(x = xn, y = c(q75$dist.subspace.hopca, rev(q25$dist.subspace.hopca)),
col = adjustcolor(colors["hopca"], alpha.f = 0.3), border = NA)
polygon(x = xn, y = c(q75$dist.subspace.pca, rev(q25$dist.subspace.pca)),
col = adjustcolor(colors["pca"], alpha.f = 0.3), border = NA)
polygon(x = xn, y = c(q75$dist.subspace.tsir, rev(q25$dist.subspace.tsir)),
col = adjustcolor(colors["tsir"], alpha.f = 0.3), border = NA)
# par(mar = rep(0, 4))
# legend("topright", legend = names(colors), col = colors, lwd = line.width,
# lty = 1, bty = "n")
# par(mar = margins)
})
with(stats, {
par(mar = margins)
plot(range(n), c(0, 1.05),
type = "n", bty = "n", main = "RMSE (Prediction Error)",
xlab = "Sample Size", ylab = "Error")
xn <- c(q75$n, rev(q25$n))
polygon(x = xn, y = c(q75$error.pred.gmlm, rev(q25$error.pred.gmlm)),
col = adjustcolor(colors["gmlm"], alpha.f = 0.3), border = NA)
polygon(x = xn, y = c(q75$error.pred.hopca, rev(q25$error.pred.hopca)),
col = adjustcolor(colors["hopca"], alpha.f = 0.3), border = NA)
polygon(x = xn, y = c(q75$error.pred.pca, rev(q25$error.pred.pca)),
col = adjustcolor(colors["pca"], alpha.f = 0.3), border = NA)
polygon(x = xn, y = c(q75$error.pred.tsir, rev(q25$error.pred.tsir)),
col = adjustcolor(colors["tsir"], alpha.f = 0.3), border = NA)
lines(n, error.pred.gmlm, col = colors["gmlm"], lwd = line.width)
lines(n, error.pred.hopca, col = colors["hopca"], lwd = line.width)
lines(n, error.pred.pca, col = colors["pca"], lwd = line.width)
lines(n, error.pred.tsir, col = colors["tsir"], lwd = line.width)
# par(mar = rep(0, 4))
# legend("topright", legend = names(colors), col = colors, lwd = line.width,
# lty = 1, bty = "n")
# par(mar = margins)
})
par(mar = c(0, 1, 1, 0))
plot(1:2, 1:2, type = "n", bty = "n", axes = FALSE, xlab = "", ylab = "")
legend("center", legend = names(colors), col = colors, lwd = line.width,
lty = 1, bty = "n", horiz = TRUE)