
A summed i.i.d. log-likelihood with the observation held fixed
Source:R/likelihood.R
de_iid_evaluator.Rdlog_lik() and every MCMC step ask the same question over and over: the
summed log-density of one fixed set of observations under a theta that
changes. de_iid_evaluator() returns a closure over the observations, so
whatever an estimator can settle once settles when the closure is built
rather than on every call. For the MDN that is coercing the observations to
a tensor, which at a few thousand rows is not a rounding error next to the
forward pass.
Details
Reducing inside the closure matters as much as the hoisting. The
n_theta x n_obs matrix is the largest object in the loop and none of it is
wanted, so the sum happens where the log-densities are produced and only
n_theta numbers ever cross back into R.
Estimators need a method here only if they can beat the default, which is
de_log_lik_iid() with its row sums taken block by block.