View source: R/flash_set_conv_crit.R
flash_set_conv_crit | R Documentation |
Used in a flash
pipeline to set the criterion for
determining whether a greedy fit or backfit has "converged."
flash_set_conv_crit(flash, fn = NULL, tol)
flash |
A |
fn |
The convergence criterion function (see Details below). If
|
tol |
The tolerance parameter (see Details below). The default, which is
set when the |
Function flash_set_conv_crit
can be used to customize
the convergence criterion for a flash
object. This criterion
determines when to stop optimizing a newly added factor
(see flash_greedy
) and when to stop backfitting
(flash_backfit
). Note that, because most alternative
convergence criteria do not make sense in the context of a nullcheck, it
does not set the "convergence" criterion for flash_nullcheck
(for example, flash_conv_crit_max_chg_L
would simply return
the maximum L^2
-normalized loading for each set of loadings
\ell_{\cdot k}
).
The criterion is defined by the function supplied as argument to fn
,
which 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
). The function must output a numeric value; if the value is
less than or equal to tol
, then the fit is considered to have
"converged." The meaning of "convergence" here varies according to the
operation being performed.
In the greedy algorithm, fn
simply compares the fit from
one iteration to the next. During a backfit, it similarly compares fits from
one iteration to the next, but it only considers the fit to have
converged when the value of fn
over successive updates to
all factor/loadings pairs is less than or equal to tol
. If,
for example, factor/loadings pairs 1, \ldots, K
are being
sequentially backfitted, then fits are compared before and
after the update to factor/loadings 1, before and after the update to
factor/loadings 2, and so on through factor/loadings K
,
and backfitting only terminates when fn
returns a value less
than or equal to tol
for all K
updates.
Package flashier
provides a number of functions that may be supplied
as convergence criteria: see
flash_conv_crit_elbo_diff
(the default criterion),
flash_conv_crit_max_chg
,
flash_conv_crit_max_chg_L
, and
flash_conv_crit_max_chg_F
. Custom functions may also be
defined. Typically, they will compare the fit in curr
(the current
iteration) to the fit in prev
(the previous iteration).
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 numeric value that can be compared against tol
; see
Examples below.
The flash
object from argument flash
, with the
new convergence criterion reflected in updates to the "internal"
flash_fit
object. These settings will persist across
all subsequent calls to flash_xxx
functions in the same
flash
pipeline (unless, of course, flash_set_conv_crit
is
again called within the same pipeline).
fl <- flash_init(gtex) %>%
flash_set_conv_crit(flash_conv_crit_max_chg, tol = 1e-3) %>%
flash_set_verbose(
verbose = 3,
fns = flash_verbose_max_chg,
colnames = "Max Chg",
colwidths = 20
) %>%
flash_greedy(Kmax = 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.