compute both the importance weights and the other terms ($\nabla_{\lambda} f(\epsilon_{m}',
\lambda')$ and $\nabla_{\lambda}|\text{det}_{J_f}(\epsilon_m,
\lambda)|$) required for evaluating the gradient itself.

The resulting importance sampling estimate for is

\^i\_ () \_[m=1]{}\^M w\_m, \[eq:impgrad\]

where the $i$ in $\nabla^i_{\lambda} \mathcal{L}(\lambda) $ refers to the importance-sampled estimate of the gradient. The computationally expensive part of the gradient $\nabla_{z} \log p(x, z_m)$ is already available and need not be computed. The rest of the terms are efficient to evaluate, and hence the whole gradient estimate is obtained in a fraction of a time compared to computing it from scratch. The importance weights are provided by $$w_m = 
  \frac{\phi(\epsilon_m')}{\phi(\epsilon_m)} \label{eq:weight}$$ and hence only require evaluating densities of the standard distribution underlying the approximation. The above description is summarized in Algorithm \[alg:impgrad\] and illustrated graphically in Figure \[fig:normal\].

It is also worth noting that if $f(\cdot)$ is constructed as a series of transformations, for example as element-wise transformations of reparameterized normal distribution as done by [@advi], then parts of the term $\nabla_{\lambda}|\text{det}_{J_f}(\epsilon'_m,
\lambda')|$ can (and naturally should) also be re-used. This is, however, of secondary importance compared to the computational saving of re-using $\nabla_z \log p(x, z_m)$.

A practical challenge with importance sampling is that 