Skip to content

Commit

Permalink
Added some comments explaining what the functions do in plot_function…
Browse files Browse the repository at this point in the history
…s.R.
  • Loading branch information
pcarbo committed Jul 27, 2024
1 parent a546328 commit c7a958c
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions code/plot_functions.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
# TO DO: Explain here what this function is for, and how to use it.
prepare_elbo_plot_data <- function (fits, e = 1) {
n <- length(fits)
labels <- names(fits)
for (i in 1:n) {
y <- fits[[i]]@logLiks
fits[[i]] <- data.frame(method = labels[i],
iteration = 1:length(y),
elbo = y)
}
out <- do.call(rbind,fits)
out$method <- factor(out$method,labels)
out$elbo <- max(out$elbo) - out$elbo + e
return(out)
}

# TO DO: Explain here what this function is for, and how to use it.
create_elbo_plot <- function (fits, k) {
# This function creates a plot comparing the improvement in the ELBO
# over time for multiple LDA runs. Input argument "k" is the number of
# topics and is only used to generate the plot title.
create_elbo_plot <- function (fits, timings, k) {
pdat <- prepare_elbo_plot_data(fits)
plot_colors <- c("dodgerblue","orange","darkblue","red")
plot_linetypes <- c("solid","solid","dashed","dashed")
Expand All @@ -31,3 +17,21 @@ create_elbo_plot <- function (fits, k) {
theme_cowplot(font_size = 10) +
theme(plot.title = element_text(size = 10,face = "plain")))
}

# This is used by create_elbo_plot to generate the data frame passed
# as input to ggplot().
prepare_elbo_plot_data <- function (fits, timings, e = 1) {
n <- length(fits)
labels <- names(fits)
for (i in 1:n) {
y <- fits[[i]]@logLiks
fits[[i]] <- data.frame(method = labels[i],
iteration = 1:length(y),
elbo = y)
}
out <- do.call(rbind,fits)
out$method <- factor(out$method,labels)
out$elbo <- max(out$elbo) - out$elbo + e
return(out)
}

0 comments on commit c7a958c

Please sign in to comment.