rgpycrumbs.surfaces._hyperparameters

Shared numerical policy for surface hyperparameter fits.

Each value below is derived from the data, the floating-point format, or a cited estimator:

  • Length scales start at the median Euclidean distance between distinct inputs. Garreau, Jitkrittum and Kanagawa analyse this median heuristic, and note that some authors use the median distance itself rather than that distance over sqrt(2), https://doi.org/10.48550/arXiv.1707.07269. Repeated inputs are left out, so they do not pull the start toward zero. The IMQ kernel 1 / sqrt(r**2 + epsilon**2) depends on r only through r / epsilon up to its amplitude, so epsilon takes the same start. Riabiz et al. set the IMQ length scale to the median distance in the same way, https://doi.org/10.1111/rssb.12503.

  • IMQ_EPSILON_PRIOR_SHAPE is the shape of the gamma prior on the IMQ epsilon. Chung et al. propose shape 2 for a standard deviation because the density is zero at zero with a positive slope, so the estimate stays off zero. The mode of that prior is 1 / rate, which they suggest setting to a prior estimate, https://doi.org/10.1007/s11336-013-9328-2. The rate here puts the mode at the starting epsilon.

  • RQ_INITIAL_ALPHA starts the rational-quadratic mixture at shape 1. The RQ kernel is a gamma scale mixture of squared-exponential kernels over inverse squared length scales (Rasmussen and Williams, eq. 4.20). Shape 1 makes that mixture exponential, the maximum-entropy distribution on the positive reals for a fixed mean (Cover and Thomas, chapter 12, https://doi.org/10.1002/047174882X).

  • minimize_log_parameters runs SciPy’s L-BFGS-B with its documented default tolerances and returns the last iterate its line search accepted. The BFGS loop in JAX 0.9.2 moves to the trial point even when the line search fails, and jax.scipy.optimize.minimize ignores tol, https://github.com/jax-ml/jax/blob/jax-v0.9.2/jax/_src/scipy/optimize/bfgs.py.

  • covariance_roundoff_factor implements Higham’s gamma_n = n u / (1 - n u) with unit roundoff u = eps(dtype) / 2. A computed Cholesky factor R of an order-n matrix A satisfies R.T R = A + dA with |dA| <= gamma_(n+1) |R.T| |R| (Theorem 10.3), and every entry of |R.T| |R| is at most the largest diagonal entry of A. covariance_roundoff_jitter adds that entrywise bound to the diagonal, so a 300-point gradient fit in two dimensions (order 900, float32) gets gamma_901 = 5.37e-5 times the largest entry. safe_cholesky_solve reports a factorization that still fails as a NaN log-determinant instead of a wrong finite value. See Higham, Accuracy and Stability of Numerical Algorithms, 2nd ed., chapters 3 and 10, https://doi.org/10.1137/1.9780898718027.

  • observation_noise keeps the caller’s smoothing as the noise variance. Fits without a caller smoothing, or with zero, treat the observations as exact. Fixed fits and the IMQ noise caps then set the noise to the roundoff jitter. starting_noise starts optimized exact-data fits at covariance_scale, a signal-to-noise ratio of one. The largest eigenvalue of a positive semidefinite K is at most n times its largest entry, so K + covariance_scale(K) I starts the optimizer with a condition number of at most n + 1.

  • NYSTROM_RANDOM_SEED only makes the random inducing subset reproducible. No fit is tuned to its value, and callers can pass their own seed.

  • LENGTH_SCALE_FLOOR, SQUARED_DISTANCE_GUARD and RQ_DENOMINATOR_GUARD come from the float32 machine epsilon eps = 2**-23, the spacing of float32 numbers at one. Inputs of order one resolve no length shorter than eps, so the squared-exponential kernel clamps its length scale there. Its gradient-block likelihood and gradient stay finite below that. The thin-plate and Matern kernels take r = sqrt(d2 + eps**2), which is eps at coincident points. Without the guard the square root has no derivative there, and the thin-plate r**2 log(r) is NaN. In float32, d2 + eps**2 == d2 for every d2 >= 2**-21. The 1e-12 used before is a no-op in float32 for every d2 >= 2**-15. The rational-quadratic kernel adds eps**2, the squared length-scale floor, to 2 alpha l**2. The ratio then stays defined at coincident points when that product underflows. The 1e-6 used before changed that kernel by half a percent at l = 0.01 and by half at l = 1e-3. eps**2 changes it there by less than 1e-8.

Attributes

Functions

median_pairwise_distance(→ jax.numpy.ndarray)

Return the median Euclidean distance between distinct input points.

minimize_log_parameters(→ jax.numpy.ndarray)

Minimize a float32 JAX objective of log-parameters with L-BFGS-B.

covariance_roundoff_factor(→ jax.numpy.ndarray)

Return Higham's gamma_(n+1) Cholesky factor for a matrix of order n.

covariance_scale(→ jax.numpy.ndarray)

Return the largest absolute entry, or one for a zero matrix.

covariance_roundoff_jitter(→ jax.numpy.ndarray)

Return the Cholesky backward-error bound for matrix as a diagonal shift.

observation_noise(→ float)

Return the caller's smoothing, or the roundoff jitter for exact data.

starting_noise(→ float)

Return the caller's smoothing, or the covariance scale as a noise start.

Module Contents

rgpycrumbs.surfaces._hyperparameters.IMQ_EPSILON_PRIOR_SHAPE: Final = 2.0[source]
rgpycrumbs.surfaces._hyperparameters.RQ_INITIAL_ALPHA: Final = 1.0[source]
rgpycrumbs.surfaces._hyperparameters.NYSTROM_RANDOM_SEED: Final = 42[source]
rgpycrumbs.surfaces._hyperparameters.LENGTH_SCALE_FLOOR: Final[source]
rgpycrumbs.surfaces._hyperparameters.SQUARED_DISTANCE_GUARD: Final[source]
rgpycrumbs.surfaces._hyperparameters.RQ_DENOMINATOR_GUARD: Final[source]
rgpycrumbs.surfaces._hyperparameters.median_pairwise_distance(x: jax.numpy.ndarray) → jax.numpy.ndarray[source]

Return the median Euclidean distance between distinct input points.

rgpycrumbs.surfaces._hyperparameters.minimize_log_parameters(loss_fn, x0) → jax.numpy.ndarray[source]

Minimize a float32 JAX objective of log-parameters with L-BFGS-B.

rgpycrumbs.surfaces._hyperparameters.covariance_roundoff_factor(matrix_order: int, dtype: jax.numpy.dtype) → jax.numpy.ndarray[source]

Return Higham’s gamma_(n+1) Cholesky factor for a matrix of order n.

rgpycrumbs.surfaces._hyperparameters.covariance_scale(matrix: jax.numpy.ndarray) → jax.numpy.ndarray[source]

Return the largest absolute entry, or one for a zero matrix.

rgpycrumbs.surfaces._hyperparameters.covariance_roundoff_jitter(matrix: jax.numpy.ndarray) → jax.numpy.ndarray[source]

Return the Cholesky backward-error bound for matrix as a diagonal shift.

rgpycrumbs.surfaces._hyperparameters.observation_noise(smoothing, matrix: jax.numpy.ndarray) → float[source]

Return the caller’s smoothing, or the roundoff jitter for exact data.

rgpycrumbs.surfaces._hyperparameters.starting_noise(smoothing, matrix: jax.numpy.ndarray) → float[source]

Return the caller’s smoothing, or the covariance scale as a noise start.