pymc-devs / pymc-devs/pymc

BUG: Possible coefficient scaling mismatch in HSGPPeriodic prior (q_j^2 used as std)

Open
#8,167 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
9.8k
Forks
2.3k
Avg merge
21h 39m
Merged PRs (30d)
5

Description

Bug summary

HSGPPeriodic appears to apply periodic basis coefficients at the wrong scale, which can distort the GP prior variance and produce systematically incorrect prior draws.

This is not a cosmetic mismatch: it can change model behavior and inference quality whenever users rely on HSGPPeriodic as an approximation to gp.Latent with a periodic kernel.

Why this is high impact

  • It affects prior correctness for a core GP approximation API.
  • It can bias uncertainty and function amplitudes before seeing any data.
  • It directly undermines the expected equivalence between HSGPPeriodic and full periodic GP priors.

Evidence in code

1) Coefficients are documented/returned as variance-level terms (q_j^2)
  • pymc/gp/cov.py (Periodic.power_spectral_density_approx): docs and implementation indicate coefficients correspond to (\tilde q_j^2).
2) Same coefficients are used as if they were std-level terms
  • pymc/gp/hsgp_approx.py (HSGPPeriodic.prior_linearized, prior, _build_conditional): coefficients are multiplied directly into beta ~ Normal(0,1) via terms like phi @ (coeff * beta).

If coeff = q_j^2, then variance contribution becomes (q_j^2)^2 instead of q_j^2.

Observable symptom

The periodic prior equivalence test is currently xfailed:

  • tests/gp/test_hsgp_approx.py::TestHSGPPeriodic::test_prior

A scaling mismatch is a plausible root cause of this persistent mismatch.

Expected behavior

When beta ~ Normal(0,1), basis multipliers should be std-level coefficients.
If the covariance helper returns variance-level coefficients (q_j^2), HSGPPeriodic should use sqrt(q_j^2) at the multiplication site.

Suggested fix direction

  • Option A (minimal): keep power_spectral_density_approx as variance-level output and apply pt.sqrt(...) in HSGPPeriodic where coefficients multiply beta.
  • Option B: change semantics/API so the helper returns std-level coefficients consistently, then update naming/docs accordingly.

Either way, resolving this should help un-xfail periodic prior equivalence and restore expected approximation behavior.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read Periodic.power_spectral_density_approx in pymc/gp/cov.py alongside HSGPPeriodic.prior_linearized, prior, and _build_conditional in pymc/gp/hsgp_approx.py. Run tests/gp/test_hsgp_approx.py::TestHSGPPeriodic::test_prior and compare the coefficient semantics with the documented periodic covariance behavior; done means the periodic prior equivalence test passes without xfail.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.