Last active
August 29, 2015 14:07
-
-
Save dustinvtran/1517d987dcb3da6dd109 to your computer and use it in GitHub Desktop.
pretty plotting for comparing stochastic approximation methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plot.risk <- function(data, est) { | |
# Plot estimated biases of the 4 optimization routines performed. | |
# | |
# Args: | |
# data: List of x, y, A, theta in particular form | |
# est: A list of matrix estimates, one for each set of optimization | |
# methods done on the data. | |
# | |
# Returns: | |
# A log-log plot with 4 curves, showing excess risk over training size. | |
library(dplyr) | |
library(ggplot2) | |
list.bias <- list() | |
for (i in 1:length(est)) { | |
values = apply(est[[i]], 2, function(colum) { | |
log( | |
t(colum-data$theta) %*% data$A %*% (colum-data$theta), | |
base=10 | |
) | |
}) | |
list.bias[[i]] = data.frame( | |
t=log(1:length(values), base=10), | |
est.bias=values, | |
method=names(est)[i] | |
) | |
} | |
# Create a data frame row binding each p x niters matrix for ggplot. | |
dat <- rbind( | |
list.bias[[1]], | |
list.bias[[2]], | |
list.bias[[3]], | |
list.bias[[4]] | |
) | |
# Aim to plot only every hundredth one. | |
dat <- dat[c(rep(FALSE, 99), TRUE), ] | |
# Plot. | |
dat %>% | |
ggplot(aes(x=t, y=est.bias, group=method, color=method)) + | |
geom_line() + | |
scale_x_continuous(limits=c(2, 5), breaks=c(2, 3, 4, 5)) + | |
ylim(-4, 4) + | |
ggtitle("Excess risk over training size") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment