|
Deterministic Gaussian Sampling
|
quadrature-free closed forms for the LCD / modified Cramer-von-Mises distance of an even-dimensional standard normal target More...
#include <gsl/gsl_errno.h>#include <gsl/gsl_sf_expint.h>#include <cassert>#include <cmath>#include <cstddef>Go to the source code of this file.
Data Structures | |
| struct | LcdDeltaBIntegrandParams |
| parameters of the raw b-integrand used by the small-c fallback More... | |
Functions | |
| double | lcd_ei (double x) |
| exponential integral Ei(x) for negative arguments | |
| double | lcd_a_n (size_t N, double b) |
| D1, the sample-independent term of the mCvM distance. | |
| double | lcd_c_repulsion (double b, double c) |
| C(b, c), the per-pair repulsion term of D3. | |
| double | lcd_delta_b_integrand (double b, void *params) |
| b^(2k+1) * (1 + 2b^2)^(-q) * exp(-c / (2 (1 + 2b^2))) | |
| double | lcd_delta_b0 (size_t d, double u, double eULeading, double eU, double e0, double dEi, double c) |
| dB_{0,d}(c) = B_{0,d}(bMax, c) - B_{0,d}(0, c) | |
| double | lcd_delta_bkk (size_t k, double bMax, double c) |
| dBkk(k, c) = B_{k,k}(bMax, c) - B_{k,k}(0, c), the D2 term | |
| double | lcd_delta_bkk1 (size_t k, double bMax, double c) |
| dBkk1(k, c) = B_{k,k+1}(bMax, c) - B_{k,k+1}(0, c), the D2 gradient | |
| double | lcd_delta_bkk_closed (size_t k, double bMax, double c, size_t shift, bool reduced=false) |
| closed form of dBkk / dBkk1 | |
| double | lcd_delta_bkk_zero (size_t k, double bMax) |
| dBkk(k, 0) = integral{0 to bMax} b^(2k+1) / (1 + 2b^2)^k db | |
| double | lcd_delta_bkk_zero_minus_leading (size_t k, double bMax) |
| lcd_delta_bkk_zero(k, bMax) - pow(2, -k) * U / 4 | |
| double | lcd_delta_bkk_reduced (size_t k, double bMax, double c) |
| dBkk(k, c) - dBkk(k, 0), the cancellation-free attraction term | |
| double | lcd_delta_bkk_impl (size_t k, double bMax, double c, size_t shift) |
| shared body of lcd_delta_bkk / lcd_delta_bkk1 | |
| double | lcd_reported_offset (size_t N, double bMax, double weightSum) |
| the constant that turns the reduced objective back into the true distance | |
quadrature-free closed forms for the LCD / modified Cramer-von-Mises distance of an even-dimensional standard normal target
The mCvM distance of a Dirac mixture with samples s_i and weights w_i against N(0, I) decomposes into
D = D1 - 2 * D2 + D3
where D1 is sample-independent, D2 is the attraction term (samples towards the mean) and D3 is the repulsion term (samples away from each other).
D1, the sample-independent term of the mCvM distance.
Evaluates A_N(b) = integral_0^b x^(N+1) / (1 + x^2)^(N/2) dx via the recursion
A_1(b) = 0.5 * (b * sqrt(1 + b^2) - asinh(b))
A_2(b) = 0.5 * (b^2 - log(1 + b^2))
A_n(b) = (n * A_{n-2}(b) - b^n / (1 + b^2)^((n-2)/2)) / (n - 2)
applied iteratively. Valid for all N, odd and even.
| N | dimension, must be >= 1 |
| b | upper integration bound, must be >= 0 |
C(b, c), the per-pair repulsion term of D3.
C(b, c) = integral_0^b x * exp(-c / (4 x^2)) dx
= (b^2 / 2) * exp(-c / (4 b^2)) + (c / 8) * Ei(-c / (4 b^2))
| b | upper integration bound, must be > 0 |
| c | squared distance between the two samples, must be >= 0 |
|
inline |
dB_{0,d}(c) = B_{0,d}(bMax, c) - B_{0,d}(0, c)
| d | index of the base case |
| u | 1 + 2 * bMax^2 |
| eULeading | exp(-c / (2u)), or expm1(-c / (2u)) for the reduced form |
| eU | exp(-c / (2u)) |
| e0 | exp(-c / 2) |
| dEi | Ei(-c / (2u)) - Ei(-c / 2) |
| c | squared norm of the sample, must be > 0 |
b^(2k+1) * (1 + 2b^2)^(-q) * exp(-c / (2 (1 + 2b^2)))
With reduced set, exp is replaced by expm1, so the integral evaluates dBkk(c) - dBkk(0) directly and never forms the O(bMax^2) intermediate - the same trick gm_to_dirac_short::calculateP2 uses.
| b | integration variable |
| params | LcdDeltaBIntegrandParams |
dBkk(k, c) = B_{k,k}(bMax, c) - B_{k,k}(0, c), the D2 term
D2 = pow(2, k) * sum_i w_i * lcd_delta_bkk(k, bMax, c_i), with c_i = ||s_i||^2.
| k | half the dimension, N = 2k; must be >= 1 |
| bMax | upper integration bound, must be > 0 |
| c | squared norm of the sample, must be >= 0 |
dBkk1(k, c) = B_{k,k+1}(bMax, c) - B_{k,k+1}(0, c), the D2 gradient
| k | half the dimension, N = 2k; must be >= 1 |
| bMax | upper integration bound, must be > 0 |
| c | squared norm of the sample, must be >= 0 |
|
inline |
closed form of dBkk / dBkk1
| k | half the dimension, N = 2k |
| bMax | upper integration bound |
| c | squared norm of the sample, must be > 0 |
| shift | 0 for dBkk (uses dB_{0,j}), 1 for dBkk1 (uses dB_{0,j+1}) |
shared body of lcd_delta_bkk / lcd_delta_bkk1
| k | half the dimension, N = 2k |
| bMax | upper integration bound |
| c | squared norm of the sample |
| shift | 0 for dBkk (uses dB_{0,j}), 1 for dBkk1 (uses dB_{0,j+1}) |
dBkk(k, c) - dBkk(k, 0), the cancellation-free attraction term
Equal to integral{0 to bMax} b^(2k+1)/(1+2b^2)^k * expm1(-c/(2(1+2b^2))) db.
The constant removed per sample is lcd_delta_bkk_zero(k, bMax); D2 as a whole loses pow(2, k) * (sum_i w_i) * lcd_delta_bkk_zero(k, bMax).
| k | half the dimension, N = 2k; must be >= 1 |
| bMax | upper integration bound, must be > 0 |
| c | squared norm of the sample, must be >= 0 |
dBkk(k, 0) = integral{0 to bMax} b^(2k+1) / (1 + 2b^2)^k db
The c = 0 value of the attraction term, in elementary closed form. With u = 1 + 2b^2 the substitution gives
Z = 2^-(k+2) * integral{1 to U} (1 - 1/u)^k du
= 2^-(k+2) * [ (U-1) - k*ln(U)
This is the constant lcd_delta_bkk_reduced() removes. It is O(bMax^2) by construction, so it belongs in the reported offset, never inside the optimizer's objective.
| k | half the dimension, N = 2k; must be >= 1 |
| bMax | upper integration bound, must be > 0 |
lcd_delta_bkk_zero(k, bMax) - pow(2, -k) * U / 4
The same expression with (U - 1) replaced by -1, i.e. with the O(bMax^2) leading term removed. The result is O(ln U), so subtracting it from the expm1 form of the closed dBkk introduces no cancellation.
| k | half the dimension, N = 2k; must be >= 1 |
| bMax | upper integration bound, must be > 0 |
exponential integral Ei(x) for negative arguments
| x | argument, must be strictly negative |
the constant that turns the reduced objective back into the true distance
The optimizer minimises a reduced objective in which every O(bMax^2) piece has been removed analytically:
f_reduced = -2 * pow(2,k) * sum_i w_i * lcd_delta_bkk_reduced(k, bMax, c_i)
and the true distance is D = f_reduced + K, with
K = A_N(bMax)
collecting the D1 term, the per-sample attraction constant and the per-pair repulsion constant respectively.
| N | dimension, must be even and >= 2 |
| bMax | upper integration bound, must be > 0 |
| weightSum | sum of the Dirac weights, normally 1 |