View source: R/flash_set_verbose.R
flash_set_verbose | R Documentation |
Used in a flash
pipeline to set the output that will be printed
after each greedy or backfitting iteration.
flash_set_verbose(
flash,
verbose = 1L,
fns = NULL,
colnames = NULL,
colwidths = NULL
)
flash |
A |
verbose |
When and how to display progress updates. Set to A single tab-delimited table of values may also be output using
option |
fns |
A vector of functions. Used to calculate values to display
after each greedy/backfit iteration when |
colnames |
A vector of column names, one for each function in
|
colwidths |
A vector of column widths, one for each function in
|
Function flash_set_verbose
can be used to customize
the output that is printed to console while fitting a flash
object.
After each greedy or backfitting iteration (see, respectively,
flash_greedy
and flash_backfit
), each
function in argument fns
is successively evaluated and the
result is printed to console in a table with column names defined by
argument colnames
and column widths defined by argument
colwidths
.
Each function in fns
must accept exactly three parameters,
curr
, prev
, and k
: curr
refers to the
flash_fit
object from the current iteration; prev
,
to the flash_fit
object from the previous iteration;
and, if the iteration is a sequential backfitting iteration (that is, a
flash_backfit
iteration with argument
extrapolate = FALSE
), k
identifies the factor/loadings pair
that is currently being updated (in all other cases, k
is
NULL
). Package flashier
provides a number of functions that
may be used to customize output: see
flash_verbose_elbo
,
flash_verbose_elbo_diff
,
flash_verbose_max_chg
,
flash_verbose_max_chg_L
, and
flash_verbose_max_chg_F
. Custom functions may also be
defined. They might inspect the current flash_fit
object
via argument curr
; compare the fit in curr
to the fit from the
previous iteration (provided by argument prev
); or
ignore both flash_fit
objects entirely (for example, to
track progress over time, one might simply call Sys.time
).
To facilitate working with flash_fit
objects, package
flashier
provides a number of accessors, which are enumerated in
the documentation for object flash_fit
. Custom functions
should return a character string that contains the output exactly as it is
to displayed; see Examples below.
The flash
object from argument flash
, with the
new verbose settings reflected in updates to the "internal"
flash_fit
object. These settings will persist across
all subsequent calls to flash_xxx
functions until they are modified
by another call to flash_set_verbose
.
# Suppress all verbose output.
fl <- flash_init(gtex) %>%
flash_set_verbose(0) %>%
flash_greedy(Kmax = 5)
# Set custom verbose output.
sparsity_F <- function(curr, prev, k) {
g_F <- flash_fit_get_g(curr, n = 2)
g_F_pi0 <- g_F$pi[1] # Mixture weight of the "null" component.
return(g_F_pi0)
}
verbose_fns <- c(flash_verbose_elbo, flash_verbose_max_chg_F, sparsity_F)
colnames <- c("ELBO", "Max Chg (Tiss)", "Sparsity (Tiss)")
colwidths <- c(12, 18, 18)
fl <- flash_init(gtex) %>%
flash_set_verbose(
verbose = 3,
fns = verbose_fns,
colnames = colnames,
colwidths = colwidths
) %>%
flash_greedy(Kmax = 3)
# Output can be changed as needed.
fl <- flash_init(gtex) %>%
flash_set_verbose(verbose = 1) %>%
flash_greedy(Kmax = 5L) %>%
flash_backfit(verbose = 3) %>%
flash_greedy(Kmax = 1L)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.