From gpcam
Designs prior mean functions for gpCAM that encode known physics, theoretical models, or expected trends, with recipes for constant, linear, Gaussian, polynomial, and physics-informed means.
How this skill is triggered — by the user, by Claude, or both
Slash command
/gpcam:prior-mean-functionsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Design prior mean functions that encode known physics or expected trends.
Design prior mean functions that encode known physics or expected trends.
When the user has prior knowledge about the expected behavior:
def my_mean(x, hyperparameters):
"""
Parameters
----------
x : np.ndarray, shape (N, D)
Input positions.
hyperparameters : np.ndarray, 1D
The FULL hyperparameter vector (shared with kernel and noise).
Returns
-------
m : np.ndarray, shape (N,)
Prior mean value at each input point.
"""
If no prior mean is provided, gpCAM uses the average of y_data as a constant mean — this is fine for most cases.
def constant_mean(x, hps):
"""Explicit constant mean. hps[-1] = mean value."""
return np.full(len(x), hps[-1])
def linear_mean(x, hps):
"""
Linear prior mean: m(x) = a + b0*x0 + b1*x1 + ...
Uses hps[K], hps[K+1], ..., hps[K+D] where K is where mean hps start.
"""
K = 3 # INDEX WHERE MEAN HYPERPARAMETERS START — adjust for your kernel
D = x.shape[1]
intercept = hps[K]
slopes = hps[K+1:K+1+D]
return intercept + x @ slopes
def gaussian_peak_mean(x, hps):
"""
Prior: expect a Gaussian peak near a known location.
hps[K]: amplitude
hps[K+1]: center_x
hps[K+2]: center_y
hps[K+3]: width
"""
K = 3 # adjust
amp = hps[K]
cx, cy = hps[K+1], hps[K+2]
w = hps[K+3]
r2 = (x[:, 0] - cx)**2 + (x[:, 1] - cy)**2
return amp * np.exp(-r2 / (2 * w**2))
def quadratic_mean(x, hps):
"""Quadratic background: a + b*x + c*x^2 (1D)."""
K = 2 # adjust
return hps[K] + hps[K+1] * x[:, 0] + hps[K+2] * x[:, 0]**2
def bragg_mean(x, hps):
"""
Prior mean based on Bragg's law: peak at 2*d*sin(theta) = n*lambda.
x[:, 0] = 2theta angle in degrees
hps[K] = amplitude
hps[K+1] = d-spacing estimate
"""
K = 3
wavelength = 1.54 # Cu K-alpha, fixed
two_theta = np.radians(x[:, 0])
# Expected peak positions
d = hps[K+1]
expected = hps[K] * np.exp(-(np.sin(two_theta/2) - wavelength/(2*d))**2 / 0.001)
return expected
This is where most bugs happen. The prior mean function receives the same hyperparameter vector as the kernel and noise functions. You must:
# Example layout:
# hps[0] = signal variance (kernel)
# hps[1:3] = length scales (kernel, 2D input)
# hps[3] = intercept (mean function)
# hps[4:6] = slopes (mean function)
# hps[6] = noise amplitude (noise function)
#
# Total: 7 hyperparameters
hp_bounds = np.array([
[0.001, 100.0], # signal variance
[0.01, 50.0], # length scale dim 0
[0.01, 50.0], # length scale dim 1
[-10.0, 10.0], # intercept
[-5.0, 5.0], # slope dim 0
[-5.0, 5.0], # slope dim 1
[0.001, 10.0], # noise amplitude
])
[min(y_data) * 2, max(y_data) * 2][-range(y)/range(x), +range(y)/range(x)][known_position - tolerance, known_position + tolerance][min_expected_width, max_expected_width]hyperparameter_bounds.len(x), not a scalar.npx claudepluginhub lbl-camera/gpcam --plugin gpcamDesigns custom kernel (covariance) functions for gpCAM that encode domain knowledge like smoothness, periodicity, symmetry, anisotropy, or non-Euclidean input spaces.
Builds Bayesian models with PyMC v5+, specifies priors, runs MCMC inference via nutpie, diagnoses convergence, and compares models using ArviZ.
Bayesian modeling with PyMC: hierarchical models, MCMC (NUTS), variational inference, LOO/WAIC comparison, posterior predictive checks. Use for fitting Bayesian models and estimating posteriors.