Repository navigation
Add nested Leja quadrature and a dimension-adaptive sparse grid - #1589
NAThompson wants to merge 1 commit into
Conversation
|
@JacobHass8 : Check it out at your convenience. |
950bfb6 to
b071d87
Compare
| // The weights solve sum_i w_i p_k(x_i) = sqrt(mu0) delta_k0, k < n. Scaling column i by sqrt(w(x_i)) makes the | ||
| // matrix Q_ki = sqrt(w(x_i)) p_k(x_i) well conditioned where the Vandermonde matrix p_k(x_i) is not. Each n is | ||
| // solved by LU with partial pivoting over the degrees k, in O(N^4) for all n; reusing one factorization of Q^T in | ||
| // Leja order would take O(N^3), but for Legendre its weights are up to 5 times less accurate. | ||
| void compute_weights(unsigned N) |
There was a problem hiding this comment.
I wonder if there is a way to generalize this for any weight function if you don't know the recurrence relation. I think there is a way if you know the moments of the weight function but I'm not exactly sure.
There was a problem hiding this comment.
Yes. The two halves of the construction need different things. The points only use √w through log √w and its derivatives (the greedy argmax), so any weight we can evaluate works as is. The orthonormal recurrence (beta(k), mu0) is only used for the weights, to keep the moment system well conditioned.
Recovering the recurrence from raw moments ∫xᵏw is badly conditioned: the Hankel matrix's condition number grows exponentially. The stable routes are Gautschi's:
- the modified Chebyshev algorithm, from modified moments ∫pₖ(x)w(x)dx against a known basis such as Legendre or Chebyshev, which is stable on a bounded interval;
- discretized Stieltjes or Lanczos, which only needs w, discretized by a fine Gauss or tanh-sinh rule.
Either would give a general leja<Real>(w, support). I kept this PR to the two closed-form weights, but a Jacobi weight (also closed form) or a general weight via discretized Stieltjes would be a natural follow-up.
-claude
b071d87 to
291a854
Compare
Leja rules reuse earlier evaluations; the sparse grid refines where contributions are largest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
291a854 to
d7bdf04
Compare
Leja rules reuse earlier evaluations; the sparse grid refines where contributions are largest.
leja_legendreandleja_hermiteare nested weighted Leja rules (one new point per rule, weights from a √w-scaled moment system), with an adaptiveintegrate.sparse_grid(f, rule, dimension, max_calls, tolerance)builds a dimension-adaptive sparse grid (Gerstner–Griebel) from them, over [−1, 1]^d or against exp(−|x|²) on ℝ^d. Both are in the nanobind layer.One dimension
Error vs function calls: Leja (nested, one new call per rule), its free estimate, one-shot Gauss, and Gauss re-run at each doubling.
Where Leja loses, Hermite with a pole at ±i:
Sparse grid
Genz integrands, relative error vs calls, against Tasmanian 8.2 (Leja rules, surplus and anisotropic refinement), Monte Carlo and randomized Sobol' QMC (medians of 32):
Where QMC wins, a peaked integrand in eight dimensions:
max_calls(tolerance 1e-14) so every point is a budget-limited result; the honesty numbers below come from a tolerance sweep.Evidence (H5Web, VS Code extension): leja_correctness.h5.zip (exactness for every n, weights vs 100 digits, greedy choices, Lebesgue constants), sparse_grid_evidence.h5.zip (all convergence plots, honesty of the estimate, chosen index sets).
Benchmark (
reporting/performance/leja_quadrature_performance.cpp, Apple M-series, -O3, CPU time)🤖 Generated with Claude Code