/gpcam:prior-mean-functionsfrom gpcam
Encodes known physics or expected trends as custom prior mean functions for gpCAM Gaussian process models, replacing the default data-mean prior.
Ships in gpcam. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Verified against gpCAM 8.7.0 / fvgp 4.11.1 — last checked 2026-10-28 (gpCAM a21385a).
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).
Read ONLY the indices reserved for the mean function.
Returns
-------
m : np.ndarray, shape (N,)
Prior mean value at each input point.
"""
Attach it with the prior_mean_function keyword:
from gpcam import GPOptimizer
gpo = GPOptimizer(
x_data=x_data,
y_data=y_data,
init_hyperparameters=init_hps, # must cover kernel + mean (+ noise)
prior_mean_function=my_mean,
)
gpo.train(hyperparameter_bounds=hp_bounds)
args parameter: Declare a 3rd positional parameter my_mean(x, hps, args) to receive GPOptimizer(..., args=...) (gp_optimizer.py:153-154; see experiment-designer for the full args dispatch table).prior_mean_function_grad): Optional callable returning shape (len(hps), N) (gp_optimizer.py:165-171).prior_mean_function is omitted, gpCAM uses fvgp.GP._default_mean_function, which is a constant equal to each output's average of y_data (gp_optimizer.py:157-160) — not zero.gp_optimizer.py:153-160):
"independent" and "kronecker" modes, x has shape (N, D) and prior_mean_function may return (N,) or (N, No).multi_task_mode="cartesian", x has shape (N, D + 1) with the task index in the last column (x[:, -1]), and prior_mean_function returns a 1-D vector of shape (N,) (remember x.shape[1] is D + 1).K)See experiment-designer ("Hyperparameter Coordination") for the canonical layout (hps[:K] kernel, hps[K : K + M] prior mean, hps[K + M :] noise). With the single-task default ARD kernel, K = 1 + D = 1 + x.shape[1]; with a custom kernel, K is the number of parameters that kernel consumes. Never index with hps[-1] in a prior mean function — the trailing slice belongs to the noise function.
def constant_mean(x, hps):
"""
Explicit constant mean.
hps[K] = mean value, where K = 1 + D for the default kernel.
"""
K = 1 + x.shape[1]
return np.full(len(x), hps[K])
def linear_mean(x, hps):
"""
Linear prior mean: m(x) = a + b0*x0 + b1*x1 + ...
hps[K] = intercept
hps[K+1:K+1+D] = slopes
Uses D + 1 hyperparameters.
"""
D = x.shape[1]
K = 1 + D # default kernel: hps[0] + D length scales
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. 2-D input.
hps[K]: amplitude
hps[K+1]: center_x
hps[K+2]: center_y
hps[K+3]: width
Uses 4 hyperparameters.
"""
K = 1 + x.shape[1]
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 (1-D input, so K = 2).
Uses 3 hyperparameters.
"""
K = 1 + x.shape[1]
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
Uses 2 hyperparameters.
"""
K = 1 + x.shape[1]
wavelength = 1.54 # Cu K-alpha, fixed
two_theta = np.radians(x[:, 0])
d = hps[K+1]
expected = hps[K] * np.exp(-(np.sin(two_theta/2) - wavelength/(2*d))**2 / 0.001)
return expected
Prior mean hyperparameters sit at hps[K : K + M] between the kernel (hps[:K]) and noise (hps[K + M :]) slices — see experiment-designer for the full coordination rules.
import numpy as np
from gpcam import GPOptimizer
D = 2
K = 1 + D # mean hyperparameters start here
def linear_mean(x, hps):
return hps[K] + x @ hps[K+1:K+1+D]
def learnable_noise(x, hps):
return np.full(len(x), hps[K + 1 + D]**2) # noise sits after the mean
hp_bounds = np.array(
[[0.001, 100.0]] + # signal variance (kernel)
[[0.01, 50.0]] * D + # length scales (kernel)
[[-10.0, 10.0]] + # intercept (mean)
[[-5.0, 5.0]] * D + # slopes (mean)
[[0.001, 10.0]] # noise amplitude (noise)
)
gpo = GPOptimizer(
x_data, y_data,
init_hyperparameters=np.ones(len(hp_bounds)),
prior_mean_function=linear_mean,
noise_function=learnable_noise,
)
gpo.train(hyperparameter_bounds=hp_bounds)
assert len(gpo.hyperparameters) == len(hp_bounds) # cheap layout check
[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]K = 3 is right only for 2-D input with the default kernel. Derive K = 1 + D.hps[-1] collides with the noise function under the standard kernel → mean → noise ordering. Always index forward from K.prior_mean_function=: Defining the function is not enough; it must be passed to the constructor.hyperparameter_bounds.len(x), not a scalar.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub lbl-camera/gpcam --plugin gpcam11 skills in this plugin
/acquisition-functionsUse when choosing or writing an acquisition function for gpCAM — selecting a built-in criterion for exploration, optimization, batch, or multi-task runs, or implementing a custom callable for UCB/LCB, minimization EI, constraints, radical gradient, or threshold finding./cost-functionsUse when modeling the real expense of moving between gpCAM measurement points — motor travel time, settling, directional costs, sample damage, beam time, or zone-based penalties./experiment-designerUse for end-to-end autonomous experiment design with gpCAM. Translates a scientist's description of their measurement into a complete, runnable gpCAM script — useful for replacing raster scans with adaptive sampling, peak-finding, or parameter optimization./gp2scale-advancedUse for large-scale gpCAM experiments (>10k points up to millions) using sparse compactly-supported kernels and Dask distributed computing for exact GP computation at scale./kernel-designerUse when designing or composing custom kernel (covariance) functions for gpCAM — smoothness, periodicity, symmetry, anisotropy, non-stationary amplitude/length-scale kernels (`non_stat_kernel`, Gibbs), non-Euclidean inputs, or neural-network-warped deep kernels (`Network`)./multi-task-advancedUse for multi-output, vector-valued, or function-valued gpCAM experiments using GPOptimizer with several output columns and multi_task_mode (or migrating legacy fvGPOptimizer code) — useful when a single measurement returns multiple correlated quantities (e.g., spectra, multi-channel detectors).Other plugins' skills for the same job