A variety of logarithmic integrators, method for empty cache, analytic jacobians for UV and IR parameter - #3
Open
Jpwessely wants to merge 5 commits into
Open
A variety of logarithmic integrators, method for empty cache, analytic jacobians for UV and IR parameter #3Jpwessely wants to merge 5 commits into
Jpwessely wants to merge 5 commits into
Conversation
…y.py regarding the cache, added analytic parrameter gradients for kernels with asymptotics
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds analytic hyperparameter gradients for the asymptotic kernel and introduces logarithmic / semi-infinite quadrature integrators to better handle wide dynamic ranges and UV-tail behavior.
Changes:
- Add
_empty_cache()andparams_gradient()to the asymptotic kernel wrapper. - Introduce
Riemann_1D_log,GaussLegendre_1D_log,GaussLegendre_1D_log_UVtail, andGaussLegendre_1D_semiinfintegrators.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| fredipy/kernels.py | Adds cache invalidation and analytic gradients for AsymptoticKernel hyperparameters. |
| fredipy/integrators.py | Adds new log-grid and semi-infinite Gauss-Legendre-based integration strategies (incl. UV tail correction). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+281
to
+285
| def _empty_cache(self) -> None: | ||
| """Clear this kernel's cache and propagate to the inner kernel.""" | ||
| self._K_asymp = None | ||
| self._x, self._y = np.array([None]), np.array([None]) | ||
| self.kernel._empty_cache() |
Comment on lines
+420
to
+423
| tau_x = softtheta(x1, self.mu_ir, self.l_ir, -self.ir) # σ_+(x;ir) | ||
| tau_y = softtheta(y1, self.mu_ir, self.l_ir, -self.ir) | ||
| sig_x = softtheta(x1, self.mu_uv, self.l_uv, -self.uv) # σ_-(x;uv) | ||
| sig_y = softtheta(y1, self.mu_uv, self.l_uv, -self.uv) |
| grads.append(_wrap) | ||
|
|
||
| # ---- UV asymptotic parameter gradients: mu_uv, l_uv ---------------- | ||
| if self.uv: |
Comment on lines
+299
to
+308
| def singleIntegration( | ||
| self, | ||
| constraint: LinearEquality, | ||
| kernel: Callable, | ||
| w_pred: np.ndarray | ||
| ) -> np.ndarray: | ||
| return ( | ||
| self.weights * constraint(make_row_vector(self.w), x=make_column_vector(constraint.x)) | ||
| @ kernel(self.w, w_pred) | ||
| ) |
Comment on lines
+376
to
+379
| # correction_{mn} = T (A_m + A_n) + T² | ||
| ones_col = np.ones((A.shape[0], 1)) | ||
| correction = self.T_uv * (A @ ones_col.T + ones_col @ A.T) + self.T_uv ** 2 | ||
| return bulk + correction |
np.sqrt(np.diag(C)) can receive a spuriously negative diagonal entry from floating-point cancellation in the posterior covariance (e.g. at constrained data points or deep in the UV/IR asymptotic tails where variance -> 0), returning nan instead of ~0. Clip to [0, inf) before the sqrt. See fredipy_diff_doc.md #6 in the reconstructions repo for full rationale.
The sign<0 branch computed exp(-(x-mu0)/l0)/(exp(-(x-mu0)/l0)+1) directly. For x far below mu0 relative to l0 (e.g. deep-IR kernel evaluations with a narrow l_ir), exp(...) overflows to inf in both numerator and denominator, giving inf/inf = nan even though the correct limit is exactly 1.0. Rewritten as the algebraic complement of the overflow-safe sign>0 branch instead. Adds a regression test. See fredipy_diff_doc.md #7 in the reconstructions repo for full rationale.
GaussLegendre_1D_log_UVtail overrode singleIntegration and doubleIntegrationSymmetric
but not doubleIntegration, so the cross-covariance block between the sum-rule constraint
and any other integral constraint silently dropped the analytic tail correction that both
the diagonal block and the prediction operator carried. The GP covariance matrix was
therefore inconsistent with the operator predicted through, making predict() and
predict_data() describe different models (44% relative error on the reintegration
identity: reintegrating the posterior mean over the integrator's own nodes must reproduce
predict_data(), and did not).
Derivation: for w' > w_uv >> mu_uv the kernel is rank-1 in the tail, so splitting both
integrals at w_uv gives
Sigma_12 = BB + A_1 T_2^T + T_1 A_2^T + T_1 T_2^T
with A the bulk-UV overlap and T the tail moment, both per-constraint. The existing
symmetric formula bulk + 2AT + T^2 is the C_1 = C_2 special case, so the override is
deleted rather than kept in parallel. T is a per-constraint, per-row vector -- the
sum-rule and KL kernels have different UV falloffs, so no single scalar serves both sides.
The correction lives in GaussLegendre_1D_log driven by per-constraint uv_tail_moment() /
uv_anchor() hooks, so blocks (i,j) and (j,i) are the same expression with roles swapped
and symmetry is structural. This matters because models.py's np.linalg.cholesky reads
only the lower triangle and would silently accept an asymmetric matrix. A node guard
raises NotImplementedError for genuinely different grids, and an all-zero-T fast path
keeps every non-UVtail model bit-identical.
Also fixed here:
- T's exponent 13/22 was hardcoded and gluon-specific, but T is the sum-rule-weighted
tail and depends on the observable's anomalous dimension; the ghost project (9/44) was
off by a factor 10.4. tail_moment is now a required constructor argument -- deliberately
no default, since the silent default is what caused this.
- singleIntegration's tail was a broadcast where the general form is an outer product
(latent: the sum-rule constraint has a single row).
- The analytic NLL gradient added T1 @ T2.T unchanged, but that term is
hyperparameter-independent so its derivative is zero. Pre-existing (the deleted
symmetric override did the same to the sr-sr block); corrected via an explicit
gradient mode.
Verified: reintegration identity 4.02e-16 on a well-conditioned model (4.4e-2
uncorrected, so the test is not vacuous); covariance asymmetry 6.66e-16 against matrix
scale 6.2; analytic gradient agrees with finite differences to 5.2e-07 for all six
hyperparameters. New regression suite in tests/test_integrators_uvtail.py; 83 passed.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fredipy_diff_doc.md
For the Integrator that includes the UV tail: it works only for the gluon, I left it in for you to see it but in the current form its to specific.