Manuscript Offprint
arXiv:2610.17151Implicit and explicit reparameterizations of the Folded Normal and Rice distributions
Synopsis
Implicit and explicit reparameterized gradient estimators for the folded Normal and Rice distributions are derived, implemented, and applied to French–Wilson scaling of X-ray diffraction data by variational inference.
Abstract
Variational inference is a flexible tool for modeling experimental data and has proven useful in crystallography. Pathwise gradient estimators provide low-variance gradients for reparameterized variational inference, but are not readily available for some distributions central to crystallography. This work derives and implements implicit and explicit reparameterized gradient estimators for the folded Normal and Rice distributions in PyTorch, and compares their variance analytically and empirically. In each case the implicit estimator achieves lower variance for the location derivative, particularly at small location-to-scale ratios, while the scale-derivative variances are nearly equal. For both distributions, implicit estimator is proved to be the conditional expectation of the explicit estimator given the sampled magnitude, so its variance is never larger. As a practical application, French-Wilson scaling is formulated as a variational inference problem, using the folded Normal and Rice distributions as variational families for centric and acentric reflections, respectively. Both estimators recover the exact posterior to better than 1% on the amplitude, and converge at the same rate. The implementations are available in the open-source package rs-distributions.
Keywords: reparameterization trick; folded Normal distribution; variational inference; Rice distribution; French–Wilson scaling
In this work we implement explicit and implicit pathwise estimators for the folded Normal (henceforth FoldedNormal) and Rice distributions. The FoldedNormal distribution was first characterized by Leone et al. (1961), but the underlying model appears in X-ray crystallography as early as 1956, in the heavy-atom phasing analysis of Woolfson (1956). Beyond crystallography, the FoldedNormal appears in applications ranging from biomedical modeling (Liu et al., 2020) to economics (Liao, 2010) and signal processing (Reig et al., 2019). The Rice distribution, introduced by Rice (1944), is the distribution of the magnitude of a complex normal variable with nonzero mean and isotropic covariance. It arises in magnetic resonance imaging (MRI) (Gudbjartsson & Patz, 1995; Lauwers et al., 2010), wireless communications (Marcum, 1960; Simon & Alouini, 2008), and crystallography (Read & McCoy, 2016).
Our interest is in crystallography, where these distributions first appeared when Wilson (1949) analyzed the statistics of diffraction intensities. He showed that the centric and acentric structure factor amplitude distributions are, respectively, the half-normal and Rayleigh distributions, which are special cases of the FoldedNormal (with ) and Rice (with ) that arise in the absence of prior structural information. More recently, the FoldedNormal and Rice distributions have taken on a new role in gradient-based structure determination and data reduction, where one conditions on partial structural information and then integrates over the unobserved phase, producing FoldedNormal or Rice likelihood functions (Bricogne, 1997; Pannu & Read, 1996). For example, ROCKET refines AlphaFold2 predictions against diffraction data by optimizing intensity-based likelihoods built from the FoldedNormal (centric) and Rice (acentric) distributions (Fadini et al., 2026). Similarly, the diffusion-based CrystalBoltz guides sampling with a likelihood built from the same two distributions (Kim et al., 2026), and Careless uses the half-normal and Rayleigh distributions as priors on structure factor amplitudes (Dalton et al., 2022; Aldama et al., 2023; Hekstra et al., 2025). Such applications, which backpropagate through these likelihoods, motivate efficient and differentiable implementations of the underlying FoldedNormal and Rice sampling paths.
We characterize and compare the behavior of implicit and explicit gradient estimators for these distributions, both analytically and empirically. For both the FoldedNormal and the Rice distributions, we prove a variance ordering between the two estimators by recognizing the implicit estimator as the conditional expectation of the explicit estimator given the sampled magnitude and applying the law of total variance. As a practical application, we use these reparameterizations to formulate French–Wilson scaling (French & Wilson, 1978) as a variational inference problem, demonstrating that our distributions can serve as effective variational families for crystallographic structure factor estimation. Our implementations are provided in our open-source PyTorch package rs-distributions.
1.1 Explicit and implicit gradient estimators
In this section we set up the notation and mathematical framework for stochastic gradient estimation. We assume an objective function of the form
where is a test function of variates from a distribution with distributional parameters . The gradient of equation 1 with respect to , , is our estimand of interest. Both the implicit and explicit reparameterization methods yield estimators for (Figurnov et al., 2018; Kingma & Welling, 2019). These methods are known as pathwise gradient estimators, and they use the sampling path of . Samples can be generated by either (1) directly sampling from the distribution , or (2) first drawing samples from a simpler base distribution and transforming the sample with a deterministic function , which is referred to as a sampling path. The sampling path and the Law of the Unconscious Statistician (Grimmett & Stirzaker, 2020) allow us to rewrite the expectation in equation 1 as one over the base distribution
The estimand of interest becomes
(3)
where we assume the standard regularity conditions — almost-sure differentiability of the sampling path and an integrable local dominating function — that justify exchanging differentiation and integration in the third line (Glasserman, 2003; Mohamed et al., 2020). In explicit reparameterization (Figurnov et al., 2018), base samples are transformed with a sampling path g, giving the Monte
https://github.com/rs-station/distributions
Carlo estimator
Under explicit reparameterization, the sampling path is built from an invertible standardization function that maps the -dependent variable to a variate , where the base distribution does not depend on . For the FoldedNormal, the base distribution is the standard normal , and the standardization is that of the underlying normal . This standardization is , so that . The sampling path is then a composition of the inverse standardization function, , and the absolute-value transform, . We note that explicit reparameterization requires an invertible standardization function; the outer transform (here ) does not need to be invertible.
For some distributions, the standardization function has no closed-form inverse, or that inverse is too expensive to compute. In this case, one can use implicit reparameterization (Figurnov et al., 2018), which does not require inverting the standardization function. Instead, implicit reparameterization differentiates the standardization relation directly. Holding the standardized sample fixed and differentiating with respect to yields the pathwise derivative , which needs only and its derivatives, not its inverse. Here, the Monte Carlo estimator takes the form
(5)
where denotes the implicit Monte Carlo estimator (equation 5). Throughout, the subscript on denotes the parameter with respect to which the derivative is taken, and the superscripts E and I distinguish the explicit and implicit estimators.
2 Implementation
In this section we derive the implicit and explicit gradient estimators of the FoldedNormal and Rice distributions, and we implement them in PyTorch (Paszke et al., 2019). To validate our implementations, we use a test function with analytical derivatives that serve as ground truths. We also derive the theoretical variance of each estimator, and we check our empirical results against it.
2.1 FoldedNormal distribution
Let and let , so that . The density of is a sum of two Normal densities,
where the two terms are the contributions of the pre-images and . The special case recovers the half-normal distribution, which serves as the centric Wilson prior in Section 3.
2.1.1 FoldedNormal: test function
We validate our implicit and explicit FoldedNormal implementations against the test function , which has closed-form derivatives. The expectation of the test function, , follows from the FoldedNormal variance identity
and the second-moment expansion
(8)
Differentiating with respect to and gives us the ground truth derivatives
2.1.2 FoldedNormal: explicit estimator
A FoldedNormal( ) random variable is the absolute value of a Normal( ) random variable (Leone et al., 1961). The standardization function for a Normal( ) distribution is , so that . The sampling path for is given by
where is obtained from the inverse standardization function (the location-scale transform). We use explicit reparameterization to construct a Monte Carlo gradient estimator
(equation 4) of the form
(11)
where is the number of Monte Carlo samples, is the test function, and . Taking the - and -components of equation 11 yields estimators of the ground-truth derivatives (equation 9)
We refer to and as the explicit location- and scale-derivative estimators, respectively. In Section S1 of the supporting information, we show that these estimators are unbiased, and that their variance is given by
2.1.3 FoldedNormal: implicit estimator
When deriving the explicit pathwise estimator, we used the Normal distribution standardization function to construct the sampling path. Alternatively, we can use the FoldedNormal cumulative distribution function (CDF), denoted by , as the standardization function (Figurnov et al., 2018). In this case, the standardization function does not admit a closed-form inverse, so we use implicit reparameterization instead. The implicit Monte Carlo estimator is given by
(14)
where in the second line we used the fact that the derivative of the CDF is the probability density function (PDF) . Taking the - and -components of equation 14 yields the following Monte Carlo estimators (derived in Section S2 of the supporting information),
(15) and
where is the PDF of the standard Normal distribution, , and .
2.1.4 FoldedNormal: variance ordering
The explicit and implicit estimators defined above produce different per-sample gradient estimates. The explicit estimator depends on the sign of the underlying Normal sample (through ), whereas the implicit estimator depends only on the FoldedNormal sample .
Theorem 1 (Variance ordering of FoldedNormal derivative estimators). Let and let be continuously differentiable with . For , the single-sample explicit and implicit derivative estimators of satisfy
Consequently, the implicit estimator is unbiased, and its variance is bounded above by the variance of the explicit estimator,
The proof of Theorem 1 is given in Appendix A. In the proof of Theorem 1, we decompose the explicit variance by the law of total variance, yielding the following expression
which we use to derive the variance of the implicit location- and scale-derivative estimators:
The term does not have a closed form but can be approximated with numerical quadrature. Our full derivation of equation 20 is in Appendix B.
2.2 Rice distribution
Let be a bivariate Normal vector with independent components and . Let , so that with and . The Rice law depends on only through its norm ; the direction of is not identifiable. The density of R is
where is the modified Bessel function of the first kind, order zero. The special case recovers the Rayleigh distribution, which appears as the acentric Wilson prior in Section 3.
2.2.1 Rice: test function
We validate the Rice estimators against the test function , whose expectation has a closed-form gradient. Expanding the expectation, we get
Differentiating with respect to the Rice parameters and gives us the ground truth derivatives
2.2.2 Rice: explicit estimator
Each component of follows a Normal distribution, so the sampling path for can be written in terms of two independent standard Normal variables,
where . Since , explicit reparameterization produces derivatives with respect to and , rather than . Using the sampling path and the test function , we obtain the unbiased derivative estimators (derived in Section S3 of the supporting information)
(25)
Because the Rice law depends on only through , we align the mean with the first coordinate without loss of generality, , so the location derivative is the single-component derivative . For a general mean, the -derivative is the projection , whose continuous limit at is described in Section S3 of the supporting information. The variance of these estimators is given by
2.2.3 Rice: implicit estimator
The CDF of the Rice distribution is given by
where is the first-order Marcum Q-function (Marcum, 1960; Simon & Alouini, 2008). The partial derivatives of the Rice CDF are known (Pratt, 1968), and we use them to derive the implicit reparameterization gradients in Section S4 of the supporting information. Writing for the argument of the modified Bessel functions ( and ), the implicit pathwise derivatives are
For any differentiable test function f, the implicit Monte Carlo gradient estimators are
and
where .
2.2.4 Rice: variance ordering
As in the FoldedNormal case, the explicit and implicit estimators produce different per-sample gradient estimates. Writing and for the unit sample and mean directions, the explicit estimator depends on the cosine of the angle between the sample and the mean direction, , whereas the implicit estimator depends only on the magnitude .
Theorem 2 (Variance ordering of Rice derivative estimators). Let and let be continuously differentiable with . For , the single-sample explicit and implicit derivative estimators of satisfy
Consequently, the implicit estimator is unbiased, and its variance is bounded above by the variance of the explicit estimator,
The proof of Theorem 2 is given in Appendix C. This is the exact analogue of Theorem 1, with the magnitude R playing the role of the FoldedNormal sample Y, and the sampled direction on the circle playing the role of sign(X). In both cases the implicit estimator is the Rao–Blackwellization of the explicit one (Casella & Robert, 1996; Lam et al., 2025), obtained by conditioning on the magnitude and averaging over the direction.
The variance of the implicit location- and scale-derivative estimators is given by
with again evaluated by numerical quadrature (derivation in Appendix D).
3 Application: French–Wilson scaling
X-ray crystallography is routinely used for determining the three-dimensional electron density of a molecule from its diffraction data. Doing so requires determining complex-valued terms called structure factors, which we denote by . In practice, data reduction algorithms are used to estimate the intensity (I) of each structure factor. The intensity is related to the squared amplitude (F) of the structure factors, . Although the intensity is strictly non-negative by definition, data processing algorithms may return negative intensities. These negative values cannot be used by subsequent algorithms, and they must either be discarded or mapped to non-negative values.
French & Wilson (1978) address negative integrated intensities with a Bayesian correction. The idea is to use Bayes' theorem to obtain the following posterior distribution
where is the true intensity, is a measured intensity, is a Wilson prior, and is a Normal likelihood. The Wilson prior is given by
where the centric prior is a half-normal distribution and the acentric prior is a Rayleigh distribution, the zero-location special cases of the FoldedNormal and Rice families whose estimators we derived above. Thus, the posterior is proportional to the product of a Normal likelihood and Wilson prior, and the posterior has positive support.
To demonstrate one use of our reparameterizations, we approximate the French–Wilson posterior using variational inference (Jordan et al., 1998; Blei et al., 2017). In particular, we use the FoldedNormal and Rice distributions to approximate the centric and acentric posterior distributions, respectively. Employing these distributions in this way builds on a history of “inflated-variance” Rice distributions that combine prior information on structure factor amplitudes with experimental observations (Green, 1979; Read & McCoy, 2016).
Let denote the variational distribution, where for centric reflections and for acentric reflections. The objective function used in variational inference is called the Evidence Lower Bound (ELBO), which is given by
where is the expected log-likelihood, is the Kullback–Leibler divergence, and for centrics or for acentrics. No closed form of the Kullback–Leibler divergence exists for either the FoldedNormal or the Rice, so we estimate the ELBO itself with the following Monte Carlo estimator
We evaluate on a synthetic dataset of 2,240 samples, and on a hen egg-white lysozyme experimental dataset (PDB: 9B7C). The supporting information gives the optimization protocol and learning rates (Section S5, Table S1), and the datasets and the reference calculations they are scored against (Section S6).
4 Results
4.1 Variance of the FoldedNormal estimators
The explicit and implicit FoldedNormal gradient estimators are unbiased, and their variances scale as 1/N with the number of Monte Carlo samples (Fig. 1). For the derivative with respect to , the implicit estimator exhibits lower variance than the explicit estimator, and by Theorem 1 its variance is given by equation 20 (Fig. 1, left). For the derivative with respect to , the empirical variances of the explicit estimator and the implicit estimator nearly overlap and match the theoretical prediction from equation 13 (Fig. 1, right). The variances of the explicit and implicit FoldedNormal location-derivative estimators across a parameter grid are shown in Fig. 2, and the scale-derivative variances in Fig. S1. Figure 3 shows the variance ratio , which is independent of the number of Monte Carlo samples N, and lies in [0, 1] since the explicit variance is an upper bound on the implicit variance. The variance ratio of the location-derivative falls to 0 as , while the scale-derivative ratio dips to 0.90 near . We note that as both ratios approach 1, implying that the estimators exhibit approximately the same variance.

Figure 1: Theoretical and empirical variance of the FoldedNormal pathwise estimators as a function of Monte Carlo sample size N, at , (small ). Left, the derivative with respect to ; right, the derivative with respect to . The two empirical curves match their respective theoretical predictions: for the explicit estimator and equation 20 for the implicit estimator (left), where the expected conditional variance is the analytical gap from Theorem 1. For the derivative (right) both empirical curves coincide with the theoretical prediction of equation 13. At this parameter setting, the implicit derivative estimator achieves variance roughly 50-fold smaller than the explicit estimator.
Variance of the Location Derivative Estimator for FoldedNormal Distributions

Figure 2: Theoretical (top) and empirical (bottom) variance of the explicit ( ) and implicit ( ) FoldedNormal derivative estimators of as a function of and . The colorbar denotes the variance value for each pair. The empirical variance was computed across 10,000 simulations using 100 Monte Carlo samples each. The theoretical variance was calculated using equations 13 and 20, for the explicit and implicit estimators, respectively.

Figure 3: Variance ratio of the implicit FoldedNormal estimator relative to the explicit estimator, as a function of the location-to-scale ratio , for the test function . Because the explicit variance is the upper bound, the ratio lies in and is independent of the number of Monte Carlo samples. The location-derivative ratio falls to 0 at small , while the scale-derivative ratio dips only to 0.90 near .
4.2 Variance of the Rice estimators
The Rice estimators exhibit qualitatively the same pattern as the FoldedNormal case, with both variances scaling as 1/N (Fig. 4). For the derivative with respect to , the implicit estimator exhibits lower variance than the explicit estimator, and by Theorem 2 its variance is given by equation 34, with the largest improvement at small (Fig. 4, left). For the derivative with respect to , the explicit and implicit empirical variances nearly overlap and match the theoretical prediction (Fig. 4, right). In both panels the empirical variances match their respective theoretical curves. The variances of the explicit and implicit Rice location-derivative estimators across the parameter grid are shown in Fig. 5, and the scale-derivative variances in Fig. S2. As with the FoldedNormal case, Fig. 6 summarizes the magnitude of the improvement as the variance ratio, which shows that the location-derivative ratio falls to 0 as , while the scale-derivative ratio dips only to 0.90 near .

Figure 4: Theoretical and empirical variance of the Rice pathwise estimators as a function of Monte Carlo sample size N, at , (small ). Left, the derivative with respect to ; right, the derivative with respect to . The two empirical curves match their respective theoretical predictions: for the explicit estimator and equation 34 for the implicit estimator (left), where the expected conditional variance is the analytical gap from Theorem 2; for the derivative (right) the theoretical curves coincide with the empirical curves. For the derivative at this parameter setting, the implicit estimator achieves variance roughly 100-fold smaller than the explicit estimator.
4.3 French–Wilson scaling
We evaluate the variational French–Wilson model on a synthetic dataset of 2,240 samples. To obtain reference values, we evaluate the exact posterior by quadrature and take its mean and standard deviation as the reference amplitude and uncertainty . We ask whether the choice of estimator, explicit or implicit, affects (1) how well each recovers the reference moments, and (2) the rate of convergence. The model is trained using five different optimization algorithms: stochastic
Variance of the Location Derivative Estimator for Rician Distributions

Figure 5: Theoretical (top) and empirical (bottom) variance of the explicit ( ) and implicit ( ) Rice derivative estimators of as a function of and . The colorbar denotes the variance value for each pair. The empirical variance was computed across 10,000 simulations using 100 Monte Carlo samples each. The theoretical variance was calculated using equations 26 and 34, for the explicit and implicit estimators, respectively.
gradient descent (Robbins & Monro, 1951) with and without momentum (Polyak, 1964), RMSprop (Tieleman & Hinton, 2012), Adam (Kingma & Ba, 2015) and AdaBelief (Zhuang et al., 2020). The model is also applied to an experimental dataset (PDB: 9B7C).
4.3.1 Agreement with synthetic reference
We use the mean and standard deviation of the approximate posterior as point estimates for the amplitude and its uncertainty, which we denote by and , respectively. Agreement between the point estimates and the reference is reported as the mean absolute percentage error and .
The variational approximation recovers both the mean and standard deviation of the reference posterior (Fig. 7). With the Adam optimizer and Monte Carlo samples, the explicit estimator matches the reference centric amplitudes to 0.67% and the acentric amplitudes to 0.33%,

Figure 6: Variance ratio of the implicit Rice estimator relative to the explicit estimator, as a function of the location-to-scale ratio , for the test function . As in the FoldedNormal case, the ratio lies in and is independent of the number of Monte Carlo samples. The location-derivative ratio falls to 0 at small , while the scale-derivative ratio dips only to 0.90 near .
and the centric and acentric posterior standard deviations to 2.41% and 1.67%. The implicit estimator matches the same four quantities, in the same order, to 0.93%, 0.53%, 2.57% and 1.81%. All four errors decrease with an increasing number of Monte Carlo samples, and reach the lowest error at the largest N we tested. Table S2 gives the same four quantities at N = 512 for every optimization algorithm, and Fig. S3 shows their dependence on N.
Acentric amplitudes are recovered more accurately than centric ones at every N, under every optimization algorithm (Fig. S3). With respect to acentric reflections, the two estimators are indistinguishable under RMSprop and both forms of stochastic gradient descent; the implicit estimator is less accurate under Adam and AdaBelief. For centric reflections, the implicit estimator is less accurate under RMSprop, Adam and AdaBelief; and the two estimators are indistinguishable under both forms of stochastic gradient descent. Under Adam and AdaBelief, the difference in accuracy between the two estimators falls steadily as the number of Monte Carlo samples grows.
4.3.2 Effect of the reparameterizations on training
We measured the ratio of the implicit to explicit gradient variance at the initial and final step of training, for both reparameterizations and all five optimizers. Both estimators are evaluated at the same variational parameters. The measurement was replicated ten times for each estimator/optimizer pairing. We then binned the per-reflection ratios by the reflection's observed signal-to-noise ratio , and report the median and interquartile range in each bin (Figs. S4 and S5).
At initialization the centric location ratio ranges from 0.23 to approximately 1.0, over bins with ; and the acentric location ratio ranges from 0.61 to 1.0 over the same bins. The variance ratio for the scale derivatives is approximately 1.0 at the start and end of training. By convergence,
Recovery of the reference posterior (Adam)

Monte Carlo samples
Figure 7: Recovery of the reference posterior, optimized with Adam, as a function of the number of Monte Carlo samples N used per gradient. Panels show the amplitude F and the posterior width , plotted separately for centric and acentric reflections. Each point is a median over ten replicates, and the bands span the interquartile range (too narrow to visualize). The same comparison for all five optimization algorithms is given in Fig. S3.
the centric location ratio rises from its initial ratio in bins with . This indicates that the parameters have moved to a regime where the implicit and explicit variances are similar. Thus, the reduced variance of the implicit estimator is largest at the start of training for weak centric reflections, and that reduction disappears by the end of training. We next ask whether the implicit estimator's lower variance at the start of training has any effect on the rate of convergence or on the agreement of the final estimates.
The two estimators reduce the error at the same rate over most of training (Fig. S6). Under plain stochastic gradient descent and stochastic gradient descent with momentum, the two curves coincide, differing by no more than 0.02 percentage points at any recorded step. For RMSprop, the two curves are indistinguishable early in training, differing by at most 0.03 percentage points through step 1,000. Adam and AdaBelief use different learning rates because we tuned the learning rates for each optimizer before carrying out our experiments (Section S5 of the supporting information). The implicit estimator uses a learning rate 3.3 times larger than the explicit estimator (Table S1). Although the implicit estimator uses a higher learning rate, the two estimators converge to nearly the same ELBO value, and the explicit estimator achieves a lower mean absolute percentage error.
The variance difference between the two estimators is largest for centric reflections with non-positive intensity ( ). Therefore, we split the centric reflections into positive and non-positive intensities, and we plot the difference in amplitude recovery between the two estimators (Fig. 8). For both positive and non-positive intensities, we see that the two estimators agree more with each other as a function of increasing Monte Carlo samples N. In the non-positive bin, where the variances differ the most, the explicit estimator is the more accurate of the two under the adaptive optimizers. Under stochastic gradient descent, with and without momentum, the accuracy is nearly identical. We also observe that the explicit estimator is more accurate in the positive bin under Adam and AdaBelief, while RMSprop and the stochastic gradient descent variants agree almost exactly.
The difference in accuracy between the explicit and implicit estimators (under the Adam optimizer) narrows with longer training, but it does not vanish. We trained our model with the Adam optimizer for 200,000 training steps, using only the centric reflections, and N = 512 Monte Carlo samples. The median difference in centric amplitude error is 0.47 percentage points at 10,000 steps, 0.27 at 25,000, and 0.25 at 200,000. Most of the narrowing happens within the first 25,000 steps, and the remaining 175,000 close the gap by 0.03 percentage points.
centric,
centric,

Monte Carlo samples per step
Monte Carlo samples per step
Figure 8: Difference in amplitude mean absolute percentage error (MAPE) against the reference posterior (implicit minus explicit), as a function of number of Monte Carlo samples used at each training step. Left, the centric reflections at or below zero intensity, where the two gradient variances differ; right, intensities with , where the implicit and explicit gradient variances are approximately the same. Positive values favor the explicit estimator at this number of optimization steps. Points are means over the ten per-replicate paired differences, and the bands are one standard error of the mean.
4.3.3 Application to an experimental dataset
We used our model on a hen egg-white lysozyme dataset containing 45,196 unique reflections that span a resolution range between 56.1 and 1.10 Å (PDB: 9B7C). The dataset contains 4,791 centric reflections, and 2.9% of the reflections are non-positive ( ) (Section S6 of the supporting information). We binned the data into resolution bins to estimate the mean intensity of each bin for the Wilson prior (Section S6 of the supporting information). The fitted amplitudes are scored against numerical quadrature of the same posterior, as in Section 4.3.1. Only the Adam optimizer was used because of its prevalence in modern machine learning algorithms. A total of 25,000 steps were used for training, and Monte Carlo samples were used for the gradient estimators. As a sanity check, we also used the cctbx French–Wilson scaling algorithm (Grosse-Kunstleve et al., 2002) on the same set of reflections.
The variational posterior amplitudes agree with the quadrature to 0.12% for the explicit estimator, and to 0.17% for the implicit estimator (Table 1). The explicit estimator is more accurate (in terms of mean absolute percentage error) than the implicit, on acentric and centric reflections, for both the amplitude and uncertainty. The cctbx French–Wilson implementation agrees with the quadrature to 0.10%, and recovers the posterior standard deviations more closely than variational inference.
Table 1: The mean absolute percentage error of each method against the exact posterior, evaluated on an experimental hen egg-white lysozyme dataset (PDB: 9B7C).
| Method | error (%) | error (%) | ||
|---|---|---|---|---|
| centric | acentric | centric | acentric | |
| Explicit | 0.22 | 0.11 | 1.76 | 1.54 |
| Implicit | 0.28 | 0.15 | 2.06 | 1.82 |
| cctbx | 0.06 | 0.11 | 0.07 | 0.39 |
5 Conclusion
We implemented implicit and explicit gradient estimators of the FoldedNormal and Rice distributions in PyTorch, available in the open-source package rs-distributions. We validated the FoldedNormal and Rice derivative estimators against analytical ground truths for the test functions and , respectively, and confirmed that the estimators are unbiased. For both the FoldedNormal and the Rice distributions, we proved that the implicit estimator is the conditional expectation of the explicit estimator given the sampled magnitude (Theorems 1 and 2). Consequently, the law of total variance yields a variance bound that holds for any continuously differentiable function with finite-variance explicit gradient estimators. The variance reduction is largest for the location derivative at small location-to-scale ratios, where the implicit estimator's variance drops by orders of magnitude relative to the explicit, while the scale-derivative variance falls by at most 10% (Figs. 3 and 6). Our empirical variance measurements match our theoretical predictions for both distributions.
We then applied both estimators to French–Wilson scaling, where the FoldedNormal and Rice distributions are the variational families for centric and acentric reflections. The explicit estimator recovers a quadrature reference posterior to 0.67% on the centric amplitude and 0.33% on the acentric amplitude at Monte Carlo samples per gradient. The variance reduction is largest for centric reflections at or below zero intensity, which is in agreement with Theorems 1 and 2. It is weaker on acentric reflections and near zero on the scale derivative of both classes.
We used our French–Wilson model to explore whether the reduced variance offered by the implicit estimator provided any practical advantages, such as a reduced error or faster convergence. For this particular problem, the answer depends on the type of optimization algorithm used during training. Under the adaptive optimizers, the explicit estimator is more accurate than the implicit. However, this difference is reduced as a function of increasing number of Monte Carlo samples used to estimate the gradients. Under stochastic gradient descent, neither of the estimators exhibits an advantage over the other. On an experimental lysozyme dataset, both estimators reproduce the exact posterior amplitude to better than 1%.
Appendices
A Proof of Theorem 1
The key observation in this proof is that the implicit FoldedNormal pathwise derivative is the Rao–Blackwellization of the explicit derivative with respect to the sampled magnitude ; once this identity is established, unbiasedness and the variance ordering follow immediately from standard conditional-expectation identities. Throughout this section, we let , , and we let denote the standard Normal PDF.
Conditional distribution of X given Y. The absolute-value function is two-to-one for Y > 0, which means that the equation has solutions and . By Bayes' rule, with denoting the Normal( ) density,
and similarly .
Conditional expectation of the explicit gradient. Under explicit reparameterization, and . Conditional on , each partial derivative takes on two values,
Applying the Law of the Unconscious Statistician (Grimmett & Stirzaker, 2020) to the expectation of the conditional distribution gives us
and
These match the implicit gradient formulas derived in Section S2 of the supporting information for . Since we required that is continuously differentiable, we know that the derivative exists. Further, is fully determined conditional on , so it factors out of the conditional expectation,
where the final equality uses the conditional expectations of computed above, which shows the identity (17) stated in the main text.
Unbiasedness and variance ordering
Both arguments below require the explicit estimator to have finite second moment, which is satisfied with the assumption . The unbiasedness of follows from the tower property (Grimmett & Stirzaker, 2020) applied to (44),
where the last equality follows from the unbiasedness of the explicit estimator (Section S1 of the supporting information). The variance ordering (18) follows from the law of total variance,
and from the non-negativity of the second term. The first term equals by (44). Equality holds if and only if .
B Variance gap of the FoldedNormal estimators
Applying the law of total variance to conditioned on Y, and using equation 44, expresses the gap between the two variances as an expected conditional variance,
For the test function and parameter , the conditional variance evaluates to
Taking the expectation with respect to the FoldedNormal density (equation 6) yields the per-sample variance gaps
These integrals have no closed form, but they can be evaluated by numerical quadrature. Combining equation 47 with the closed-form explicit variances (equation 13) yields the variance of the implicit estimator for N Monte Carlo samples, equation 20.
C Proof of Theorem 2
The argument mirrors the steps used in the proof of Theorem 1 (Appendix A). We first establish the conditional density of the direction given , then show that the conditional expectation of the explicit derivative recovers the implicit derivative, and finally apply the tower property and the law of total variance. Write and for the unit sample and mean directions, respectively, and parametrize with the polar axis along , so that is the angle between and and .
Conditional distribution of the direction given . The bivariate distribution that defines has density . Restricting the density to a circle of radius , and using , the terms are constant in , so . Normalizing over gives a von Mises density (Bricogne, 1997),
with concentration , where is the modified Bessel function of the first kind (Mardia & Jupp, 2009). This is the Rice analogue of the two-point Bayes step in Appendix A. In that case, the pre-image values, , were weighted by and . Here, the pre-image values lie on the circle of radius , and they are weighted by the von Mises density.
We note that the mean direction and the angle require that . When , the mean vanishes, is isotropic, and is Rayleigh. Further, when we get that , so that , and the von Mises density is uniform .
Conditional expectation of the explicit gradient. The pathwise derivatives of R were obtained in vector form in Section S3 of the supporting information, and are given by
Both terms are affine, and conditioning on fixes the magnitude, leaving as the only random variable. Hence, by linearity of expectation, the only average required for each term is . Applying the Law of the Unconscious Statistician (Grimmett & Stirzaker, 2020) with the von Mises density,
Because the von Mises density is an exponential family with natural parameter and sufficient statistic , this mean equals the derivative of the log-normalizer (Wainwright & Jordan, 2008),
(54) where the final step uses . Substituting the conditional expectation back into the derivatives gives us
These are exactly the implicit derivative terms and obtained from the Marcum-Q CDF in Section S4 of the supporting information, so the conditional-expectation route and the CDF route produce the same term. Because we required f to be continuously differentiable, the derivative exists, and as a function of R alone it factors out of the conditional expectation,
which establishes the identity (32) stated in the main text.
Unbiasedness and variance ordering. Both arguments below require the explicit estimator to have finite second moment, which the requirement provides. The unbiasedness of follows from the tower property (Grimmett & Stirzaker, 2020) applied to (56),
where the last equality uses the unbiasedness of the explicit estimator (Section S3 of the supporting information). The variance ordering (33) follows from the law of total variance,
and the non-negativity of the second term. The first term equals by (56). Equality holds if and only if .
D Variance gap of the Rice estimators
Conditional on , the direction follows the von Mises density (Appendix C), an exponential family with natural parameter and sufficient statistic . The variance of the sufficient statistic is therefore the second derivative of the log-normalizer, (Wainwright & Jordan, 2008). Differentiating once more with the quotient rule gives
Using and in the first term gives
Now, applying the law of total variance to conditioned on R, and using equation 56, expresses the gap between the two variances as an expected conditional variance,
For the test function and the parameter , the conditional variance is given by the terms
where is given by equation 60. Taking the expectation of with respect to the Rice density (equation 21) yields the per-sample variance gaps
and
The remaining integral in the variance terms involves ratios of modified Bessel functions and has no closed form. As in the FoldedNormal case, we can evaluate the integral by numerical quadrature. Combining equation 61 with the closed-form explicit variances and (Section 2.2.2) yields the variance of the implicit estimator for Monte Carlo samples, equation 34.
Acknowledgements
We would like to thank Doris Mai for contributing to and helping maintain our open-source package rs-distributions.
This work depends on open-source software, and we thank the developers and maintainers of PyTorch (Paszke et al., 2019), ArviZ (Kumar et al., 2019), cctbx (Grosse-Kunstleve et al., 2002), reciprocalspaceship (Greisman et al., 2021), gemmi (Wojdyr, 2022), adabelief-pytorch, NumPy (Harris et al., 2020), SciPy (Virtanen et al., 2020), pandas, Polars, Matplotlib and seaborn.
We used Claude Code (Anthropic), running Claude Opus 5, as a coding assistant while writing the analysis and figure-generation scripts, and for editing the text. The code and text were checked for errors, and the authors take full responsibility for the content of this paper.
Funding
This work was supported by National Institutes of Health (NIH) grant DP2-GM141000 (to D.R.H.), National Science Foundation Graduate Research Fellowship grant 2023321426 (to L.A.A.). The Linac Coherent Light Source (LCLS) at the SLAC National Accelerator Laboratory is an Office of Science User Facility operated for the U.S. Department of Energy Office of Science by Stanford University. This work was supported by the U.S. Department of Energy, Office of Science, Basic Energy Sciences under Contract No. DEAC02-76SF00515.
Conflicts of interest: The authors declare there are no conflicts of interest.
Data availability: The implicit and explicit FoldedNormal and Rice distributions are implemented in the open-source PyTorch package rs-distributions, at https://github.com/rs-station/distributions. The code that reproduces every analysis, figure and table in this work, including the French–Wilson variational model from Section S5 of the supporting information, is at https://github.com/Hekstra-Lab/gradient_estimator_paper. That repository also contains the script that generates the synthetic dataset from Section S6 of the supporting information. The experimental data are the deposited structure factors of PDB entry 9B7C, available from the Protein Data Bank at https://www.rcsb.org/structure/9B7C.
References
Aldama, L. A., Dalton, K. M. & Hekstra, D. R. (2023). Acta Crystallographica Section D Structural Biology, 79(9), 796–805.
Blei, D. M., Kucukelbir, A. & McAuliffe, J. D. (2017). Journal of the American Statistical Association, 112(518), 859–877.
Bricogne, G. (1997). In Macromolecular Crystallography Part A, vol. 276 of Methods in Enzymology, pp. 361–423. Academic Press.
https://www.sciencedirect.com/science/article/pii/S0076687997760695
Casella, G. & Robert, C. P. (1996). Biometrika, 83(1), 81–94.
Dalton, K. M., Greisman, J. B. & Hekstra, D. R. (2022). Nature Communications, 13(1), 7764.
Fadini, A., Li, M., McCoy, A. J., Banjara, S., Okumura, H., Napier, E., Fontana, P., Khan, A. R., Jovine, L., Terwilliger, T. C. et al. (2026). Nature methods, pp. 1–11.
Figurnov, M., Mohamed, S. & Mnih, A. (2018). In Advances in Neural Information Processing Systems (NeurIPS), vol. 31, pp. 441–452. https://arxiv.org/abs/1805.08498
French, S. & Wilson, K. (1978). Acta Crystallographica Section A, 34(4), 517–525.
Glasserman, P. (2003). Monte Carlo Methods in Financial Engineering, vol. 53 of Stochastic Modelling and Applied Probability. New York, NY: Springer.
Green, E. A. (1979). Acta Crystallographica Section A: Crystal Physics, Diffraction, Theoretical and General Crystallography, 35(3), 351–359.
Greisman, J. B., Dalton, K. M. & Hekstra, D. R. (2021). Journal of Applied Crystallography, 54(5), 1521–1529.
Grimmett, G. & Stirzaker, D. (2020). Probability and Random Processes. Oxford: Oxford University Press, 4th ed.
Grosse-Kunstleve, R. W., Sauter, N. K., Moriarty, N. W. & Adams, P. D. (2002). Journal of Applied Crystallography, 35(1), 126–136.
Gudbjartsson, H. & Patz, S. (1995). Magnetic Resonance in Medicine, 34(6), 910–914.
Harris, C. R., Millman, K. J., van der Walt, S. J., Gommers, R., Virtanen, P., Cournapeau, D., Wieser, E., Taylor, J., Berg, S., Smith, N. J., Kern, R., Picus, M., Hoyer, S., van Kerkwijk, M. H., Brett, M., Haldane, A., del Río, J. F., Wiebe, M., Peterson, P., Gérard-Marchant, P., Sheppard, K., Reddy, T., Weckesser, W., Abbasi, H., Gohlke, C. & Oliphant, T. E. (2020). Nature, 585(7825), 357–362.
Hekstra, D. R., Wang, H. K., Klureza, M. A., Greisman, J. B. & Dalton, K. M. (2025). Science Advances, 11(49), eadj2921.
https://www.science.org/doi/abs/10.1126/sciadv.adj2921
Jordan, M. I., Ghahramani, Z., Jaakkola, T. S. & Saul, L. K. (1998). In Learning in Graphical Models, edited by M. I. Jordan, pp. 105–161. Dordrecht: Springer Netherlands.
Kim, M., Mai, H., Shenoy, J., Follmer, A., Wetzstein, G. & Poitevin, F. (2026). arXiv preprint arXiv:2605.15564.
https://arxiv.org/abs/2605.15564
Kingma, D. P. & Ba, J. (2015). In International Conference on Learning Representations (ICLR). https://arxiv.org/abs/1412.6980
Kingma, D. P. & Welling, M. (2019). Foundations and Trends in Machine Learning, 12(4), 307–392.
Kumar, R., Carroll, C., Hartikainen, A. & Martin, O. (2019). Journal of Open Source Software, 4(33), 1143.
Lam, K. H., Bui, T. D., Deligiannidis, G. & Teh, Y. W. (2025). In Advances in Neural Information Processing Systems (NeurIPS). https://arxiv.org/abs/2506.07687
Lauwers, L., Barbé, K., Van Moer, W. & Pintelon, R. (2010). Measurement Science and Technology, 21(11), 115804.
Leone, F. C., Nelson, L. S. & Nottingham, R. B. (1961). Technometrics, 3(4), 543–550.
Liao, M.-Y. (2010). International Journal of Production Research, 48(14), 4123–4137.
Liu, X., Tian, G.-L., Fei, Y., Shu, L. & Zhao, Q. (2020). Journal of Computational and Applied Mathematics, 379, 112941.
Marcum, J. (1960). IRE Transactions on Information Theory, 6(2), 59–267.
Mardia, K. V. & Jupp, P. E. (2009). Directional Statistics. John Wiley & Sons.
Mohamed, S., Rosca, M., Figurnov, M. & Mnih, A. (2020). Journal of Machine Learning Research, 21(132), 1–62.
https://jmlr.org/papers/v21/19-346.html
Pannu, N. S. & Read, R. J. (1996). Acta Crystallographica Section A: Foundations of Crystallography, 52(5), 659–668.
Paszke, A., Gross, S., Massa, F., Lerer, A., Bradbury, J., Chanan, G., Killeen, T., Lin, Z., Gimelshein, N., Antiga, L., Desmaison, A., Köpf, A., Yang, E., DeVito, Z., Raison, M., Tejani, A., Chilamkurthy, S., Steiner, B., Fang, L., Bai, J. & Chintala, S. (2019). In Advances in Neural Information Processing Systems (NeurIPS), vol. 32, pp. 8024–8035. https://arxiv.org/abs/1912.01703
Polyak, B. T. (1964). USSR Computational Mathematics and Mathematical Physics, 4(5), 1–17.
Pratt, W. (1968). Proceedings of the IEEE, 56(7), 1220–1221.
Read, R. J. & McCoy, A. J. (2016). Acta Crystallographica Section D Structural Biology, 72(3), 375–387.
Reig, J., Rodrigo Peñarrocha, V. M., Rubio, L., Martínez-Inglés, M. T. & Molina-García-Pardo, J. M. (2019). IEEE Access, 7, 77328–77339.
Rezende, D. J., Mohamed, S. & Wierstra, D. (2014). In Proceedings of the 31st International Conference on Machine Learning (ICML), vol. 32 of Proceedings of Machine Learning Research, pp. 1278–1286. PMLR.
https://proceedings.mlr.press/v32/rezende14.html
Rice, S. O. (1944). The Bell System Technical Journal, 23(3), 282–332.
Robbins, H. & Monro, S. (1951). The Annals of Mathematical Statistics, 22(3), 400–407.
Simon, M. K. & Alouini, M.-S. (2008). IEEE Transactions on Information Theory, 54(7), 3369–3370.
Sutton, R. S. & Barto, A. G. (2018). Reinforcement Learning: An Introduction. Adaptive Computation and Machine Learning. Cambridge, Massachusetts: The MIT Press, 2nd ed.
Tieleman, T. & Hinton, G. (2012). Lecture 6.5—RMSprop: Divide the gradient by a running average of its recent magnitude. Coursera: Neural Networks for Machine Learning.
Virtanen, P., Gommers, R., Oliphant, T. E. et al. (2020). Nature Methods, 17(3), 261–272.
Wainwright, M. J. & Jordan, M. I. (2008). Foundations and Trends in Machine Learning, 1(1-2), 1–305.
Wilson, A. J. C. (1949). Acta Crystallographica, 2(5), 318–321.
Wojdyr, M. (2022). Journal of Open Source Software, 7(73), 4200.
Woolfson, M. M. (1956). Acta Crystallographica, 9(10), 804–810.
https://doi.org/10.1107/S0365110X56002187
Zhuang, J., Tang, T., Ding, Y., Tatikonda, S., Dvornek, N., Papademetris, X. & Duncan, J. S.
(2020). In Advances in Neural Information Processing Systems, vol. 33, pp. 18795–18806.
Supporting information
S1 Derivation of the FoldedNormal explicit gradient estimator
Let so that our loss function is . We are interested in the variance and expectation of the gradient estimator for
For a single Monte Carlo sample, , we have
The first component is given by
The second component is
The third component involves , so we have to differentiate with respect to and . Differentiating with respect to gives
and differentiating with respect to gives us
Hence, we get that
(S7) and
These are the explicit derivative estimators when using a single Monte Carlo sample, for the test function .
Now we find the variance and the expectation of the gradients:
and
Hence, the estimators are unbiased. The variance is given by:
and
(S12)
From equation S10, we know that . For the term , we get
Hence, we get
(S14)
From these derivations we see that the variance of the estimator with respect to depends on , and the variance of the estimator with respect to depends on both and . In practice, we use more than one Monte Carlo sample ( ), so the expectation becomes
(S15)
which is the same as the single-sample case because of the linearity of expectation. If we assume that each Monte Carlo sample is i.i.d., we get the following variance
(S16)
When we differentiate with respect to we get
Differentiating with respect to gives us
S2 Derivation of the FoldedNormal implicit gradient estimator
Starting from equation 5 of the main text, we use the CDF of the FoldedNormal distribution as the standardization function s. The CDF of the FoldedNormal, denoted here by , has the form
where erf is the error function. Differentiating with respect to gives us
We note that the two components on the right-hand side of equation S20 are Normal distribution PDFs evaluated at Y, with means and respectively (both with scale ). Then, differentiating with respect to gives us
Defining the following variables,
and letting denote the PDF of the standard Normal distribution, we can write shorter expressions for equations S20 and S21,
(S23)
and
(S24)
This allows us to write the per-sample implicit gradients as
(S25)
and
(S26)
Averaging these per-sample gradients over Monte Carlo samples yields the estimators and reported in the main text.
S3 Derivation of the Rice explicit gradient estimator
Let , where with , , and . Using the explicit pathwise Monte Carlo estimator shown in equation 4 of the main text, we want to find the per-sample gradient , where . Differentiating with respect to , we get
(S27)
Now we differentiate with respect to , which gives us
(S28)
Lastly, we take the partial derivative with respect to ,
(S29)
Thus, our Monte Carlo estimators take the form
(S30)
Taking the expectation of the estimators gives us,
The variance of the estimators is given by
and,
Projecting the location derivative onto via , and using the independence of the two components, gives
since . At the weights and take the indeterminate form 0/0, but the estimator extends continuously: its mean and its variance do not depend on the mean direction, so fixing any reference direction (for instance ) yields these same values.
Vector form. The component-wise derivation above can be written compactly for a general differentiable test function by differentiating through the norm . The gradient of the norm with respect to the sample is the unit vector
Since gives and , the chain rule yields the pathwise gradients
Projecting the location derivative onto the mean direction , via , gives us the following directional derivative
(S37)
where is the angle between the sample and the mean direction . Then, using the equality , we get that
For the test function , where , these reduce to the component expressions above,
S4 Derivation of the Rice implicit gradient estimator
In this section we construct an implicit pathwise estimator for the Rice distribution and the test function . To do so, we use the CDF of the Rice distribution, denoted by , which is defined as
where is the first-order Marcum Q-function, which is the complementary CDF for the Rice distribution (Marcum, 1960; Simon & Alouini, 2008). We note that the derivatives of are given by
where and are modified Bessel functions of the first kind (Pratt, 1968). To enable composition with a parameter-dependent map (introduced below), we rewrite the standardization function in terms of the abstract arguments of , defining as
Note that coincides with under the substitution , ; the two-argument form is introduced solely to make the chain rule below transparent. The standardization function has the following Jacobian, denoted by ,
which we expand to
To simplify the notation, let
giving us
Now, we define the vector-valued function as
Our function h has the Jacobian,
where denotes the derivative with respect to the i-th argument. Using , we can express our standardization function as a composition,
Using the chain rule, we get that
(S50)
Substituting the components of and writing , we obtain
where
with
Using the implicit reparameterization gradient formulas,
and
The c terms cancel, leaving behind clean expressions for the gradients of the samples.
S5 French-Wilson variational implementation
Our French–Wilson scaling variational inference model is implemented in PyTorch (Algorithm S1). We fit our model using the implicit and explicit reparameterizations, using five different optimization algorithms. For each reparameterization and optimizer pairing, we train the model 10 times independently, each differing by the number of Monte Carlo samples, , used for estimating the ELBO. Every combination is replicated 10 times (for a total of 1000 experiments), trained for 25,000 steps.
We chose the learning rates in a separate sweep, where we tested at every , using 20,000 training steps for each run. For each optimizer and estimator, we kept the rates that were stable (produced finite gradient values) at every , and among those took the one with the best mean ELBO rank across . Table S1 lists the learning rates we kept. The two stochastic gradient descent variants were unstable with higher learning rates, and with a smaller number of Monte Carlo samples. Thus, for the stochastic gradient descent variants we instead chose the learning rate based on stability. Stochastic gradient descent with momentum uses a momentum of 0.9. Adam and AdaBelief use , and AdaBelief uses with rectification and decoupled weight decay disabled. Every remaining setting is the torch.optim default, or the adabelief-pytorch default for AdaBelief.
Table S1: Learning rates used for the different optimizers, one per gradient estimator.
| Optimizer | Explicit | Implicit |
|---|---|---|
| SGD | ||
| SGD + momentum | ||
| RMSprop | ||
| Adam | ||
| AdaBelief |
S6 Datasets and reference calculations
Synthetic dataset. We construct an initial dataset by picking values over a grid of , and , for 1,300 grid points. Each grid point is split into centric and acentric reflections, for a total of 2,600 samples. We then use the French–Wilson scaling algorithm from the cctbx package (Grosse-Kunstleve et al., 2002) on the synthetic data. This step rejected 360 of the samples. We use the remaining 2,240 samples as our synthetic dataset.
Experimental dataset. We use the deposited structure factors of PDB entry 9B7C, a hen egg-white lysozyme dataset in space group with unit cell parameters and . The 9B7C-sf.cif file contains 45,196 unique reflections spanning a resolution between 56.1 and . We use reciprocalspacehip to read the .cif file, and to merge the Friedel
Algorithm S1 French–Wilson scaling by variational inference
Require: observed intensity , uncertainty , expected intensity , centric flag c, positivity floor
Require: step count S, Monte Carlo samples per gradient N, learning rate , optimizer OPTIM
Require: the explicit or the implicit reparameterization
1:
2:
3: for to S do
4: if c then
5:
6:
7: else
8:
9:
10: end if
11: draw along the explicit or implicit sampling path
12:
13: if is finite then
14:
15: end if
16: end for
17:
18: mates. The data is then binned into 50 resolution shells containing equal numbers of reflections, and we use the mean intensity in each shell as the Wilson prior parameter .
Reference posteriors. We compute the reference posterior by quadrature, for both the synthetic dataset and the experimental dataset. For each reflection we evaluate the amplitude posterior from equation 35 of the main text on a 20,001-point grid and integrate by composite Simpson's rule. We also report the cctbx implementation (Grosse-Kunstleve et al., 2002) of the original French–Wilson correction (French & Wilson, 1978).
S7 Variance of the scale-derivative estimators
The variances of the explicit and implicit scale-derivative estimators across the and parameter grids are shown in Figs. S1 and S2.
Variance of the Scale Derivative Estimator for FoldedNormal Distributions

Figure S1: Theoretical (top) and empirical (bottom) variance of the explicit ( ) and implicit ( ) FoldedNormal derivative estimators of as a function of and . The colorbar denotes the variance value for each pair. The empirical variance was computed across 10,000 simulations using 100 Monte Carlo samples each. The theoretical variance was calculated using equations 13 and 20 of the main text, for the explicit and implicit estimators, respectively.
S8 Reference recovery under every optimization algorithm
We use the mean absolute percentage error and a correlation coefficient to score the approximate posteriors against the quadrature reference from Section S6. The scores are reported for each
Variance of the Scale Derivative Estimator for Rician Distributions

Figure S2: Theoretical (top) and empirical (bottom) variance of the explicit ( ) and implicit ( ) Rice derivative estimators of as a function of and . The colorbar denotes the variance value for each pair. The empirical variance was computed across 10,000 simulations using 100 Monte Carlo samples each. The theoretical variance was calculated using equations 26 and 34 of the main text, for the explicit and implicit estimators, respectively.
optimization algorithm and reparameterization, and the scores are split by centric and acentric reflections. Figure S3 plots all four errors against the number of Monte Carlo samples, and Table S2 gives them at N = 512.
S9 Gradient variance at the initialization and at convergence
Figure S4 shows the variance ratio at the start and end of training for the Adam optimizer; and Figure S5 shows the ratio for all five optimizers we tested. At initialization, all of the training runs are initialized at the same parameters, so the initial ratio is the same. At convergence, each run converges to different parameters. Thus, to measure the ratio at the end of training, we record the parameters that the implicit estimator converged to, and we use those parameters to estimate the
Recovery of the reference posterior for every optimization algorithm

Monte Carlo samples
Figure S3: Recovery of the reference posterior as a function of the number of Monte Carlo samples N used per gradient, for each of the five optimization algorithms tested. The first and second row show the amplitude F for centric and acentric reflections, respectively. The third and fourth rows show the posterior width for centric and for acentric reflections, respectively. The two amplitude rows share a vertical scale, and so do the two posterior-width rows. Lines are medians over ten replicates and bands span the interquartile range.
gradient of both the explicit and implicit reparameterizations.
S10 Convergence under every optimization algorithm
Figure S6 shows the centric amplitude error and the objective over training, for each of the five optimization algorithms.
Table S2: Recovery of the reference posterior at , for every optimization algorithm and both estimators. Errors are mean absolute percentage errors and correlations are Pearson coefficients against the reference amplitude. Each value is the median over ten replicates.
| Algorithm | Estimator | error (%) | error (%) | for | |||
|---|---|---|---|---|---|---|---|
| centric | acentric | centric | acentric | centric | acentric | ||
| SGD | Explicit | 3.91 | 2.33 | 2.64 | 2.83 | 0.99417 | 0.99539 |
| Implicit | 3.91 | 2.33 | 2.64 | 2.83 | 0.99417 | 0.99539 | |
| SGD + mom. | Explicit | 2.10 | 0.91 | 2.85 | 2.60 | 0.99896 | 0.99924 |
| Implicit | 2.10 | 0.91 | 2.85 | 2.60 | 0.99896 | 0.99924 | |
| RMSprop | Explicit | 0.69 | 0.33 | 2.42 | 1.67 | 0.99975 | 0.99992 |
| Implicit | 0.76 | 0.33 | 2.45 | 1.68 | 0.99972 | 0.99992 | |
| Adam | Explicit | 0.67 | 0.33 | 2.41 | 1.67 | 0.99975 | 0.99992 |
| Implicit | 0.93 | 0.53 | 2.57 | 1.81 | 0.99962 | 0.99979 | |
| AdaBelief | Explicit | 0.69 | 0.34 | 2.41 | 1.68 | 0.99974 | 0.99992 |
| Implicit | 0.95 | 0.55 | 2.58 | 1.82 | 0.99960 | 0.99978 | |

Figure S4: Ratio of implicit to explicit gradient variance, plotted against the observed signal-to-noise (SNR) of the reflection. The ratio is measured at the initialization and at the converged parameters of an Adam fit after 25,000 steps at . The top row shows the variance ratio for the location-derivative, and the bottom row shows the variance ratio for the scale-derivative. The ratio is shown separately for the centric reflections (left column) and the acentric reflections (right column). Each point is a median over reflections and ten replicates, and the bands span the interquartile range within each bin. The axis is divided into 18 equal-width bins between -3 and 9.

Figure S5: Ratio of implicit to explicit gradient variance at the initialization parameters, and at each algorithm's own converged parameters after 25,000 steps at N = 512. The top row is the centric location derivative and the bottom row is the centric scale derivative. The initialization parameters are the same in all cases, so the curve is identical across each row. Points are medians over reflections and ten replicates and bands span the interquartile range within each bin. The SNR axis is divided into 18 equal-width bins between -3 and 9. The three lowest bins hold nine reflections each, and the fullest hold about three hundred.
Agreement and objective against training step (centric reflections, N = 512)

Figure S6: Centric amplitude error and objective against training step, one column per optimization algorithm, at N = 512 Monte Carlo samples per gradient. Top, mean absolute percentage error against the reference posterior; bottom, the negative ELBO. Lines are medians over ten replicates and bands span the interquartile range. Every algorithm drives the objective to within 0.5% of the same value, so the fits agree closely on the optimum they approach. Stochastic gradient descent's objective is still descending at the end of training, so it has not converged.