Skip to content

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
JonasTurnwald:mainfrom
Jpwessely:main
Open

A variety of logarithmic integrators, method for empty cache, analytic jacobians for UV and IR parameter #3
Jpwessely wants to merge 5 commits into
JonasTurnwald:mainfrom
Jpwessely:main

Conversation

@Jpwessely

Copy link
Copy Markdown

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.

Jpwessely and others added 2 commits May 26, 2026 16:49
…y.py regarding the cache, added analytic parrameter gradients for kernels with asymptotics
Copilot AI review requested due to automatic review settings June 2, 2026 16:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() and params_gradient() to the asymptotic kernel wrapper.
  • Introduce Riemann_1D_log, GaussLegendre_1D_log, GaussLegendre_1D_log_UVtail, and GaussLegendre_1D_semiinf integrators.

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 thread fredipy/kernels.py
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 thread fredipy/kernels.py
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)
Comment thread fredipy/kernels.py
grads.append(_wrap)

# ---- UV asymptotic parameter gradients: mu_uv, l_uv ----------------
if self.uv:
Comment thread fredipy/integrators.py
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 thread fredipy/integrators.py Outdated
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
Jpwessely and others added 3 commits August 13, 2026 11:56
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants