This function fits a variational posterior q(z) using a chosen normalizing flow. The objective is the ELBO:
fitflowvariational(
observed,
states = NULL,
flowtype = c("maf", "splinepwlin", "planar", "radial"),
flowspec = list(),
inittheta = NULL,
pxgivenz,
nmc = 256,
control = list()
)A list containing:
flow: the fitted flow model
elbo: final ELBO value
theta: optimized parameter vector (if applicable)
convergence: optim() convergence code
Observed empirical distribution Q (probability vector).
Optional vector of category names.
One of "maf", "splinepwlin", "planar", "radial".
A list specifying structural parameters (d, K, etc.).
Optional initial parameter vector for trainable flows.
A function mapping latent z to a categorical pmf.
Number of Monte Carlo samples for ELBO estimation.
List of control parameters passed to optim().
\(\log p(x | z) + \log p(z) - \log q(z)\)
The flow parameters (theta) are optimized via optim() when applicable
(MAF and spline flows). Planar and radial flows have no trainable parameters.
This function performs generic variational inference using a chosen
normalizing flow and a user-provided likelihood pxgivenz.
For specialized rare-event inference using:
Girsanov change of measure
Freidlin–Wentzell quasi-potential
see the wrapper functions:
fitflow_girsanov()
fitflow_FW()
These wrappers construct a tilted likelihood and then call
fitflowvariational() internally.