Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,17 @@ The reference usage example for all three models is
`ELBOTerms`, `collapsed_elbo` → `CollapsedELBOTerms`,
`fitc_log_marginal_likelihood` → `FITCTerms`, plus `vfe_diagnostics`
and `dpp_regularizer`.
- **Kernels** — `ptgp/kernels/`. `Kernel` base class; subclasses
implement `_eval(X, Y)` and (optionally) `diag(X)`. Stationary
(`ExpQuad`, `Matern12/32/52`), nonstationary (`Gibbs`, `RandomWalk`,
`WarpedInput`), categorical (`Overlap`, `LowRankCategorical`),
combination (`SumKernel`, `ProductKernel`, via `+` / `*`). `active_dims`
selects input columns.
- **Kernels** — `ptgp/kernels/`. A `Kernel` is a graph on the row
placeholders of its `input_dim`, and it stores nothing else. The leaves
are typed `KernelOp` nodes with the parameters as explicit inputs, and
`+` / `*` are ordinary graph arithmetic on them. To add a kernel, subclass
`KernelOp`, implement `evaluate(left, right, *parameters)`, set
`unit_diagonal = True` when `k(x, x) = 1`, and build the graph with
`leaf_graph`. Never store graph objects on an Op. `Kernel.diag` is
`pt.diagonal(self(X))`, and a rewrite lowers it. Stationary (`ExpQuad`,
`Matern12/32/52`), nonstationary (`Linear`, `Gibbs`, `RandomWalk`,
`WarpedInput`), categorical (`Overlap`, `LowRankCategorical`).
`active_dims` selects input columns.
- **Likelihoods** — `ptgp/likelihoods/`. `Gaussian`, `Bernoulli`,
`Poisson`, `NegativeBinomial`, `StudentT`. Non-Gaussian variants
implement `variational_expectation` for SVGP.
Expand Down Expand Up @@ -141,7 +146,8 @@ The reference usage example for all three models is
check at initialisation — call this before training), `get_initial_params`
(prior-median / prior-draw / unconstrained-zero), `save_fit` / `load_fit`.
- **Rewrites** — `ptgp/rewrites.py`. The cubic-floor enablers; see the
mental-model section.
mental-model section. Kernel-targeted rewrites match on `KernelOp`, and
`late_inline_kernel` exposes each body at specialize, after they have run.
- **High-level API** — `ptgp/optim/api.py` (`fit`, `predict`,
`FitResult`, re-exported at top level) wraps the compile helpers for
the common case; `ptgp/idata.py` (`to_idata`) packages a fit as an
Expand Down
9 changes: 0 additions & 9 deletions docs/source/api/kernels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,3 @@ Categorical

Overlap
LowRankCategorical

Composition
-----------

.. autosummary::
:toctree: generated/

SumKernel
ProductKernel
23 changes: 12 additions & 11 deletions docs/source/user_guide/kernels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@ Kernels

**WRITEME.** This page is a stub. Cover the kernel catalogue,
composition via ``+`` and ``*``, ``active_dims``, the ``eta`` scale
convention, and the ``pt.assume(K, symmetric=True, positive_definite=True)``
convention, and the ``pta.assume(K, symmetric=True, positive_definite=True)``
annotation pattern.

ptgp kernels are implemented natively (not reused from PyMC) and operate on
matrix pairs. ``Kernel.__call__(X, Y=None)`` returns a symbolic PyTensor
tensor. When called with ``Y=None`` the kernel produces ``K(X, X)``
annotated as ``symmetric=True, positive_definite=True`` so downstream
rewrites can specialize.
ptgp kernels are implemented natively (not reused from PyMC). A
:class:`~ptgp.kernels.Kernel` is a PyTensor graph on placeholder rows, and
``Kernel.__call__(X, Y=None)`` replaces those rows with ``X`` and ``Y``. When
called with ``Y=None`` the kernel produces ``K(X, X)`` annotated as
``symmetric=True, positive_definite=True`` so downstream rewrites can
specialize.

Available families
------------------

- **Stationary**: :class:`~ptgp.kernels.ExpQuad`,
:class:`~ptgp.kernels.Matern52`, :class:`~ptgp.kernels.Matern32`,
:class:`~ptgp.kernels.Matern12`.
- **Non-stationary**: :class:`~ptgp.kernels.Gibbs`,
:class:`~ptgp.kernels.RandomWalk`, :class:`~ptgp.kernels.WarpedInput`.
- **Non-stationary**: :class:`~ptgp.kernels.Linear`,
:class:`~ptgp.kernels.Gibbs`, :class:`~ptgp.kernels.RandomWalk`,
:class:`~ptgp.kernels.WarpedInput`.
- **Categorical**: :class:`~ptgp.kernels.Overlap`,
:class:`~ptgp.kernels.LowRankCategorical` for multi-class or categorical
inputs.
- **Composition**: :class:`~ptgp.kernels.SumKernel`,
:class:`~ptgp.kernels.ProductKernel`, produced by the ``+`` and ``*``
operators on existing kernels.
- **Composition**: the ``+`` and ``*`` operators on existing kernels return
a :class:`~ptgp.kernels.Kernel` whose graph is the sum or product of theirs.

Scale convention
----------------
Expand Down
4 changes: 1 addition & 3 deletions docs/sphinxext/generate_kernel_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ def _build_random_walk():
# kernels added to ``ptgp.kernels`` will still trigger the check until they
# land in ``KERNEL_RECIPES`` or are added here.
KERNEL_GALLERY_BLACKLIST: set[str] = {
"Kernel", # abstract base class
"SumKernel", # composition, not a "kernel" on its own
"ProductKernel", # composition
"Kernel", # base class, and the type of every composition
"Gibbs", # requires a user-supplied lengthscale function
"WarpedInput", # requires a user-supplied warp function
"Overlap", # categorical, needs a different render mode
Expand Down
35 changes: 35 additions & 0 deletions notebooks/gp_as_pymc_model/gp_as_pymc_model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""GP models as PyMC models, with the fitting objective read from the model.

- ``GP``: a process; ``f(X)`` is its values at ``X``, a random variable in a ``pm.Model``.
- ``objective(model, approx)``: named terms of a fitting criterion, read from the model.
- Families: ``Exact``, ``VFE``, ``FITC``, ``SVGP`` for GPs; ``MeanField``, ``Gaussian``, ``Point``.
- ``fit(obj)`` (scipy, L-BFGS-B) and ``compile_training_step(obj, optimizer, param_groups)``
(pytensor-ml optimizers, per group; ``natural_gradient`` for an SVGP's q(u)): both give a
``Fit``, which holds the history and predicts.
"""

from .families import FITC, SVGP, VFE, Exact, Gaussian, GPFamily, MeanField, Point
from .fit import Fit, compile_training_step, fit, natural_gradient
from .model import GP, GPRV, find_gp_sums, processes
from .objective import Objective, objective

__all__ = [
"FITC",
"GP",
"GPRV",
"SVGP",
"VFE",
"Exact",
"Fit",
"GPFamily",
"Gaussian",
"MeanField",
"Objective",
"Point",
"compile_training_step",
"find_gp_sums",
"fit",
"natural_gradient",
"objective",
"processes",
]
Loading
Loading