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 kernel1 / sqrt(r**2 + epsilon**2)depends onronly throughr / epsilonup to its amplitude, soepsilontakes 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_SHAPEis the shape of the gamma prior on the IMQepsilon. 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 is1 / 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 startingepsilon.RQ_INITIAL_ALPHAstarts 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_parametersruns 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, andjax.scipy.optimize.minimizeignorestol, https://github.com/jax-ml/jax/blob/jax-v0.9.2/jax/_src/scipy/optimize/bfgs.py.covariance_roundoff_factorimplements Higham’sgamma_n = n u / (1 - n u)with unit roundoffu = eps(dtype) / 2. A computed Cholesky factorRof an order-nmatrixAsatisfiesR.T R = A + dAwith|dA| <= gamma_(n+1) |R.T| |R|(Theorem 10.3), and every entry of|R.T| |R|is at most the largest diagonal entry ofA.covariance_roundoff_jitteradds that entrywise bound to the diagonal, so a 300-point gradient fit in two dimensions (order 900, float32) getsgamma_901 = 5.37e-5times the largest entry.safe_cholesky_solvereports 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_noisekeeps the caller’ssmoothingas the noise variance. Fits without a callersmoothing, or with zero, treat the observations as exact. Fixed fits and the IMQ noise caps then set the noise to the roundoff jitter.starting_noisestarts optimized exact-data fits atcovariance_scale, a signal-to-noise ratio of one. The largest eigenvalue of a positive semidefiniteKis at mostntimes its largest entry, soK + covariance_scale(K) Istarts the optimizer with a condition number of at mostn + 1.NYSTROM_RANDOM_SEEDonly makes the random inducing subset reproducible. No fit is tuned to its value, and callers can pass their ownseed.LENGTH_SCALE_FLOOR,SQUARED_DISTANCE_GUARDandRQ_DENOMINATOR_GUARDcome from the float32 machine epsiloneps = 2**-23, the spacing of float32 numbers at one. Inputs of order one resolve no length shorter thaneps, 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 taker = sqrt(d2 + eps**2), which isepsat coincident points. Without the guard the square root has no derivative there, and the thin-plater**2 log(r)is NaN. In float32,d2 + eps**2 == d2for everyd2 >= 2**-21. The1e-12used before is a no-op in float32 for everyd2 >= 2**-15. The rational-quadratic kernel addseps**2, the squared length-scale floor, to2 alpha l**2. The ratio then stays defined at coincident points when that product underflows. The1e-6used before changed that kernel by half a percent atl = 0.01and by half atl = 1e-3.eps**2changes it there by less than1e-8.
Attributes¶
Functions¶
|
Return the median Euclidean distance between distinct input points. |
|
Minimize a float32 JAX objective of log-parameters with L-BFGS-B. |
|
Return Higham's |
|
Return the largest absolute entry, or one for a zero matrix. |
|
Return the Cholesky backward-error bound for |
|
Return the caller's smoothing, or the roundoff jitter for exact data. |
|
Return the caller's smoothing, or the covariance scale as a noise start. |
Module Contents¶
- 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 ordern.
- 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
matrixas a diagonal shift.